cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aadamc...@apache.org
Subject svn commit: r952697 - in /cayenne/main/trunk/framework: cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/ cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/ cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuratio...
Date Tue, 08 Jun 2010 15:35:26 GMT
Author: aadamchik
Date: Tue Jun  8 15:35:26 2010
New Revision: 952697

URL: http://svn.apache.org/viewvc?rev=952697&view=rev
Log:
CAY-1421 CayenneRuntime shutdown functionality

* adding Injector shutdown functionality and hooking it up to CayenneFilter and ROP servlet

Modified:
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
    cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
    cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java?rev=952697&r1=952696&r2=952697&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/Injector.java
Tue Jun  8 15:35:26 2010
@@ -52,4 +52,11 @@ public interface Injector {
      * initialize tested objects that are relying on field injecton.
      */
     void injectMembers(Object object);
+
+    /**
+     * A lifecycle method that let's the injector's services to clean up their state and
+     * release resources. This method would normally generate a scope end event for the
+     * injector's one and only singleton scope.
+     */
+    void shutdown();
 }

Modified: cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java?rev=952697&r1=952696&r2=952697&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
(original)
+++ cayenne/main/trunk/framework/cayenne-di-unpublished/src/main/java/org/apache/cayenne/di/spi/DefaultInjector.java
Tue Jun  8 15:35:26 2010
@@ -25,6 +25,7 @@ import org.apache.cayenne.ConfigurationE
 import org.apache.cayenne.di.Injector;
 import org.apache.cayenne.di.Key;
 import org.apache.cayenne.di.Module;
+import org.apache.cayenne.di.OnScopeEnd;
 import org.apache.cayenne.di.Provider;
 import org.apache.cayenne.di.Scope;
 
@@ -137,6 +138,10 @@ public class DefaultInjector implements 
         provider1.get();
     }
 
+    public void shutdown() {
+        singletonScope.postScopeEvent(OnScopeEnd.class);
+    };
+
     SingletonScope getSingletonScope() {
         return singletonScope;
     }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java?rev=952697&r1=952696&r2=952697&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/rop/server/ROPHessianServlet.java
Tue Jun  8 15:35:26 2010
@@ -22,9 +22,11 @@ import java.util.Collection;
 import java.util.Map;
 
 import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
 
 import org.apache.cayenne.DataChannel;
+import org.apache.cayenne.configuration.CayenneRuntime;
 import org.apache.cayenne.configuration.server.CayenneServerModule;
 import org.apache.cayenne.configuration.server.CayenneServerRuntime;
 import org.apache.cayenne.configuration.web.RequestHandler;
@@ -59,17 +61,20 @@ import com.caucho.hessian.server.Hessian
  */
 public class ROPHessianServlet extends HessianServlet {
 
+    protected ServletContext servletContext;
+
     /**
      * Installs {@link HessianService} to respond to {@link RemoteService} requests.
      */
     @Override
     public void init(ServletConfig configuration) throws ServletException {
 
+        this.servletContext = configuration.getServletContext();
+
         WebConfiguration configAdapter = new WebConfiguration(configuration);
 
         String configurationLocation = configAdapter.getConfigurationLocation();
-        Map<String, String> eventBridgeParameters = configAdapter
-                .getOtherParameters();
+        Map<String, String> eventBridgeParameters = configAdapter.getOtherParameters();
 
         Collection<Module> modules = configAdapter
                 .createModules(
@@ -97,7 +102,18 @@ public class ROPHessianServlet extends H
         // TODO: andrus 04/14/2010: if CayenneFilter and ROPHessianServlet are used
         // together in the same webapp, maybe a good idea to ensure they are using the
         // same stack...Merging CayenneRuntime's modules might be tough though.
-        WebUtil.setCayenneRuntime(configuration.getServletContext(), runtime);
+
+        WebUtil.setCayenneRuntime(servletContext, runtime);
         super.init(configuration);
     }
+
+    @Override
+    public void destroy() {
+        super.destroy();
+
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
+        if (runtime != null) {
+            runtime.getInjector().shutdown();
+        }
+    }
 }

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java?rev=952697&r1=952696&r2=952697&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/configuration/web/CayenneFilter.java
Tue Jun  8 15:35:26 2010
@@ -76,7 +76,11 @@ public class CayenneFilter implements Fi
     }
 
     public void destroy() {
-        // noop for now...
+        CayenneRuntime runtime = WebUtil.getCayenneRuntime(servletContext);
+
+        if (runtime != null) {
+            runtime.getInjector().shutdown();
+        }
     }
 
     public void doFilter(

Modified: cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
URL: http://svn.apache.org/viewvc/cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java?rev=952697&r1=952696&r2=952697&view=diff
==============================================================================
--- cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
(original)
+++ cayenne/main/trunk/framework/cayenne-jdk1.5-unpublished/src/main/java/org/apache/cayenne/event/DefaultEventManager.java
Tue Jun  8 15:35:26 2010
@@ -27,6 +27,7 @@ import java.util.Map;
 import java.util.WeakHashMap;
 
 import org.apache.cayenne.CayenneRuntimeException;
+import org.apache.cayenne.di.OnScopeEnd;
 import org.apache.cayenne.util.Invocation;
 
 /**
@@ -97,6 +98,7 @@ public class DefaultEventManager impleme
      * 
      * @since 3.0
      */
+    @OnScopeEnd
     public void shutdown() {
         this.stopped = true;
 



Mime
View raw message