cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject [2/3] git commit: Add ability to register a closeable directly to the endpoint to have it called at shutdown/close to simplify cleanup of per client/service specific things
Date Fri, 14 Mar 2014 18:19:13 GMT
Add ability to register a closeable directly to the endpoint to have it called at shutdown/close
to simplify cleanup of per client/service specific things


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/4391aa5b
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/4391aa5b
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/4391aa5b

Branch: refs/heads/master
Commit: 4391aa5b0ba88c131d348f215ae5074590498f70
Parents: a546648
Author: Daniel Kulp <dkulp@apache.org>
Authored: Fri Mar 14 14:17:09 2014 -0400
Committer: Daniel Kulp <dkulp@apache.org>
Committed: Fri Mar 14 14:19:01 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/cxf/endpoint/ClientImpl.java   |  7 +++++++
 .../java/org/apache/cxf/endpoint/Endpoint.java     | 11 +++++++++++
 .../java/org/apache/cxf/endpoint/EndpointImpl.java | 17 +++++++++++++++++
 .../java/org/apache/cxf/endpoint/ServerImpl.java   |  8 ++++++++
 .../apache/cxf/jaxrs/client/AbstractClient.java    |  7 +++++++
 .../security/wss4j/AbstractPolicySecurityTest.java |  6 ++++++
 6 files changed, 56 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
index 43099cf..145e18e 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
@@ -148,6 +148,13 @@ public class ClientImpl
         if (bus == null) {
             return;
         }
+        for (Closeable c : getEndpoint().getCleanupHooks()) {
+            try {
+                c.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
         ClientLifeCycleManager mgr = bus.getExtension(ClientLifeCycleManager.class);
         if (null != mgr) {
             mgr.clientDestroyed(this);

http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/core/src/main/java/org/apache/cxf/endpoint/Endpoint.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/endpoint/Endpoint.java b/core/src/main/java/org/apache/cxf/endpoint/Endpoint.java
index e53bf0e..d88e51e 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/Endpoint.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/Endpoint.java
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.endpoint;
 
+import java.io.Closeable;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.Executor;
@@ -55,4 +56,14 @@ public interface Endpoint extends Map<String, Object>, InterceptorProvider
{
     void setOutFaultObserver(MessageObserver observer);
 
     List<Feature> getActiveFeatures();
+    
+    /**
+     * Add a hook that will be called when this end point being terminated.
+     * This will be called prior to the Server/ClientLifecycleListener.*Destroyed()
+     * method is called.  This provides an opportunity to cleanup any resources
+     * that are specific to this Endpoint. 
+     * @param c
+     */
+    void addCleanupHook(Closeable c);
+    List<Closeable> getCleanupHooks();
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java b/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java
index 0ba0d52..432fdf6 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/EndpointImpl.java
@@ -19,9 +19,12 @@
 
 package org.apache.cxf.endpoint;
 
+import java.io.Closeable;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.ResourceBundle;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.Executor;
 import java.util.logging.Logger;
 
@@ -62,6 +65,7 @@ public class EndpointImpl extends AbstractAttributedInterceptorProvider
implemen
     private MessageObserver inFaultObserver;
     private MessageObserver outFaultObserver;
     private List<Feature> activeFeatures;
+    private List<Closeable> cleanupHooks;
 
     public EndpointImpl(Bus bus, Service s, QName endpointName) throws EndpointException
{
         this(bus, s, s.getEndpointInfo(endpointName));
@@ -189,4 +193,17 @@ public class EndpointImpl extends AbstractAttributedInterceptorProvider
implemen
     public int hashCode() {
         return endpointInfo.hashCode();
     }
+    
+    public synchronized void addCleanupHook(Closeable c) {
+        if (cleanupHooks == null) {
+            cleanupHooks = new CopyOnWriteArrayList<Closeable>();
+        }
+        cleanupHooks.add(c);
+    }
+    public List<Closeable> getCleanupHooks() {
+        if (cleanupHooks == null) {
+            return Collections.emptyList();
+        }
+        return cleanupHooks;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java b/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
index c2c8799..6bba8c5 100644
--- a/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
+++ b/core/src/main/java/org/apache/cxf/endpoint/ServerImpl.java
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.endpoint;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
@@ -162,6 +163,13 @@ public class ServerImpl implements Server {
         
         LOG.fine("Server is stopping.");
         
+        for (Closeable c : endpoint.getCleanupHooks()) {
+            try {
+                c.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
         if (slcMgr != null) {
             slcMgr.stopServer(this);
         }

http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
----------------------------------------------------------------------
diff --git a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
index e57488a..8e7123d 100644
--- a/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
+++ b/rt/rs/client/src/main/java/org/apache/cxf/jaxrs/client/AbstractClient.java
@@ -289,6 +289,13 @@ public abstract class AbstractClient implements Client {
         if (cfg.getBus() == null) {
             return;
         }
+        for (Closeable c : cfg.getEndpoint().getCleanupHooks()) {
+            try {
+                c.close();
+            } catch (IOException e) {
+                //ignore
+            }
+        }
         ClientLifeCycleManager mgr = cfg.getBus().getExtension(ClientLifeCycleManager.class);
         if (null != mgr) {
             mgr.clientDestroyed(new FrontendClientAdapter(getConfiguration()));

http://git-wip-us.apache.org/repos/asf/cxf/blob/4391aa5b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/AbstractPolicySecurityTest.java
----------------------------------------------------------------------
diff --git a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/AbstractPolicySecurityTest.java
b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/AbstractPolicySecurityTest.java
index 19570a6..544c32b 100644
--- a/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/AbstractPolicySecurityTest.java
+++ b/rt/ws/security/src/test/java/org/apache/cxf/ws/security/wss4j/AbstractPolicySecurityTest.java
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.ws.security.wss4j;
 
+import java.io.Closeable;
 import java.net.URL;
 import java.util.Arrays;
 import java.util.Collection;
@@ -601,6 +602,11 @@ public abstract class AbstractPolicySecurityTest extends AbstractSecurityTest
{
 
         public void setOutFaultObserver(MessageObserver observer) {            
         }
+        public void addCleanupHook(Closeable c) {
+        }
+        public List<Closeable> getCleanupHooks() {
+            return null;
+        }
     }
     
     /**


Mime
View raw message