diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java index f94fcad79e2..ec88f38c0ad 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/AbstractConnection.java @@ -42,7 +42,7 @@ public abstract class AbstractConnection implements Connection private final List listeners = new CopyOnWriteArrayList<>(); private final AtomicReference _state = new AtomicReference<>(State.IDLE); -// private final long _created=System.currentTimeMillis(); + private final long _created=System.currentTimeMillis(); private final EndPoint _endPoint; private final Executor _executor; private final Callback _readCallback; @@ -218,7 +218,7 @@ public abstract class AbstractConnection implements Connection @Override public void onOpen() { - LOG.info("{} opened", this); + LOG.debug("onOpen {}", this); for (Listener listener : listeners) listener.onOpened(this); @@ -233,7 +233,7 @@ public abstract class AbstractConnection implements Connection @Override public void onClose() { - LOG.info("{} closed",this); + LOG.debug("onClose {}",this); for (Listener listener : listeners) listener.onClosed(this); @@ -251,23 +251,37 @@ public abstract class AbstractConnection implements Connection getEndPoint().close(); } -// @Override -// public int getMessagesIn() -// { -// return 0; -// } -// -// @Override -// public int getMessagesOut() -// { -// return 0; -// } -// -// @Override -// public long getCreatedTimeStamp() -// { -// return _created; -// } + @Override + public int getMessagesIn() + { + return 0; + } + + @Override + public int getMessagesOut() + { + return 0; + } + + @Override + public long getBytesIn() + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getBytesOut() + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getCreatedTimeStamp() + { + return _created; + } @Override public String toString() diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java b/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java index ce9eaa87699..3a8f18c2a03 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java @@ -58,20 +58,19 @@ public interface Connection extends AutoCloseable @Override public void close(); -// public int getMessagesIn(); -// -// public int getMessagesOut(); -// -// public long getCreatedTimeStamp(); - + public int getMessagesIn(); + public int getMessagesOut(); + public long getBytesIn(); + public long getBytesOut(); + public long getCreatedTimeStamp(); + + public interface Listener { public void onOpened(Connection connection); public void onClosed(Connection connection); - // TODO: add onMessageIn/Out + onBytesIn/Out - public static class Empty implements Listener { @Override diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java index 66266b54eef..33b712e07f4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnectionFactory.java @@ -51,10 +51,9 @@ public abstract class AbstractConnectionFactory extends AggregateLifeCycle imple _inputbufferSize=size; } - protected void configureConnection(Connection connection, Connector connector, EndPoint endPoint) + protected AbstractConnection configure(AbstractConnection connection, Connector connector, EndPoint endPoint) { - if (connection instanceof AbstractConnection) - ((AbstractConnection)connection).setInputBufferSize(getInputBufferSize()); + connection.setInputBufferSize(getInputBufferSize()); if (connector instanceof AggregateLifeCycle) { @@ -62,6 +61,7 @@ public abstract class AbstractConnectionFactory extends AggregateLifeCycle imple for (Connection.Listener listener : aggregate.getBeans(Connection.Listener.class)) connection.addListener(listener); } + return connection; } @Override diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java index de6d171ce9b..a1ee0c2e96c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractConnector.java @@ -137,7 +137,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co protected final Logger LOG = Log.getLogger(getClass()); // Order is important on server side, so we use a LinkedHashMap private final Map _factories = new LinkedHashMap<>(); - private final Statistics _stats = new ConnectorStatistics(); private final Server _server; private final Executor _executor; private final Scheduler _scheduler; @@ -175,7 +174,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co unmanage(_executor); // inherited from server addBean(_scheduler); addBean(_byteBufferPool); - addBean(_stats,true); for (ConnectionFactory factory:factories) addConnectionFactory(factory); @@ -187,11 +185,6 @@ public abstract class AbstractConnector extends AggregateLifeCycle implements Co _acceptors = new Thread[acceptors]; } - @Override - public Statistics getStatistics() - { - return _stats; - } @Override public Server getServer() diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java index d0bf2741426..82f939057ec 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Connector.java @@ -85,132 +85,4 @@ public interface Connector extends LifeCycle, Graceful */ public Object getTransport(); - /** - * @return the {@link Statistics} associated with this {@link Connector} - */ - public Statistics getStatistics(); - - /** - *

{@link Connector} statistics.

- */ - public interface Statistics extends LifeCycle - { - /** - *

Resets the statistics.

- */ - public void reset(); - - /** - * @return the number of messages received by this connector - * since last call to {@link #reset}. - */ - public int getMessagesIn(); - - /** - * @return the number of messages sent by this connector - * since last call to {@link #reset}. - */ - public int getMessagesOut(); - - /** - * @return the number of bytes received by this connector - * since last call to {@link #reset}. - */ - public int getBytesIn(); - - /** - * @return the number of bytes sent by this connector - * since last call to {@link #reset}. - */ - public int getBytesOut(); - - /** - * @return the total time connections have been open, in milliseconds, - * since last call to {@link #reset}. - */ - public long getConnectionsDurationTotal(); - - /** - * @return the number of connections accepted by the server - * since last call to {@link #reset}. - */ - public int getConnections() ; - - /** - * @return the number of connections currently open that were opened - * since last call to {@link #reset}. - */ - public int getConnectionsOpen() ; - - /** - * @return the max number of connections opened simultaneously - * since last call to {@link #reset}. - */ - public int getConnectionsOpenMax() ; - - /** - * @return the max time a connection has been open, in milliseconds, - * since last call to {@link #reset}. - */ - public long getConnectionsDurationMax(); - - /** - * @return the mean time connections have been open, in milliseconds, - * since last call to {@link #reset}. - */ - public double getConnectionsDurationMean() ; - - /** - * @return the standard deviation of the time connections have been open, in milliseconds, - * since last call to {@link #reset}. - */ - public double getConnectionsDurationStdDev() ; - - /** - * @return the mean number of messages received per connection - * since last call to {@link #reset}. - */ - public double getConnectionsMessagesInMean() ; - - /** - * @return the standard deviation of the number of messages received per connection - * since last call to {@link #reset}. - */ - public double getConnectionsMessagesInStdDev() ; - - /** - * @return the max number of messages received by a connection - * since last call to {@link #reset}. - */ - public int getConnectionsMessagesInMax(); - - /** - * @return the number of milliseconds the statistics have been started or reset - */ - public long getStartedMillis(); - - /** - *

Callback method invoked when a new connection is opened.

- */ - public void connectionOpened(); - - /** - *

Callback method invoked when a connection is upgraded.

- * - * @param messagesIn the number of messages received by the previous connection - * @param messagesOut the number of messages send by the previous connection - */ - public void connectionUpgraded(int messagesIn, int messagesOut); - - /** - *

Callback method invoked when a connection is closed.

- * - * @param duration the time the connection was opened - * @param messagesIn the number of messages received by the connection - * @param messagesOut the number of messages send by the connection - */ - public void connectionClosed(long duration, int messagesIn, int messagesOut); - } - - } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java index b0d150b1531..dfd4e4ecb3b 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java @@ -23,7 +23,7 @@ import java.util.Arrays; import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.io.Connection; -import org.eclipse.jetty.server.Connector.Statistics; +import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.AggregateLifeCycle; @@ -31,7 +31,8 @@ import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.statistic.CounterStatistic; import org.eclipse.jetty.util.statistic.SampleStatistic; -class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpable, Connection.Listener +@ManagedObject("Connector Statistics") +public class ConnectorStatistics extends AbstractLifeCycle implements Dumpable, Connection.Listener { private final AtomicLong _startMillis = new AtomicLong(-1L); private final CounterStatistic _connectionStats = new CounterStatistic(); @@ -48,97 +49,81 @@ class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpa @Override public void onClosed(Connection connection) { - // TODO - connectionClosed(0, 0, 0); + connectionClosed(System.currentTimeMillis()-connection.getCreatedTimeStamp(),connection.getMessagesIn(),connection.getMessagesOut()); } - @Override public int getBytesIn() { // TODO return -1; } - @Override public int getBytesOut() { // TODO return -1; } - @Override public int getConnections() { return (int)_connectionStats.getTotal(); } - @Override public long getConnectionsDurationMax() { return _connectionDurationStats.getMax(); } - @Override public double getConnectionsDurationMean() { return _connectionDurationStats.getMean(); } - @Override public double getConnectionsDurationStdDev() { return _connectionDurationStats.getStdDev(); } - @Override public long getConnectionsDurationTotal() { return _connectionDurationStats.getTotal(); } - @Override public int getConnectionsMessagesInMax() { return (int)_messagesIn.getMax(); } - @Override public double getConnectionsMessagesInMean() { return _messagesIn.getMean(); } - @Override public double getConnectionsMessagesInStdDev() { return _messagesIn.getStdDev(); } - @Override public int getConnectionsOpen() { return (int)_connectionStats.getCurrent(); } - @Override public int getConnectionsOpenMax() { return (int)_connectionStats.getMax(); } - @Override public int getMessagesIn() { return (int)_messagesIn.getTotal(); } - @Override public int getMessagesOut() { return (int)_messagesIn.getTotal(); } - @Override public long getStartedMillis() { long start = _startMillis.get(); @@ -156,7 +141,6 @@ class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpa { } - @Override public void reset() { _startMillis.set(System.currentTimeMillis()); @@ -166,7 +150,6 @@ class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpa _connectionDurationStats.reset(); } - @Override public void connectionOpened() { if (isStarted()) @@ -175,7 +158,6 @@ class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpa } } - @Override public void connectionUpgraded(int messagesIn, int messagesOut) { if (isStarted()) @@ -185,7 +167,6 @@ class ConnectorStatistics extends AbstractLifeCycle implements Statistics, Dumpa } } - @Override public void connectionClosed(long duration, int messagesIn, int messagesOut) { if (isStarted()) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java index c42489bda0f..f3951933e7f 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnection.java @@ -138,17 +138,17 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http } -// @Override -// public int getMessagesIn() -// { -// return getHttpChannel().getRequests(); -// } -// -// @Override -// public int getMessagesOut() -// { -// return getHttpChannel().getRequests(); -// } + @Override + public int getMessagesIn() + { + return getHttpChannel().getRequests(); + } + + @Override + public int getMessagesOut() + { + return getHttpChannel().getRequests(); + } @Override public String toString() @@ -444,9 +444,9 @@ public class HttpConnection extends AbstractConnection implements Runnable, Http if (connection != null) { LOG.debug("Upgrade from {} to {}", this, connection); + onClose(); getEndPoint().setConnection(connection); - // TODO -// ((AbstractConnector)getConnector()).connectionUpgraded(this,connection); + connection.onOpen(); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java index 293baf925ea..d42687977f1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpConnectionFactory.java @@ -51,9 +51,7 @@ public class HttpConnectionFactory extends AbstractConnectionFactory implements @Override public Connection newConnection(Connector connector, EndPoint endPoint) { - HttpConnection connection = new HttpConnection(_config, connector, endPoint); - configureConnection(connection, connector, endPoint); - return connection; + return configure(new HttpConnection(_config, connector, endPoint), connector, endPoint); } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/SslConnectionFactory.java b/jetty-server/src/main/java/org/eclipse/jetty/server/SslConnectionFactory.java index f8b1ca1e1fa..a6e61ae6273 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/SslConnectionFactory.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/SslConnectionFactory.java @@ -78,7 +78,7 @@ public class SslConnectionFactory extends AbstractConnectionFactory engine.setUseClientMode(false); SslConnection sslConnection = new SslConnection(connector.getByteBufferPool(), connector.getExecutor(), endPoint, engine); - configureConnection(sslConnection, connector, endPoint); + configure(sslConnection, connector, endPoint); ConnectionFactory next = connector.getConnectionFactory(_nextProtocol); EndPoint decryptedEndPoint = sslConnection.getDecryptedEndPoint(); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java index dde2b7e77b8..8e0f048ccb1 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SelectChannelStatisticsTest.java @@ -49,6 +49,7 @@ public class SelectChannelStatisticsTest private static final Logger LOG = Log.getLogger(SelectChannelStatisticsTest.class); private static Server _server; + private static ConnectorStatistics _statistics; private static AbstractNetworkConnector _connector; private static CyclicBarrier _connect; private static CountDownLatch _closed; @@ -63,17 +64,9 @@ public class SelectChannelStatisticsTest _connect = new CyclicBarrier(2); _server = new Server(); - _connector = new ServerConnector(_server) - { - // TODO -// @Override -// public void connectionClosed(Connection connection) -// { -// super.connectionClosed(connection); -// _closed.countDown(); -// } - - }; + _connector = new ServerConnector(_server); + _statistics = new ConnectorStatistics(); + _connector.addBean(_statistics); _server.addConnector(_connector); HandlerWrapper wrapper = new HandlerWrapper() @@ -127,13 +120,12 @@ public class SelectChannelStatisticsTest @Before public void init() throws Exception { - _connector.getStatistics().start(); + _statistics.reset(); } @After public void tini() throws Exception { - _connector.getStatistics().stop(); } @Test @@ -145,19 +137,19 @@ public class SelectChannelStatisticsTest doClose(1); - assertEquals(1, _connector.getStatistics().getConnections()); - assertEquals(0, _connector.getStatistics().getConnectionsOpen()); - assertEquals(1, _connector.getStatistics().getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsOpen() <= _connector.getStatistics().getConnectionsOpenMax()); + assertEquals(1, _statistics.getConnections()); + assertEquals(0, _statistics.getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpenMax()); + assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMax() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() <= _connector.getStatistics().getConnectionsDurationMax()); + assertTrue(_statistics.getConnectionsDurationMean() > 0); + assertTrue(_statistics.getConnectionsDurationMax() > 0); + assertTrue(_statistics.getConnectionsDurationMean() <= _statistics.getConnectionsDurationMax()); - assertEquals(1, _connector.getStatistics().getMessagesIn()); - assertEquals(1.0, _connector.getStatistics().getConnectionsMessagesInMean(), 0.01); - assertEquals(1, _connector.getStatistics().getConnectionsMessagesInMax()); - assertTrue(_connector.getStatistics().getConnectionsMessagesInMean() <= _connector.getStatistics().getConnectionsMessagesInMax()); + assertEquals(1, _statistics.getMessagesIn()); + assertEquals(1.0, _statistics.getConnectionsMessagesInMean(), 0.01); + assertEquals(1, _statistics.getConnectionsMessagesInMax()); + assertTrue(_statistics.getConnectionsMessagesInMean() <= _statistics.getConnectionsMessagesInMax()); } @Test @@ -171,19 +163,19 @@ public class SelectChannelStatisticsTest doClose(1); - assertEquals(1, _connector.getStatistics().getConnections()); - assertEquals(0, _connector.getStatistics().getConnectionsOpen()); - assertEquals(1, _connector.getStatistics().getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsOpen() <= _connector.getStatistics().getConnectionsOpenMax()); + assertEquals(1, _statistics.getConnections()); + assertEquals(0, _statistics.getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpenMax()); + assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMax() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() <= _connector.getStatistics().getConnectionsDurationMax()); + assertTrue(_statistics.getConnectionsDurationMean() > 0); + assertTrue(_statistics.getConnectionsDurationMax() > 0); + assertTrue(_statistics.getConnectionsDurationMean() <= _statistics.getConnectionsDurationMax()); - assertEquals(2, _connector.getStatistics().getMessagesIn()); - assertEquals(2.0, _connector.getStatistics().getConnectionsMessagesInMean(), 0.01); - assertEquals(2, _connector.getStatistics().getConnectionsMessagesInMax()); - assertTrue(_connector.getStatistics().getConnectionsMessagesInMean() <= _connector.getStatistics().getConnectionsMessagesInMax()); + assertEquals(2, _statistics.getMessagesIn()); + assertEquals(2.0, _statistics.getConnectionsMessagesInMean(), 0.01); + assertEquals(2, _statistics.getConnectionsMessagesInMax()); + assertTrue(_statistics.getConnectionsMessagesInMean() <= _statistics.getConnectionsMessagesInMax()); } @Test @@ -205,19 +197,19 @@ public class SelectChannelStatisticsTest doClose(3); - assertEquals(3, _connector.getStatistics().getConnections()); - assertEquals(0, _connector.getStatistics().getConnectionsOpen()); - assertEquals(3, _connector.getStatistics().getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsOpen() <= _connector.getStatistics().getConnectionsOpenMax()); + assertEquals(3, _statistics.getConnections()); + assertEquals(0, _statistics.getConnectionsOpen()); + assertEquals(3, _statistics.getConnectionsOpenMax()); + assertTrue(_statistics.getConnectionsOpen() <= _statistics.getConnectionsOpenMax()); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMax() > 0); - assertTrue(_connector.getStatistics().getConnectionsDurationMean() <= _connector.getStatistics().getConnectionsDurationMax()); + assertTrue(_statistics.getConnectionsDurationMean() > 0); + assertTrue(_statistics.getConnectionsDurationMax() > 0); + assertTrue(_statistics.getConnectionsDurationMean() <= _statistics.getConnectionsDurationMax()); - assertEquals(6, _connector.getStatistics().getMessagesIn()); - assertEquals(2.0, _connector.getStatistics().getConnectionsMessagesInMean(), 0.01); - assertEquals(3, _connector.getStatistics().getConnectionsMessagesInMax()); - assertTrue(_connector.getStatistics().getConnectionsMessagesInMean() <= _connector.getStatistics().getConnectionsMessagesInMax()); + assertEquals(6, _statistics.getMessagesIn()); + assertEquals(2.0, _statistics.getConnectionsMessagesInMean(), 0.01); + assertEquals(3, _statistics.getConnectionsMessagesInMax()); + assertTrue(_statistics.getConnectionsMessagesInMean() <= _statistics.getConnectionsMessagesInMax()); } protected void doInit(int count) @@ -260,7 +252,7 @@ public class SelectChannelStatisticsTest _connect.await(); - assertEquals(count, _connector.getStatistics().getConnectionsOpen()); + assertEquals(count, _statistics.getConnectionsOpen()); String line=_in[idx].readLine(); while(line!=null) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java index da5da91f5f2..f24f2b32dcb 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/SlowClientWithPipelinedRequestTest.java @@ -54,7 +54,7 @@ public class SlowClientWithPipelinedRequestTest @Override public Connection newConnection(Connector connector, EndPoint endPoint) { - return new HttpConnection(new HttpChannelConfig(),connector,endPoint) + return configure(new HttpConnection(new HttpChannelConfig(),connector,endPoint) { @Override public void onFillable() @@ -62,7 +62,7 @@ public class SlowClientWithPipelinedRequestTest handles.incrementAndGet(); super.onFillable(); } - }; + },connector,endPoint); } }); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java index c8adcab2901..b0dd2036618 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/StatisticsHandlerTest.java @@ -36,6 +36,7 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.continuation.Continuation; import org.eclipse.jetty.continuation.ContinuationListener; import org.eclipse.jetty.continuation.ContinuationSupport; +import org.eclipse.jetty.server.ConnectorStatistics; import org.eclipse.jetty.server.LocalConnector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.Server; @@ -46,6 +47,7 @@ import org.junit.Test; public class StatisticsHandlerTest { private Server _server; + private ConnectorStatistics _statistics; private LocalConnector _connector; private LatchHandler _latchHandler; private StatisticsHandler _statsHandler; @@ -56,6 +58,8 @@ public class StatisticsHandlerTest _server = new Server(); _connector = new LocalConnector(_server); + _statistics=new ConnectorStatistics(); + _connector.addBean(_statistics); _server.addConnector(_connector); _latchHandler = new LatchHandler(); @@ -79,6 +83,7 @@ public class StatisticsHandlerTest _statsHandler.setHandler(new AbstractHandler() { + @Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { request.setHandled(true); @@ -104,7 +109,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(1, _connector.getStatistics().getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpen()); assertEquals(1, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -140,7 +145,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(2, _connector.getStatistics().getConnectionsOpen()); + assertEquals(2, _statistics.getConnectionsOpen()); assertEquals(2, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -177,7 +182,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(4, _connector.getStatistics().getConnectionsOpen()); + assertEquals(4, _statistics.getConnectionsOpen()); assertEquals(4, _statsHandler.getRequests()); assertEquals(2, _statsHandler.getRequestsActive()); @@ -215,6 +220,7 @@ public class StatisticsHandlerTest final CyclicBarrier barrier[] = { new CyclicBarrier(2), new CyclicBarrier(2), new CyclicBarrier(2)}; _statsHandler.setHandler(new AbstractHandler() { + @Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { request.setHandled(true); @@ -262,7 +268,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(1, _connector.getStatistics().getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpen()); assertEquals(1, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -286,10 +292,12 @@ public class StatisticsHandlerTest continuationHandle.get().addContinuationListener(new ContinuationListener() { + @Override public void onTimeout(Continuation continuation) { } + @Override public void onComplete(Continuation continuation) { try { barrier[2].await(); } catch(Exception e) {} @@ -301,7 +309,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(1, _connector.getStatistics().getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpen()); assertEquals(1, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -341,6 +349,7 @@ public class StatisticsHandlerTest final CyclicBarrier barrier[] = { new CyclicBarrier(2), new CyclicBarrier(2), new CyclicBarrier(2)}; _statsHandler.setHandler(new AbstractHandler() { + @Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { request.setHandled(true); @@ -389,7 +398,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(1, _connector.getStatistics().getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpen()); assertEquals(1, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -403,10 +412,12 @@ public class StatisticsHandlerTest continuationHandle.get().addContinuationListener(new ContinuationListener() { + @Override public void onTimeout(Continuation continuation) { } + @Override public void onComplete(Continuation continuation) { try { barrier[2].await(); } catch(Exception e) {} @@ -461,6 +472,7 @@ public class StatisticsHandlerTest final CyclicBarrier barrier[] = { new CyclicBarrier(2), new CyclicBarrier(2), new CyclicBarrier(2)}; _statsHandler.setHandler(new AbstractHandler() { + @Override public void handle(String path, Request request, HttpServletRequest httpRequest, HttpServletResponse httpResponse) throws IOException, ServletException { request.setHandled(true); @@ -509,7 +521,7 @@ public class StatisticsHandlerTest barrier[0].await(); - assertEquals(1, _connector.getStatistics().getConnectionsOpen()); + assertEquals(1, _statistics.getConnectionsOpen()); assertEquals(1, _statsHandler.getRequests()); assertEquals(1, _statsHandler.getRequestsActive()); @@ -523,10 +535,12 @@ public class StatisticsHandlerTest assertTrue(continuationHandle.get().isSuspended()); continuationHandle.get().addContinuationListener(new ContinuationListener() { + @Override public void onTimeout(Continuation continuation) { } + @Override public void onComplete(Continuation continuation) { try { barrier[2].await(); } catch(Exception e) {} diff --git a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPConnectionFactory.java b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPConnectionFactory.java index e2e274f351f..de85b9765a8 100644 --- a/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPConnectionFactory.java +++ b/jetty-spdy/spdy-http-server/src/main/java/org/eclipse/jetty/spdy/server/proxy/ProxyHTTPConnectionFactory.java @@ -45,7 +45,7 @@ public class ProxyHTTPConnectionFactory extends AbstractConnectionFactory implem @Override public Connection newConnection(Connector connector, EndPoint endPoint) { - return new ProxyHTTPSPDYConnection(connector, httpChannelConfig, endPoint, version, proxyEngineSelector); + return configure(new ProxyHTTPSPDYConnection(connector, httpChannelConfig, endPoint, version, proxyEngineSelector),connector,endPoint); } @Override diff --git a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/NPNServerConnectionFactory.java b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/NPNServerConnectionFactory.java index 0be4c749b3f..9d47500e042 100644 --- a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/NPNServerConnectionFactory.java +++ b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/NPNServerConnectionFactory.java @@ -97,7 +97,7 @@ public class NPNServerConnectionFactory extends AbstractConnectionFactory if (dft==null) dft=_protocols.get(0); - return new NextProtoNegoServerConnection((DecryptedEndPoint)endPoint, connector,protocols,_defaultProtocol); + return configure(new NextProtoNegoServerConnection((DecryptedEndPoint)endPoint, connector,protocols,_defaultProtocol),connector,endPoint); } @Override diff --git a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java index 98256587095..853cf3978df 100644 --- a/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java +++ b/jetty-spdy/spdy-server/src/main/java/org/eclipse/jetty/spdy/server/SPDYServerConnectionFactory.java @@ -78,7 +78,6 @@ public class SPDYServerConnectionFactory extends AbstractConnectionFactory ServerSessionFrameListener listener = provideServerSessionFrameListener(connector,endPoint); SPDYConnection connection = new ServerSPDYConnection(connector,endPoint, parser, listener, getInputBufferSize()); - configureConnection(connection, connector, endPoint); FlowControlStrategy flowControlStrategy = newFlowControlStrategy(version); @@ -90,7 +89,7 @@ public class SPDYServerConnectionFactory extends AbstractConnectionFactory sessionOpened(session); - return connection; + return configure(connection,connector,endPoint); } protected FlowControlStrategy newFlowControlStrategy(short version) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java index b9b4a7d589d..8a8e6d734b7 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AggregateLifeCycle.java @@ -51,23 +51,8 @@ public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable private final List _beans = new CopyOnWriteArrayList<>(); private boolean _started = false; - enum Managed { MANAGED, UNMANAGED, AUTO }; - - private class Bean + public AggregateLifeCycle() { - private final Object _bean; - private volatile Managed _managed = Managed.AUTO; - - private Bean(Object b) - { - _bean = b; - } - - @Override - public String toString() - { - return String.format("{%s,%b}", _bean, _managed); - } } /** @@ -495,4 +480,24 @@ public class AggregateLifeCycle extends AbstractLifeCycle implements Destroyable } } } + + + enum Managed { MANAGED, UNMANAGED, AUTO }; + + private class Bean + { + private final Object _bean; + private volatile Managed _managed = Managed.AUTO; + + private Bean(Object b) + { + _bean = b; + } + + @Override + public String toString() + { + return String.format("{%s,%b}", _bean, _managed); + } + } }