393832 start connectors last
This commit is contained in:
parent
f336511f87
commit
a1d0efc2bb
|
@ -21,38 +21,19 @@ package org.eclipse.jetty.io;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.util.Callback;
|
import org.eclipse.jetty.util.Callback;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.thread.Scheduler;
|
import org.eclipse.jetty.util.thread.Scheduler;
|
||||||
|
|
||||||
public abstract class AbstractEndPoint implements EndPoint
|
public abstract class AbstractEndPoint extends IdleTimeout implements EndPoint
|
||||||
{
|
{
|
||||||
private static final Logger LOG = Log.getLogger(AbstractEndPoint.class);
|
private static final Logger LOG = Log.getLogger(AbstractEndPoint.class);
|
||||||
private final long _created=System.currentTimeMillis();
|
private final long _created=System.currentTimeMillis();
|
||||||
private final InetSocketAddress _local;
|
private final InetSocketAddress _local;
|
||||||
private final InetSocketAddress _remote;
|
private final InetSocketAddress _remote;
|
||||||
|
|
||||||
private final Scheduler _scheduler;
|
|
||||||
private final AtomicReference<Scheduler.Task> _timeout = new AtomicReference<>();
|
|
||||||
private final Runnable _idleTask = new Runnable()
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
long idleLeft=checkIdleTimeout();
|
|
||||||
if (idleLeft>=0)
|
|
||||||
scheduleIdleTimeout(idleLeft > 0 ? idleLeft : getIdleTimeout());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
private volatile long _idleTimeout;
|
|
||||||
private volatile long _idleTimestamp=System.currentTimeMillis();
|
|
||||||
private volatile Connection _connection;
|
private volatile Connection _connection;
|
||||||
|
|
||||||
private final FillInterest _fillInterest = new FillInterest()
|
private final FillInterest _fillInterest = new FillInterest()
|
||||||
|
@ -74,9 +55,9 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
|
|
||||||
protected AbstractEndPoint(Scheduler scheduler,InetSocketAddress local,InetSocketAddress remote)
|
protected AbstractEndPoint(Scheduler scheduler,InetSocketAddress local,InetSocketAddress remote)
|
||||||
{
|
{
|
||||||
|
super(scheduler);
|
||||||
_local=local;
|
_local=local;
|
||||||
_remote=remote;
|
_remote=remote;
|
||||||
_scheduler=scheduler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -85,19 +66,6 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
return _created;
|
return _created;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long getIdleTimeout()
|
|
||||||
{
|
|
||||||
return _idleTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setIdleTimeout(long idleTimeout)
|
|
||||||
{
|
|
||||||
_idleTimeout = idleTimeout;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InetSocketAddress getLocalAddress()
|
public InetSocketAddress getLocalAddress()
|
||||||
{
|
{
|
||||||
|
@ -109,17 +77,7 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
{
|
{
|
||||||
return _remote;
|
return _remote;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getIdleTimestamp()
|
|
||||||
{
|
|
||||||
return _idleTimestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void notIdle()
|
|
||||||
{
|
|
||||||
_idleTimestamp=System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Connection getConnection()
|
public Connection getConnection()
|
||||||
{
|
{
|
||||||
|
@ -145,6 +103,12 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
_writeFlusher.onClose();
|
_writeFlusher.onClose();
|
||||||
_fillInterest.onClose();
|
_fillInterest.onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close()
|
||||||
|
{
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <C> void fillInterested(C context, Callback<C> callback) throws IllegalStateException
|
public <C> void fillInterested(C context, Callback<C> callback) throws IllegalStateException
|
||||||
|
@ -173,56 +137,23 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
return _writeFlusher;
|
return _writeFlusher;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void scheduleIdleTimeout(long delay)
|
@Override
|
||||||
|
protected void onIdleExpired(TimeoutException timeout)
|
||||||
{
|
{
|
||||||
Scheduler.Task newTimeout = null;
|
if (isOutputShutdown() || _fillInterest.isInterested() || _writeFlusher.isInProgress())
|
||||||
if (isOpen() && delay > 0 && _scheduler!=null)
|
|
||||||
newTimeout = _scheduler.schedule(_idleTask, delay, TimeUnit.MILLISECONDS);
|
|
||||||
Scheduler.Task oldTimeout = _timeout.getAndSet(newTimeout);
|
|
||||||
if (oldTimeout != null)
|
|
||||||
oldTimeout.cancel();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected long checkIdleTimeout()
|
|
||||||
{
|
|
||||||
if (isOpen())
|
|
||||||
{
|
{
|
||||||
long idleTimestamp = getIdleTimestamp();
|
boolean output_shutdown=isOutputShutdown();
|
||||||
long idleTimeout = getIdleTimeout();
|
_fillInterest.onFail(timeout);
|
||||||
long idleElapsed = System.currentTimeMillis() - idleTimestamp;
|
_writeFlusher.onFail(timeout);
|
||||||
long idleLeft = idleTimeout - idleElapsed;
|
if (output_shutdown)
|
||||||
|
close();
|
||||||
LOG.debug("{} idle timeout check, elapsed: {} ms, remaining: {} ms", this, idleElapsed, idleLeft);
|
|
||||||
|
|
||||||
if (isOutputShutdown() || _fillInterest.isInterested() || _writeFlusher.isInProgress())
|
|
||||||
{
|
|
||||||
if (idleTimestamp != 0 && idleTimeout > 0)
|
|
||||||
{
|
|
||||||
if (idleLeft <= 0)
|
|
||||||
{
|
|
||||||
LOG.debug("{} idle timeout expired", this);
|
|
||||||
|
|
||||||
boolean output_shutdown=isOutputShutdown();
|
|
||||||
TimeoutException timeout = new TimeoutException("Idle timeout expired: " + idleElapsed + "/" + idleTimeout + " ms");
|
|
||||||
_fillInterest.onFail(timeout);
|
|
||||||
_writeFlusher.onFail(timeout);
|
|
||||||
|
|
||||||
if (output_shutdown)
|
|
||||||
close();
|
|
||||||
notIdle();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return idleLeft>=0?idleLeft:0;
|
|
||||||
}
|
}
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return String.format("%s@%x{%s<r-l>%s,o=%b,is=%b,os=%b,fi=%s,wf=%s,to=%d}{%s}",
|
return String.format("%s@%x{%s<r-l>%s,o=%b,is=%b,os=%b,fi=%s,wf=%s,it=%d}{%s}",
|
||||||
getClass().getSimpleName(),
|
getClass().getSimpleName(),
|
||||||
hashCode(),
|
hashCode(),
|
||||||
getRemoteAddress(),
|
getRemoteAddress(),
|
||||||
|
@ -232,7 +163,7 @@ public abstract class AbstractEndPoint implements EndPoint
|
||||||
isOutputShutdown(),
|
isOutputShutdown(),
|
||||||
_fillInterest,
|
_fillInterest,
|
||||||
_writeFlusher,
|
_writeFlusher,
|
||||||
_idleTimeout,
|
getIdleTimeout(),
|
||||||
getConnection());
|
getConnection());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,6 +50,7 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||||
import org.eclipse.jetty.util.annotation.Name;
|
import org.eclipse.jetty.util.annotation.Name;
|
||||||
import org.eclipse.jetty.util.component.Graceful;
|
import org.eclipse.jetty.util.component.Graceful;
|
||||||
|
import org.eclipse.jetty.util.component.LifeCycle;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.eclipse.jetty.util.log.Log;
|
||||||
import org.eclipse.jetty.util.log.Logger;
|
import org.eclipse.jetty.util.log.Logger;
|
||||||
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
import org.eclipse.jetty.util.thread.QueuedThreadPool;
|
||||||
|
@ -298,6 +299,14 @@ public class Server extends HandlerWrapper implements Attributes
|
||||||
mex.ifExceptionThrow();
|
mex.ifExceptionThrow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void start(LifeCycle l) throws Exception
|
||||||
|
{
|
||||||
|
// start connectors last
|
||||||
|
if (!(l instanceof Connector))
|
||||||
|
super.start(l);
|
||||||
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------ */
|
/* ------------------------------------------------------------ */
|
||||||
@Override
|
@Override
|
||||||
protected void doStop() throws Exception
|
protected void doStop() throws Exception
|
||||||
|
|
Loading…
Reference in New Issue