Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-9.4.x' into jetty-9.4.x-51…
Browse files Browse the repository at this point in the history
…62-Improve-Decorating-Listener-Examples
  • Loading branch information
gregw committed Aug 25, 2020
2 parents 4008385 + 4dfcb80 commit c9e1fa5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 12 deletions.
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -43,7 +44,6 @@
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;
Expand Down Expand Up @@ -180,7 +180,7 @@ public static Server createServer(int port, int securePort, boolean addDebugList
StatisticsHandler stats = new StatisticsHandler();
stats.setHandler(server.getHandler());
server.setHandler(stats);
ServerConnectionStatistics.addToAllConnectors(server);
server.addBeanToAllConnectors(new ConnectionStatistics());

// === Rewrite Handler
RewriteHandler rewrite = new RewriteHandler();
Expand Down
Expand Up @@ -20,9 +20,9 @@

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;

Expand All @@ -45,7 +45,7 @@ public static Server createServer(int port)
context.addServlet(DefaultServlet.class, "/");

// Add Connector Statistics tracking to all connectors
ServerConnectionStatistics.addToAllConnectors(server);
server.addBeanToAllConnectors(new ConnectionStatistics());
return server;
}

Expand Down
6 changes: 4 additions & 2 deletions jetty-server/src/main/config/etc/jetty-stats.xml
Expand Up @@ -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="addBeanToAllConnectors">
<Arg>
<New class="org.eclipse.jetty.io.ConnectionStatistics"/>
</Arg>
</Call>
</Configure>
Expand Up @@ -41,7 +41,7 @@
* 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")
Expand Down
19 changes: 17 additions & 2 deletions jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
Expand Up @@ -42,6 +42,7 @@
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;
Expand Down Expand Up @@ -224,8 +225,8 @@ public void addConnector(Connector connector)
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);
}

/**
Expand Down Expand Up @@ -265,6 +266,20 @@ public void setConnectors(Connector[] connectors)
_connectors.addAll(Arrays.asList(connectors));
}

/**
* Add a bean to all connectors on the server.
* If the bean is an instance of {@link Connection.Listener} it will also be
* registered as a listener on all connections accepted by the connectors.
* @param bean the bean to be added.
*/
public void addBeanToAllConnectors(Object bean)
{
for (Connector connector : getConnectors())
{
connector.addBean(bean);
}
}

/**
* @return Returns the threadPool.
*/
Expand Down
Expand Up @@ -19,16 +19,19 @@
package org.eclipse.jetty.server;

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#addBeanToAllConnectors(Object)} instead.
*/
public static void addToAllConnectors(Server server)
{
for (Connector connector : server.getConnectors())
{
if (connector instanceof Container)
connector.addBean(new ConnectionStatistics());
connector.addBean(new ConnectionStatistics());
}
}
}

0 comments on commit c9e1fa5

Please sign in to comment.