Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-05-19 00:15:30 +02:00
commit 45d3783c85
4 changed files with 38 additions and 46 deletions

View File

@ -31,8 +31,8 @@ import org.eclipse.jetty.util.thread.Scheduler;
public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
{
enum State {OPEN, ISHUTTING, ISHUT, OSHUTTING, OSHUT, CLOSED};
private static final Logger LOG = Log.getLogger(AbstractEndPoint.class);
private final AtomicReference<State> _state = new AtomicReference<>(State.OPEN);
private final long _created=System.currentTimeMillis();
private volatile Connection _connection;
@ -60,14 +60,13 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
super(scheduler);
}
protected final void shutdownInput()
{
while(true)
{
State s = _state.get();
switch(s)
{
{
case OPEN:
if (!_state.compareAndSet(s,State.ISHUTTING))
continue;
@ -88,17 +87,17 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
}
}
return;
case ISHUTTING: // Somebody else ishutting
case ISHUT: // Already ishut
return;
case OSHUTTING:
if (!_state.compareAndSet(s,State.CLOSED))
continue;
// The thread doing the OSHUT will close
return;
case OSHUT:
if (!_state.compareAndSet(s,State.CLOSED))
continue;
@ -140,20 +139,20 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
}
}
return;
case ISHUTTING:
if (!_state.compareAndSet(s,State.CLOSED))
continue;
// The thread doing the ISHUT will close
return;
case ISHUT:
if (!_state.compareAndSet(s,State.CLOSED))
continue;
// Already ISHUT so we close
doOnClose();
return;
case OSHUTTING: // Somebody else oshutting
case OSHUT: // Already oshut
return;
@ -185,23 +184,23 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
if (!_state.compareAndSet(s,State.CLOSED))
continue;
// The thread doing the IO SHUT will call doOnClose
return;
return;
case CLOSED: // already closed
return;
}
}
}
protected void doShutdownInput()
{}
protected void doShutdownOutput()
{}
protected void doClose()
{}
private void doOnClose()
{
try
@ -213,7 +212,6 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
onClose();
}
}
@Override
public boolean isOutputShutdown()
@ -225,7 +223,7 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
case OSHUTTING:
return true;
default:
return false;
return false;
}
}
@Override
@ -238,7 +236,7 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
case ISHUTTING:
return true;
default:
return false;
return false;
}
}
@ -250,10 +248,10 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
case CLOSED:
return false;
default:
return true;
return true;
}
}
public void checkFlush() throws IOException
{
State s=_state.get();
@ -267,7 +265,7 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
break;
}
}
public void checkFill() throws IOException
{
State s=_state.get();
@ -306,15 +304,13 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
return false;
}
protected void reset()
{
_state.set(State.OPEN);
_writeFlusher.onClose();
_fillInterest.onClose();
}
@Override
public void onOpen()
{
@ -423,7 +419,7 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
c=c.getSuperclass();
name=c.getSimpleName();
}
Connection connection = getConnection();
return String.format("%s@%x{%s<->%s,%s,%s|%s,%d/%d,%s@%x}",
name,
@ -438,4 +434,9 @@ public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
connection == null ? null : connection.getClass().getSimpleName(),
connection == null ? 0 : connection.hashCode());
}
private enum State
{
OPEN, ISHUTTING, ISHUT, OSHUTTING, OSHUT, CLOSED
}
}

View File

@ -45,7 +45,6 @@ public abstract class ChannelEndPoint extends AbstractEndPoint implements Manage
private final GatheringByteChannel _gather;
protected final ManagedSelector _selector;
protected final SelectionKey _key;
private boolean _updatePending;
/**
@ -58,7 +57,6 @@ public abstract class ChannelEndPoint extends AbstractEndPoint implements Manage
*/
protected int _desiredInterestOps;
private abstract class RunnableTask implements Runnable
{
private final String _operation;
@ -183,11 +181,10 @@ public abstract class ChannelEndPoint extends AbstractEndPoint implements Manage
finally
{
if (_selector!=null)
_selector.onClose(this);
_selector.destroyEndPoint(this);
}
}
@Override
public int fill(ByteBuffer buffer) throws IOException
{
@ -428,5 +425,4 @@ public abstract class ChannelEndPoint extends AbstractEndPoint implements Manage
return String.format("%s{io=%s,kio=-2,kro=-2}", super.toString(), _desiredInterestOps);
}
}
}

View File

@ -145,7 +145,7 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump
* A {@link Selectable} is an {@link EndPoint} that wish to be
* notified of non-blocking events by the {@link ManagedSelector}.
*/
public interface Selectable
public interface Selectable
{
/**
* Callback method invoked when a read or write events has been
@ -341,7 +341,7 @@ public class ManagedSelector extends AbstractLifeCycle implements Runnable, Dump
private Runnable processConnect(SelectionKey key, final Connect connect)
{
SelectableChannel channel = (SelectableChannel)key.channel();
SelectableChannel channel = key.channel();
try
{
key.attach(connect.attachment);
@ -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();
if (connection!=null)
submit(new Product()
{
@Override
public void run()
{
if (LOG.isDebugEnabled())
LOG.debug("Destroyed {}", endPoint);
if (connection != null)
_selectorManager.connectionClosed(connection);
}
});
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();
}
/**