Fixed invocation of EndPoint.onClose().

Made sure EndPoint.onClose() is invoked only once and that EndPoints
that have a socket channel associated invoke the SelectorManager
lifecycle callbacks for EndPoints.
This commit is contained in:
Simone Bordet 2016-05-19 00:15:00 +02:00
parent db8a59b6f5
commit 0cac43d53f
3 changed files with 11 additions and 16 deletions

View File

@ -181,7 +181,7 @@ public abstract class ChannelEndPoint extends AbstractEndPoint implements Manage
finally
{
if (_selector!=null)
_selector.onClose(this);
_selector.destroyEndPoint(this);
}
}

View File

@ -413,6 +413,7 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump
private EndPoint createEndPoint(SelectableChannel channel, SelectionKey selectionKey) throws IOException
{
EndPoint endPoint = _selectorManager.newEndPoint(channel, this, selectionKey);
endPoint.onOpen();
_selectorManager.endPointOpened(endPoint);
Connection connection = _selectorManager.newConnection(channel, endPoint, selectionKey.attachment());
endPoint.setConnection(connection);
@ -423,21 +424,17 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump
return endPoint;
}
public void onClose(final EndPoint endPoint)
public void destroyEndPoint(final EndPoint endPoint)
{
final Connection connection = endPoint.getConnection();
submit(new Product()
{
@Override
public void run()
{
if (LOG.isDebugEnabled())
LOG.debug("Destroyed {}", endPoint);
if (connection != null)
_selectorManager.connectionClosed(connection);
endPoint.close();
}
});
submit((Product)() ->
{
if (LOG.isDebugEnabled())
LOG.debug("Destroyed {}", endPoint);
if (connection != null)
_selectorManager.connectionClosed(connection);
_selectorManager.endPointClosed(endPoint);
});
}
@Override

View File

@ -304,7 +304,6 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dump
*/
protected void endPointOpened(EndPoint endpoint)
{
endpoint.onOpen();
}
/**
@ -314,7 +313,6 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dump
*/
protected void endPointClosed(EndPoint endpoint)
{
endpoint.onClose();
}
/**