Change the way ConnectorStatistics is added to the Servers Connectors

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2020-08-20 13:34:05 +10:00
parent 70a679f5f4
commit 623d1be7c7
6 changed files with 32 additions and 12 deletions

View File

@ -29,6 +29,7 @@ import org.eclipse.jetty.deploy.PropertiesConfigurationManager;
import org.eclipse.jetty.deploy.bindings.DebugListenerBinding;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.rewrite.handler.MsieSslRule;
import org.eclipse.jetty.rewrite.handler.RewriteHandler;
@ -43,7 +44,6 @@ import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.LowResourceMonitor;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnectionStatistics;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
@ -180,7 +180,7 @@ public class LikeJettyXml
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
server.setHandler(stats);
ServerConnectionStatistics.addToAllConnectors(server);
server.addToAllConnectors(new ConnectionStatistics());
// === Rewrite Handler
RewriteHandler rewrite = new RewriteHandler();

View File

@ -20,9 +20,9 @@ package org.eclipse.jetty.embedded;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnectionStatistics;
import org.eclipse.jetty.servlet.DefaultServlet;
import org.eclipse.jetty.servlet.ServletContextHandler;
@ -45,7 +45,7 @@ public class OneServletContextJmxStats
context.addServlet(DefaultServlet.class, "/");
// Add Connector Statistics tracking to all connectors
ServerConnectionStatistics.addToAllConnectors(server);
server.addToAllConnectors(new ConnectionStatistics());
return server;
}

View File

@ -8,7 +8,9 @@
<New id="StatsHandler" class="org.eclipse.jetty.server.handler.StatisticsHandler"></New>
</Arg>
</Call>
<Call class="org.eclipse.jetty.server.ServerConnectionStatistics" name="addToAllConnectors">
<Arg><Ref refid="Server"/></Arg>
<Call name="addToAllConnectors">
<Arg>
<New class="org.eclipse.jetty.io.ConnectionStatistics"/>
</Arg>
</Call>
</Configure>

View File

@ -41,7 +41,7 @@ import org.eclipse.jetty.util.statistic.SampleStatistic;
* Adding an instance of this class as with {@link AbstractConnector#addBean(Object)}
* will register the listener with all connections accepted by that connector.
*
* @deprecated use {@link ServerConnectionStatistics} instead.
* @deprecated use {@link org.eclipse.jetty.io.ConnectionStatistics} instead.
*/
@Deprecated
@ManagedObject("Connector Statistics")

View File

@ -42,6 +42,7 @@ import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.PreEncodedHttpField;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ErrorHandler;
import org.eclipse.jetty.server.handler.HandlerWrapper;
@ -224,8 +225,8 @@ public class Server extends HandlerWrapper implements Attributes
if (connector.getServer() != this)
throw new IllegalArgumentException("Connector " + connector +
" cannot be shared among server " + connector.getServer() + " and server " + this);
if (_connectors.add(connector))
addBean(connector);
_connectors.add(connector);
addBean(connector);
}
/**
@ -265,6 +266,19 @@ public class Server extends HandlerWrapper implements Attributes
_connectors.addAll(Arrays.asList(connectors));
}
/**
* Add a {@link Connection.Listener} as a bean to all connectors on the server, this
* will register the listener with all connections accepted by the connectors.
* @param listener the listener to be added.
*/
public void addToAllConnectors(Connection.Listener listener)
{
for (Connector connector : getConnectors())
{
connector.addBean(listener);
}
}
/**
* @return Returns the threadPool.
*/

View File

@ -18,17 +18,21 @@
package org.eclipse.jetty.server;
import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.io.ConnectionStatistics;
import org.eclipse.jetty.util.component.Container;
@Deprecated
public class ServerConnectionStatistics extends ConnectionStatistics
{
/**
* @param server the server to use to add {@link ConnectionStatistics} to all Connectors.
* @deprecated use {@link Server#addToAllConnectors(Connection.Listener)} instead.
*/
public static void addToAllConnectors(Server server)
{
for (Connector connector : server.getConnectors())
{
if (connector instanceof Container)
connector.addBean(new ConnectionStatistics());
connector.addBean(new ConnectionStatistics());
}
}
}