Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ClientConnectionListener listener #12421

Draft
wants to merge 1 commit into
base: jetty-12.0.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public static ClientConnector forUnixDomain(Path path)
private boolean reusePort;
private int receiveBufferSize = -1;
private int sendBufferSize = -1;
private ClientConnectionListener listener;

public ClientConnector()
{
Expand Down Expand Up @@ -476,6 +477,7 @@ else if (networkChannel instanceof DatagramChannel)
selectorManager.accept(channel, context);
else
selectorManager.connect(channel, context);
listener.onConnectBegin((SocketChannel)channel);
}
// Must catch all exceptions, since some like
// UnresolvedAddressException are not IOExceptions.
Expand Down Expand Up @@ -513,6 +515,13 @@ public void accept(SelectableChannel selectable, Map<String, Object> context)
}
}

public void onClientConnection(ClientConnectionListener listener)
{
if (this.listener != null)
return;
this.listener = listener;
}

private void bind(NetworkChannel channel, SocketAddress bindAddress) throws IOException
{
if (LOG.isDebugEnabled())
Expand Down Expand Up @@ -593,6 +602,7 @@ protected EndPoint newEndPoint(SelectableChannel channel, ManagedSelector select
{
EndPoint endPoint = ClientConnector.this.newEndPoint(channel, selector, selectionKey);
endPoint.setIdleTimeout(getIdleTimeout().toMillis());
listener.onConnectSuccess((SocketChannel)channel);
return endPoint;
}

Expand Down Expand Up @@ -629,6 +639,7 @@ protected void connectionFailed(SelectableChannel channel, Throwable failure, Ob
{
@SuppressWarnings("unchecked")
Map<String, Object> context = (Map<String, Object>)attachment;
listener.onConnectFailure((SocketChannel)channel, failure);
connectFailed(failure, context);
}
}
Expand Down Expand Up @@ -753,4 +764,11 @@ public ChannelWithAddress newChannelWithAddress(ClientConnector clientConnector,
};
}
}

public interface ClientConnectionListener
{
public void onConnectBegin(SocketChannel s);
public void onConnectSuccess(SocketChannel s);
public void onConnectFailure(SocketChannel s, Throwable x);
}
}
Loading