404889 SelectorManager accepts attachments with sockets
This commit is contained in:
parent
c5931ad56f
commit
39d690ed2a
|
@ -167,6 +167,20 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
selector.submit(selector.new Accept(channel));
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Registers a channel to perform non-blocking read/write operations.</p>
|
||||
* <p>This method is called just after a channel has been accepted by {@link ServerSocketChannel#accept()},
|
||||
* or just after having performed a blocking connect via {@link Socket#connect(SocketAddress, int)}.</p>
|
||||
*
|
||||
* @param channel the channel to register
|
||||
* @param attachment An attachment to be passed via the selection key to the {@link SelectorManager#newConnection(SocketChannel, EndPoint, Object)} method.
|
||||
*/
|
||||
public void accept(final SocketChannel channel, Object attachment)
|
||||
{
|
||||
final ManagedSelector selector = chooseSelector();
|
||||
selector.submit(selector.new Accept(channel, attachment));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doStart() throws Exception
|
||||
{
|
||||
|
@ -685,10 +699,18 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
private class Accept implements Runnable
|
||||
{
|
||||
private final SocketChannel _channel;
|
||||
private final Object _attachment;
|
||||
|
||||
public Accept(SocketChannel channel)
|
||||
{
|
||||
this._channel = channel;
|
||||
this._attachment = null;
|
||||
}
|
||||
|
||||
public Accept(SocketChannel channel, Object attachment)
|
||||
{
|
||||
this._channel = channel;
|
||||
this._attachment = attachment;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -696,7 +718,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
{
|
||||
try
|
||||
{
|
||||
SelectionKey key = _channel.register(_selector, 0, null);
|
||||
SelectionKey key = _channel.register(_selector, 0, _attachment);
|
||||
EndPoint endpoint = createEndPoint(_channel, key);
|
||||
key.attach(endpoint);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue