From 9ee8ef74233a5e9f1a9ded5b980b81bf388a9f5c Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 21 Sep 2012 16:41:05 +1000 Subject: [PATCH] jetty-9 more lifecycle fixes --- example-jetty-embedded/pom.xml | 5 +++++ .../java/org/eclipse/jetty/embedded/LikeJettyXml.java | 4 ++-- .../jetty/deploy/providers/ScanningAppProvider.java | 3 +++ .../eclipse/jetty/server/handler/AbstractHandler.java | 2 ++ .../jetty/server/handler/HandlerCollection.java | 3 ++- .../eclipse/jetty/server/handler/HandlerWrapper.java | 3 +++ .../jetty/util/component/AbstractLifeCycle.java | 10 +++++----- .../jetty/util/component/ContainerLifeCycle.java | 5 +++++ 8 files changed, 27 insertions(+), 8 deletions(-) diff --git a/example-jetty-embedded/pom.xml b/example-jetty-embedded/pom.xml index deb02f0753e..132d7b41974 100644 --- a/example-jetty-embedded/pom.xml +++ b/example-jetty-embedded/pom.xml @@ -39,6 +39,11 @@ jetty-jmx ${project.version} + + org.eclipse.jetty.websocket + websocket-server + ${project.version} + org.eclipse.jetty.spdy spdy-http-server diff --git a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index 30c6d432132..e3c226a5f7e 100644 --- a/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/example-jetty-embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -53,8 +53,8 @@ public class LikeJettyXml Server server = new Server(threadPool); server.manage(threadPool); - server.setDumpAfterStart(true); - server.setDumpBeforeStop(true); + server.setDumpAfterStart(false); + server.setDumpBeforeStop(false); // Setup JMX MBeanContainer mbContainer=new MBeanContainer(ManagementFactory.getPlatformMBeanServer()); diff --git a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java index 870b74032a9..5ebecbfb4e6 100644 --- a/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java +++ b/jetty-deploy/src/main/java/org/eclipse/jetty/deploy/providers/ScanningAppProvider.java @@ -54,16 +54,19 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A /* ------------------------------------------------------------ */ private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener() { + @Override public void fileAdded(String filename) throws Exception { ScanningAppProvider.this.fileAdded(filename); } + @Override public void fileChanged(String filename) throws Exception { ScanningAppProvider.this.fileChanged(filename); } + @Override public void fileRemoved(String filename) throws Exception { ScanningAppProvider.this.fileRemoved(filename); diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java index 0ede60ed471..7374359948d 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/AbstractHandler.java @@ -73,6 +73,8 @@ public abstract class AbstractHandler extends ContainerLifeCycle implements Hand @Override public void setServer(Server server) { + if (_server==server) + return; if (isStarted()) throw new IllegalStateException(STARTED); _server=server; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java index ab474ea9160..cff469b80d4 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java @@ -84,7 +84,8 @@ public class HandlerCollection extends AbstractHandlerContainer if (handlers!=null) for (Handler handler:handlers) - handler.setServer(getServer()); + if (handler.getServer()!=getServer()) + handler.setServer(getServer()); updateBeans(_handlers, handlers); _handlers = handlers; diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java index c9afc370dca..0583fd07ba9 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerWrapper.java @@ -103,6 +103,9 @@ public class HandlerWrapper extends AbstractHandlerContainer @Override public void setServer(Server server) { + if (server==getServer()) + return; + if (isStarted()) throw new IllegalStateException(STARTED); diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java index 9c6199e373d..0908a847402 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/AbstractLifeCycle.java @@ -224,10 +224,10 @@ public abstract class AbstractLifeCycle implements LifeCycle public static abstract class AbstractLifeCycleListener implements LifeCycle.Listener { - public void lifeCycleFailure(LifeCycle event, Throwable cause) {} - public void lifeCycleStarted(LifeCycle event) {} - public void lifeCycleStarting(LifeCycle event) {} - public void lifeCycleStopped(LifeCycle event) {} - public void lifeCycleStopping(LifeCycle event) {} + @Override public void lifeCycleFailure(LifeCycle event, Throwable cause) {} + @Override public void lifeCycleStarted(LifeCycle event) {} + @Override public void lifeCycleStarting(LifeCycle event) {} + @Override public void lifeCycleStopped(LifeCycle event) {} + @Override public void lifeCycleStopping(LifeCycle event) {} } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java index f1cfe30918b..ca3d968f92a 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import org.eclipse.jetty.util.annotation.ManagedObject; +import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -45,6 +47,7 @@ import org.eclipse.jetty.util.log.Logger; * If adding a bean that is shared between multiple {@link ContainerLifeCycle} instances, then it should be started before being added, so it is unmanaged, or * the API must be used to explicitly set it as unmanaged. */ +@ManagedObject("Implementation of Container and LifeCycle") public class ContainerLifeCycle extends AbstractLifeCycle implements Container, Destroyable, Dumpable { private static final Logger LOG = Log.getLogger(ContainerLifeCycle.class); @@ -470,6 +473,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, * Dumps to {@link System#err}. * @see #dump() */ + @ManagedOperation("Dump the object to stderr") public void dumpStdErr() { try @@ -483,6 +487,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, } @Override + @ManagedOperation("Dump the object to a string") public String dump() { return dump(this);