Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use addEventListener(EventListener listener) instead of bespoke listener methods #3966

Merged
merged 35 commits into from
Nov 13, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
babfa3d
Avoid creating listener list for rarely used requestAttributeListener
gregw Aug 12, 2019
8514201
Issue #3964
gregw Aug 13, 2019
565298b
Issue #2578 EventListener
gregw Aug 13, 2019
40cc7bf
Issue #2578 EventListener
gregw Aug 13, 2019
548af98
Issue #2578 EventListener
gregw Aug 13, 2019
06afe72
Issue #3964
gregw Aug 13, 2019
03c0144
fix merge
gregw Aug 13, 2019
160ee44
Issue #2578 EventListener
gregw Aug 14, 2019
633889a
Issue #2578 EventListener
gregw Aug 14, 2019
216166f
Merge branch 'jetty-10.0.x' into jetty-10.0.x-2578-EventListener
gregw Aug 14, 2019
058b45a
Issue #2578 EventListener
gregw Aug 14, 2019
d64d6fc
Issue #2578 EventListener
gregw Aug 14, 2019
ff607fc
Issue #2578 EventListener
gregw Aug 14, 2019
1596f53
Issue #2578 EventListener
gregw Aug 14, 2019
a4a466f
Issue #3964
gregw Aug 14, 2019
9ea7d4c
Issue #2578 EventListener
gregw Aug 14, 2019
1ef4ba0
fixed javadoc
gregw Aug 14, 2019
35aef6b
Issue #2578 EventListener
gregw Aug 19, 2019
cc72473
Issue #3964 Listeners
gregw Aug 19, 2019
fa24361
fixed bad merge
gregw Aug 19, 2019
fc61c47
Merge branch 'jetty-10.0.x' into jetty-10.0.x-2578-EventListener
gregw Aug 19, 2019
338e04d
Issue #3964 Listeners
gregw Aug 19, 2019
eca22ed
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-…
gregw Aug 21, 2019
36b3615
Issue #3964 Listeners
gregw Aug 21, 2019
5695dc9
removed deprecated cyclic HttpChannel listeners
gregw Aug 21, 2019
536728e
removed deprecated cyclic HttpChannel listeners - import
gregw Aug 21, 2019
8d502e5
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-…
gregw Aug 25, 2019
5a16d6b
Merge branch 'jetty-10.0.x' into jetty-10.0.x-2578-EventListener
gregw Aug 27, 2019
31b772a
Merge branch 'jetty-10.0.x' into jetty-10.0.x-2578-EventListener
gregw Aug 27, 2019
8498bb5
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-…
gregw Aug 28, 2019
3a21969
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-…
gregw Aug 28, 2019
abd7629
Issue #4003 Cleanup quickstart
gregw Sep 10, 2019
057f1a3
Merge branch 'jetty-10.0.x' into jetty-10.0.x-2578-EventListener
gregw Sep 24, 2019
946151c
updates from review
gregw Sep 24, 2019
25964ae
Merge remote-tracking branch 'origin/jetty-10.0.x' into jetty-10.0.x-…
gregw Sep 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.security.PermissionCollection;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.EventListener;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -615,9 +614,8 @@ public void doStop()
TaskLog.logWithTimestamp("Stopping web application " + this);
Thread.currentThread().sleep(500L);
super.doStop();
//remove all filters, servlets and listeners. They will be recreated
//remove all filters and servlets and listeners. They will be recreated
gregw marked this conversation as resolved.
Show resolved Hide resolved
//either via application of a context xml file or web.xml or annotation or servlet api
setEventListeners(new EventListener[0]);
getServletHandler().setFilters(new FilterHolder[0]);
getServletHandler().setFilterMappings(new FilterMapping[0]);
getServletHandler().setServlets(new ServletHolder[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ public void testHttpClientName() throws Exception
String name = "foo";
HttpClient httpClient = new HttpClient();
httpClient.setName(name);
httpClient.start();

try
{
MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();
MBeanContainer mbeanContainer = new MBeanContainer(mbeanServer);
// Adding MBeanContainer as a bean will trigger the registration of MBeans.
httpClient.addBean(mbeanContainer);
httpClient.start();

String domain = HttpClient.class.getPackage().getName();
ObjectName pattern = new ObjectName(domain + ":type=" + HttpClient.class.getSimpleName().toLowerCase(Locale.ENGLISH) + ",*");
Expand Down
2 changes: 1 addition & 1 deletion jetty-home/src/main/resources/etc/jetty-setuid.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- ================================================================ -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.setuid.SetUIDListener">
<Set name="startServerAsPrivileged"><Property name="jetty.setuid.startServerAsPrivileged" default="false"/></Set>
Expand Down
2 changes: 1 addition & 1 deletion jetty-home/src/main/resources/etc/jetty-started.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- Mixin the Start FileNoticeLifeCycleListener -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.util.component.FileNoticeLifeCycleListener">
<Arg><Property name="jetty.state" default="./jetty.state"/></Arg>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Connection newConnection(EndPoint endPoint, Map<String, Object> context)

final HTTP2ClientConnection connection = new HTTP2ClientConnection(client, byteBufferPool, executor, endPoint,
parser, session, client.getInputBufferSize(), promise, listener);
connection.addListener(connectionListener);
connection.addEventListener(connectionListener);
return customize(connection, context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public Connection newConnection(Connector connector, EndPoint endPoint)

HTTP2Connection connection = new HTTP2ServerConnection(connector.getByteBufferPool(), connector.getExecutor(),
endPoint, httpConfiguration, parser, session, getInputBufferSize(), listener);
connection.addListener(sessionContainer);
connection.addEventListener(sessionContainer);
return configure(connection, connector, endPoint);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.eclipse.jetty.io;

import java.util.EventListener;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -57,13 +58,14 @@ protected AbstractConnection(EndPoint endp, Executor executor)
}

@Override
public void addListener(Listener listener)
public void addEventListener(EventListener listener)
{
_listeners.add(listener);
if (listener instanceof Listener)
_listeners.add((Listener)listener);
}

@Override
public void removeListener(Listener listener)
public void removeEventListener(EventListener listener)
{
_listeners.remove(listener);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.jetty.io;

import java.io.IOException;
import java.util.EventListener;
import java.util.List;
import java.util.Map;

Expand All @@ -43,7 +44,7 @@ public default Connection customize(Connection connection, Map<String, Object> c
{
ContainerLifeCycle client = (ContainerLifeCycle)context.get(CLIENT_CONTEXT_KEY);
if (client != null)
client.getBeans(Connection.Listener.class).forEach(connection::addListener);
client.getBeans(EventListener.class).forEach(connection::addEventListener);
return connection;
}

Expand Down
7 changes: 4 additions & 3 deletions jetty-io/src/main/java/org/eclipse/jetty/io/Connection.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.Closeable;
import java.nio.ByteBuffer;
import java.util.EventListener;

import org.eclipse.jetty.util.component.Container;

Expand All @@ -38,14 +39,14 @@ public interface Connection extends Closeable
*
* @param listener the listener to add
*/
public void addListener(Listener listener);
public void addEventListener(EventListener listener);

/**
* <p>Removes a listener of connection events.</p>
*
* @param listener the listener to remove
*/
public void removeListener(Listener listener);
public void removeEventListener(EventListener listener);

/**
* <p>Callback method invoked when this connection is opened.</p>
Expand Down Expand Up @@ -133,7 +134,7 @@ public interface UpgradeTo
* the Connector or ConnectionFactory are added as listeners to all new connections
* </p>
*/
public interface Listener
public interface Listener extends EventListener
{
public void onOpened(Connection connection);

Expand Down
29 changes: 15 additions & 14 deletions jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.eclipse.jetty.util.ProcessorUtils;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.Container;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
import org.eclipse.jetty.util.log.Log;
Expand Down Expand Up @@ -389,31 +390,27 @@ protected void connectionFailed(SelectableChannel channel, Throwable ex, Object
*/
public abstract Connection newConnection(SelectableChannel channel, EndPoint endpoint, Object attachment) throws IOException;

/**
* @param listener An EventListener
* @see AcceptListener
* @see Container#addEventListener(EventListener)
*/
public void addEventListener(EventListener listener)
{
if (isRunning())
throw new IllegalStateException(this.toString());
super.addEventListener(listener);
if (listener instanceof AcceptListener)
addAcceptListener(AcceptListener.class.cast(listener));
_acceptListeners.add((AcceptListener)listener);
}

public void removeEventListener(EventListener listener)
{
if (isRunning())
throw new IllegalStateException(this.toString());
super.removeEventListener(listener);
if (listener instanceof AcceptListener)
removeAcceptListener(AcceptListener.class.cast(listener));
}

public void addAcceptListener(AcceptListener listener)
{
if (!_acceptListeners.contains(listener))
_acceptListeners.add(listener);
}

public void removeAcceptListener(AcceptListener listener)
{
_acceptListeners.remove(listener);
_acceptListeners.remove(listener);
}

protected void onAccepting(SelectableChannel channel)
Expand Down Expand Up @@ -461,12 +458,16 @@ protected void onAccepted(SelectableChannel channel)
}
}

public interface SelectorManagerListener extends EventListener
{
}

/**
* <p>A listener for accept events.</p>
* <p>This listener is called from either the selector or acceptor thread
* and implementations must be non blocking and fast.</p>
*/
public interface AcceptListener extends EventListener
public interface AcceptListener extends SelectorManagerListener
{
/**
* Called immediately after a new SelectableChannel is accepted, but
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@ public String toString()
}

/**
* <p>A listener of {@link WriteFlusher} events.</p>
* <p>A listener of {@link WriteFlusher} events.
* If implemented by a Connection class, the {@link #onFlushed(long)} event will be delivered to it.</p>
*/
public interface Listener
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
</New>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<Configure id="Server" class="org.eclipse.jetty.server.Server">
<Ref id="httpConnector">
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerConnectorListener">
<Set name="fileName"><Property name="jetty.port.file" default="port.txt"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.EventListener;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -434,11 +433,9 @@ public void doStop() throws Exception

super.doStop();

// remove all listeners, servlets and filters. This is because we will
// re-apply
// any context xml file, which means they would potentially be added
// multiple times.
setEventListeners(new EventListener[0]);
// remove all servlets and filters. This is because we will
// re-appy any context xml file, which means they would potentially be
// added multiple times.
getServletHandler().setFilters(new FilterHolder[0]);
getServletHandler().setFilterMappings(new FilterMapping[0]);
getServletHandler().setServlets(new ServletHolder[0]);
Expand Down
2 changes: 1 addition & 1 deletion jetty-maven-plugin/src/main/resources/jetty-maven.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">

<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.maven.plugin.ServerListener">
<Set name="tokenFile"><Property name="jetty.token.file"/></Set>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void start(BundleContext context) throws Exception
{
//For test purposes, use a random port
Server server = new Server(0);
server.getConnectors()[0].addLifeCycleListener(new AbstractLifeCycleListener()
server.getConnectors()[0].addEventListener(new AbstractLifeCycleListener()
{

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</Item>
</Array>
</Arg>
<Call name="addLifeCycleListener">
<Call name="addEventListener">
<Arg>
<New class="org.eclipse.jetty.osgi.boot.utils.ServerConnectorListener">
<Set name="sysPropertyName">boot.context.service.port</Set>
Expand Down
Loading