You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Daniel Kulp <dk...@apache.org> on 2007/09/20 02:44:27 UTC

Re: svn commit: r577477 - /incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java

Willem,

I think this commit will cause more problems.

With this commit, if you have two busses in your application with 
services registered in each, if you shutdown one bus, all the services 
get killed.   We definitely don't want that.  

Basically, the engine needs to track how many services are registered on 
a port, and when that drops to 0, then possibly shutdown.

Dan



On Wednesday 19 September 2007, ningjiang@apache.org wrote:
> Author: ningjiang
> Date: Wed Sep 19 16:59:24 2007
> New Revision: 577477
>
> URL: http://svn.apache.org/viewvc?rev=577477&view=rev
> Log:
> CXF-1034 shutdown the JettyEngine when bus shutdown is called
>
> Modified:
>    
> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
>
> Modified:
> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java URL:
> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-je
>tty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEn
>gineFactory.java?rev=577477&r1=577476&r2=577477&view=diff
> ======================================================================
>======== ---
> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java (original)
> +++
> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java Wed Sep 19
> 16:59:24 2007 @@ -30,6 +30,8 @@
>  import javax.annotation.Resource;
>
>  import org.apache.cxf.Bus;
> +import org.apache.cxf.buslifecycle.BusLifeCycleListener;
> +import org.apache.cxf.buslifecycle.BusLifeCycleManager;
>  import org.apache.cxf.common.logging.LogUtils;
>  import org.apache.cxf.configuration.jsse.TLSServerParameters;
>
> @@ -42,31 +44,19 @@
>   * caches the JettyHTTPServerEngines so that they may be
>   * retrieved if already previously configured.
>   */
> -public class JettyHTTPServerEngineFactory {
> +public class JettyHTTPServerEngineFactory implements
> BusLifeCycleListener { private static final Logger LOG =
>          LogUtils.getL7dLogger(JettyHTTPServerEngineFactory.class);
>
>      /**
>       * This map holds references for allocated ports.
>       */
> -    // All system tests do not shut down bus correctly,
> -    // or the bus does not shutdown all endpoints correctly,
> -    // so that these server endings are actuall shared amongst busses
> -    // within the same JVM.
> -
> -    // We will keep it static until we can resolve the problems
> -    // in the System tests.
> -    // TODO: Fix the System Tests so that they shutdown the
> -    // buses that they are using and that the buses actually
> -    // shutdown the destinations and their server engines
> -    // properly. This will require a bit of lifecyle and reference
> -    // counting on Destinations to server engines, if they are
> -    // going to be shared, but they should by no means be
> -    // shared accross buses, right?
> +    // Still use the static map to hold the port information
> +    // in the same JVM
>      private static Map<Integer, JettyHTTPServerEngine> portMap =
>          new HashMap<Integer, JettyHTTPServerEngine>();
>
> -
> +    private BusLifeCycleManager lifeCycleManager;
>      /**
>       * This map holds the threading parameters that are to be applied
>       * to new Engines when bound to the reference id.
> @@ -89,7 +79,8 @@
>
>      public JettyHTTPServerEngineFactory() {
>          // Empty
> -    }
> +    }
> +
>
>      /**
>       * This call is used to set the bus. It should only be called
> once. @@ -104,7 +95,13 @@
>
>      @PostConstruct
>      public void registerWithBus() {
> -        bus.setExtension(this, JettyHTTPServerEngineFactory.class);
> +        if (bus != null) {
> +            bus.setExtension(this,
> JettyHTTPServerEngineFactory.class); +        }
> +        lifeCycleManager =
> bus.getExtension(BusLifeCycleManager.class); +        if (null !=
> lifeCycleManager) {
> +            lifeCycleManager.registerLifeCycleListener(this);
> +        }
>      }
>
>
> @@ -200,6 +197,29 @@
>      @PostConstruct
>      public void finalizeConfig() {
>          registerWithBus();
> +    }
> +
> +    public void initComplete() {
> +        // do nothing here
> +
> +    }
> +
> +    public void postShutdown() {
> +        // clean up the collections
> +        portMap.clear();
> +        threadingParametersMap.clear();
> +        tlsParametersMap.clear();
> +    }
> +
> +    public void preShutdown() {
> +        // shut down the jetty server in the portMap
> +        // To avoid the CurrentModificationException,
> +        // do not use portMap.vaules directly
> +
> +        JettyHTTPServerEngine[] engines =
> portMap.values().toArray(new JettyHTTPServerEngine[0]); +        for
> (JettyHTTPServerEngine engine : engines) {
> +            engine.shutdown();
> +        }
>      }
>
>  }



-- 
J. Daniel Kulp
Principal Engineer
IONA
P: 781-902-8727    C: 508-380-7194
daniel.kulp@iona.com
http://www.dankulp.com/blog

Re: svn commit: r577477 - /incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java

Posted by Willem Jiang <ni...@iona.com>.
Hi Dan,

Thank you for pointing me that , I will add the checking code for engine 
Jetty server's reference before I shutdown the engine.

Thanks,

Willem.

Daniel Kulp wrote:
> Willem,
>
> I think this commit will cause more problems.
>
> With this commit, if you have two busses in your application with 
> services registered in each, if you shutdown one bus, all the services 
> get killed.   We definitely don't want that.  
>
> Basically, the engine needs to track how many services are registered on 
> a port, and when that drops to 0, then possibly shutdown.
>
> Dan
>
>
>
> On Wednesday 19 September 2007, ningjiang@apache.org wrote:
>   
>> Author: ningjiang
>> Date: Wed Sep 19 16:59:24 2007
>> New Revision: 577477
>>
>> URL: http://svn.apache.org/viewvc?rev=577477&view=rev
>> Log:
>> CXF-1034 shutdown the JettyEngine when bus shutdown is called
>>
>> Modified:
>>    
>> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>> cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java
>>
>> Modified:
>> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>> cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java URL:
>> http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/http-je
>> tty/src/main/java/org/apache/cxf/transport/http_jetty/JettyHTTPServerEn
>> gineFactory.java?rev=577477&r1=577476&r2=577477&view=diff
>> ======================================================================
>> ======== ---
>> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>> cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java (original)
>> +++
>> incubator/cxf/trunk/rt/transports/http-jetty/src/main/java/org/apache/
>> cxf/transport/http_jetty/JettyHTTPServerEngineFactory.java Wed Sep 19
>> 16:59:24 2007 @@ -30,6 +30,8 @@
>>  import javax.annotation.Resource;
>>
>>  import org.apache.cxf.Bus;
>> +import org.apache.cxf.buslifecycle.BusLifeCycleListener;
>> +import org.apache.cxf.buslifecycle.BusLifeCycleManager;
>>  import org.apache.cxf.common.logging.LogUtils;
>>  import org.apache.cxf.configuration.jsse.TLSServerParameters;
>>
>> @@ -42,31 +44,19 @@
>>   * caches the JettyHTTPServerEngines so that they may be
>>   * retrieved if already previously configured.
>>   */
>> -public class JettyHTTPServerEngineFactory {
>> +public class JettyHTTPServerEngineFactory implements
>> BusLifeCycleListener { private static final Logger LOG =
>>          LogUtils.getL7dLogger(JettyHTTPServerEngineFactory.class);
>>
>>      /**
>>       * This map holds references for allocated ports.
>>       */
>> -    // All system tests do not shut down bus correctly,
>> -    // or the bus does not shutdown all endpoints correctly,
>> -    // so that these server endings are actuall shared amongst busses
>> -    // within the same JVM.
>> -
>> -    // We will keep it static until we can resolve the problems
>> -    // in the System tests.
>> -    // TODO: Fix the System Tests so that they shutdown the
>> -    // buses that they are using and that the buses actually
>> -    // shutdown the destinations and their server engines
>> -    // properly. This will require a bit of lifecyle and reference
>> -    // counting on Destinations to server engines, if they are
>> -    // going to be shared, but they should by no means be
>> -    // shared accross buses, right?
>> +    // Still use the static map to hold the port information
>> +    // in the same JVM
>>      private static Map<Integer, JettyHTTPServerEngine> portMap =
>>          new HashMap<Integer, JettyHTTPServerEngine>();
>>
>> -
>> +    private BusLifeCycleManager lifeCycleManager;
>>      /**
>>       * This map holds the threading parameters that are to be applied
>>       * to new Engines when bound to the reference id.
>> @@ -89,7 +79,8 @@
>>
>>      public JettyHTTPServerEngineFactory() {
>>          // Empty
>> -    }
>> +    }
>> +
>>
>>      /**
>>       * This call is used to set the bus. It should only be called
>> once. @@ -104,7 +95,13 @@
>>
>>      @PostConstruct
>>      public void registerWithBus() {
>> -        bus.setExtension(this, JettyHTTPServerEngineFactory.class);
>> +        if (bus != null) {
>> +            bus.setExtension(this,
>> JettyHTTPServerEngineFactory.class); +        }
>> +        lifeCycleManager =
>> bus.getExtension(BusLifeCycleManager.class); +        if (null !=
>> lifeCycleManager) {
>> +            lifeCycleManager.registerLifeCycleListener(this);
>> +        }
>>      }
>>
>>
>> @@ -200,6 +197,29 @@
>>      @PostConstruct
>>      public void finalizeConfig() {
>>          registerWithBus();
>> +    }
>> +
>> +    public void initComplete() {
>> +        // do nothing here
>> +
>> +    }
>> +
>> +    public void postShutdown() {
>> +        // clean up the collections
>> +        portMap.clear();
>> +        threadingParametersMap.clear();
>> +        tlsParametersMap.clear();
>> +    }
>> +
>> +    public void preShutdown() {
>> +        // shut down the jetty server in the portMap
>> +        // To avoid the CurrentModificationException,
>> +        // do not use portMap.vaules directly
>> +
>> +        JettyHTTPServerEngine[] engines =
>> portMap.values().toArray(new JettyHTTPServerEngine[0]); +        for
>> (JettyHTTPServerEngine engine : engines) {
>> +            engine.shutdown();
>> +        }
>>      }
>>
>>  }
>>     
>
>
>
>