You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by ni...@apache.org on 2006/09/14 11:12:27 UTC

svn commit: r443292 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/buslifecycle/ api/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/bus/ rt/core/src/main/java/org/apache/cxf/buslifecycle/ rt/core/src/main/java/...

Author: ningjiang
Date: Thu Sep 14 02:12:26 2006
New Revision: 443292

URL: http://svn.apache.org/viewvc?view=rev&rev=443292
Log:
[JIRA CXF-77] server will be stop when bus shutdown
 make BusLifeCycleManager can work with bus
 add ServerRegistry to hold server referece
 update the jms transport destination to make it stop when server is stopped

Added:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java   (with props)
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerRegistryImpl.java
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/ServerRegistryImpTest.java
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/buslifecycle/BusLifeCycleManager.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBus.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
    incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml
    incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusTest.java
    incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/buslifecycle/BusLifeCycleManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/buslifecycle/BusLifeCycleManager.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/buslifecycle/BusLifeCycleManager.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/buslifecycle/BusLifeCycleManager.java Thu Sep 14 02:12:26 2006
@@ -26,7 +26,7 @@
  * registered or unregistered to receive notification of <code>Bus</code>
  * lifecycle events.
  */
-public interface BusLifeCycleManager {
+public interface BusLifeCycleManager extends BusLifeCycleListener {
 
     /**
      * Register a listener to receive <code>Bus</code> lifecycle notification.

Added: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java?view=auto&rev=443292
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java (added)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java Thu Sep 14 02:12:26 2006
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.endpoint;
+
+import java.util.List;
+
+
+public interface ServerRegistry {
+    void register(Server server);
+    List<Server> getServers();
+}

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/ServerRegistry.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBus.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBus.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBus.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/CXFBus.java Thu Sep 14 02:12:26 2006
@@ -24,6 +24,7 @@
 import java.util.Map;
 
 import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.extension.ExtensionManagerImpl;
 import org.apache.cxf.interceptor.AbstractBasicInterceptorProvider;
 import org.apache.cxf.oldcfg.Configuration;
@@ -45,6 +46,7 @@
 
     private Map<Class, Object> extensions;
     private Configuration configuration;
+    private BusLifeCycleManager lifeCycleManager;
     private String id;
     private State state;
     
@@ -92,11 +94,16 @@
                                                     resourceManager);
         
         state = State.INITIAL;
+        
+        lifeCycleManager = this.getExtension(BusLifeCycleManager.class);
+        if (null != lifeCycleManager) {
+            lifeCycleManager.initComplete();
+        }
 
     }
 
       
-    public <T> T getExtension(Class<T> extensionType) {
+    public final <T> T getExtension(Class<T> extensionType) {
         Object obj = extensions.get(extensionType);
         if (null != obj) {
             return extensionType.cast(obj);
@@ -136,10 +143,16 @@
     }
 
     public void shutdown(boolean wait) {
-        // TODO: invoke PreDestroy on all resources
+        lifeCycleManager = this.getExtension(BusLifeCycleManager.class);
+        if (null != lifeCycleManager) {
+            lifeCycleManager.preShutdown();
+        }
         synchronized (this) {
             state = State.SHUTDOWN;
             notifyAll();
+        }
+        if (null != lifeCycleManager) {
+            lifeCycleManager.postShutdown();
         }
     }
     

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/buslifecycle/CXFBusLifeCycleManager.java Thu Sep 14 02:12:26 2006
@@ -47,20 +47,20 @@
         listeners.remove(listener);      
     }
     
-    void initComplete() {
+    public void initComplete() {
         for (BusLifeCycleListener listener : listeners) {
             listener.initComplete();
         }
     }
     
-    void preShutdown() {
+    public void preShutdown() {
         // TODO inverse order of registration?
         for (BusLifeCycleListener listener : listeners) {
             listener.preShutdown();
         }
     }
     
-    void postShutdown() {
+    public void postShutdown() {
         // TODO inverse order of registration?
         for (BusLifeCycleListener listener : listeners) {
             listener.postShutdown();

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java Thu Sep 14 02:12:26 2006
@@ -20,6 +20,7 @@
 package org.apache.cxf.endpoint;
 
 import java.io.IOException;
+import java.util.logging.Logger;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusException;
@@ -31,19 +32,22 @@
 
 public class ServerImpl implements Server {
     
+    private static final Logger LOG = Logger.getLogger(ServerImpl.class.getName());
     private Destination destination;
     private MessageObserver messageObserver;
     private Endpoint endpoint;
-
+    private ServerRegistry serverRegistry;
+    
     public ServerImpl(Bus bus, Endpoint endpoint, MessageObserver observer) 
         throws BusException, IOException {
         this.endpoint = endpoint;
-        this.messageObserver = observer;
+        this.messageObserver = observer;       
 
         EndpointInfo ei = endpoint.getEndpointInfo();
         DestinationFactory destinationFactory = bus.getExtension(DestinationFactoryManager.class)
             .getDestinationFactory(ei.getTransportId());
         destination = destinationFactory.getDestination(ei);
+        serverRegistry = bus.getExtension(ServerRegistry.class);
     }
     
     public Destination getDestination() {
@@ -54,13 +58,18 @@
         this.destination = destination;
     }
 
-    public void start() {
+    public void start() {        
         getDestination().setMessageObserver(messageObserver);
+        //regist the active server to run
+        if (null != serverRegistry) {
+            LOG.fine("register the server to serverRegistry ");
+            serverRegistry.register(this);
+        }
     }
 
     public void stop() {
-        getDestination().setMessageObserver(null);
-        
+        System.out.println("server to be stopped!");
+        getDestination().setMessageObserver(null);        
     }
 
     public MessageObserver getMessageObserver() {

Added: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerRegistryImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerRegistryImpl.java?view=auto&rev=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerRegistryImpl.java (added)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ServerRegistryImpl.java Thu Sep 14 02:12:26 2006
@@ -0,0 +1,80 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.endpoint;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
+
+public class ServerRegistryImpl implements ServerRegistry, BusLifeCycleListener {
+    
+    List<Server> serversList;
+    Bus bus;
+    BusLifeCycleManager lifeCycleManager;
+    
+    public ServerRegistryImpl() {
+        serversList = new ArrayList<Server>();
+    }
+
+    public Bus getBus() {
+        return bus;
+    }
+    
+    @Resource
+    public void setBus(Bus bus) {        
+        this.bus = bus;
+        lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
+        if (null != lifeCycleManager) {
+            lifeCycleManager.registerLifeCycleListener(this);
+        }
+    }
+    
+    public void register(Server server) {
+        serversList.add(server);        
+    }
+
+    public List<Server> getServers() {
+        return serversList;
+    }
+
+    public void initComplete() {
+        // TODO Auto-generated method stub
+        
+    }
+
+    public void preShutdown() {
+        // Shutdown the service       
+        for (Server server : serversList) {
+            System.out.println("call the server stop");
+            server.stop();
+        }
+    }
+
+    public void postShutdown() {
+        // TODO Auto-generated method stub
+        
+    }
+
+}

Modified: incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml (original)
+++ incubator/cxf/trunk/rt/core/src/main/resources/META-INF/bus-extensions.xml Thu Sep 14 02:12:26 2006
@@ -31,5 +31,9 @@
            interface="org.apache.cxf.phase.PhaseManager"/>
     <extension class="org.apache.cxf.workqueue.WorkQueueManagerImpl"
        	   interface="org.apache.cxf.workqueue.WorkQueueManager"/>
+    <extension class="org.apache.cxf.buslifecycle.CXFBusLifeCycleManager"
+       	   interface="org.apache.cxf.buslifecycle.BusLifeCycleManager"/>   	   
+    <extension class="org.apache.cxf.endpoint.ServerRegistryImpl"
+       	   interface="org.apache.cxf.endpoint.ServerRegistry"/>
     
 </extensions>

Modified: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusTest.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusTest.java (original)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/bus/CXFBusTest.java Thu Sep 14 02:12:26 2006
@@ -27,6 +27,8 @@
 import org.apache.cxf.BusException;
 import org.apache.cxf.binding.BindingFactoryManager;
 import org.apache.cxf.bus.CXFBus.State;
+import org.apache.cxf.buslifecycle.BusLifeCycleListener;
+import org.apache.cxf.buslifecycle.BusLifeCycleManager;
 import org.apache.cxf.event.EventProcessor;
 import org.apache.cxf.management.InstrumentationManager;
 import org.apache.cxf.oldcfg.Configuration;
@@ -142,6 +144,20 @@
         
     }
     
-    
+    public void testShutdownWithBusLifecycle() {
+        final CXFBus bus = new CXFBus();
+        BusLifeCycleManager lifeCycleManager = bus.getExtension(BusLifeCycleManager.class);
+        BusLifeCycleListener listener = EasyMock.createMock(BusLifeCycleListener.class);
+        EasyMock.reset(listener);
+        listener.preShutdown();
+        EasyMock.expectLastCall();
+        listener.postShutdown();
+        EasyMock.expectLastCall();        
+        EasyMock.replay(listener);        
+        lifeCycleManager.registerLifeCycleListener(listener);
+        bus.shutdown(true);
+        EasyMock.verify(listener);
+        
+    }
 
 }

Added: incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/ServerRegistryImpTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/ServerRegistryImpTest.java?view=auto&rev=443292
==============================================================================
--- incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/ServerRegistryImpTest.java (added)
+++ incubator/cxf/trunk/rt/core/src/test/java/org/apache/cxf/endpoint/ServerRegistryImpTest.java Thu Sep 14 02:12:26 2006
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cxf.endpoint;
+
+import junit.framework.TestCase;
+
+import org.easymock.classextension.EasyMock;
+
+public class ServerRegistryImpTest extends TestCase {
+    
+    public void testServerRegistryPreShutdown() {
+        ServerRegistryImpl serverRegistryImpl = new ServerRegistryImpl();        
+        Server server = EasyMock.createMock(Server.class);
+        EasyMock.reset(server);
+        server.stop();
+        EasyMock.expectLastCall();
+        EasyMock.replay(server);
+        serverRegistryImpl.register(server);
+        serverRegistryImpl.preShutdown();
+        EasyMock.verify(server);
+    }
+
+}

Modified: incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java?view=diff&rev=443292&r1=443291&r2=443292
==============================================================================
--- incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java (original)
+++ incubator/cxf/trunk/rt/transports/jms/src/main/java/org/apache/cxf/transport/jms/JMSDestination.java Thu Sep 14 02:12:26 2006
@@ -133,14 +133,23 @@
 
   
     public void setMessageObserver(MessageObserver observer) {
-        // to handle the incomming message
+        // to handle the incomming message        
+        if (null != observer) {
+            try {
+                activate();
+            } catch (IOException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        } else {
+            LOG.log(Level.FINE, "JMSDestination shutdown()");
+            try {
+                deactivate();
+            } catch (IOException e) {
+                //Ignore for now.
+            }
+        }
         incomingObserver = observer;
-        try {
-            activate();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } 
     }
     
     private void activate() throws IOException {