incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r609642 - /incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Date Mon, 07 Jan 2008 15:51:28 GMT
Author: fmeschbe
Date: Mon Jan  7 07:51:20 2008
New Revision: 609642

URL: http://svn.apache.org/viewvc?rev=609642&view=rev
Log:
Reorganize servlet initialization, because ServletContext is now a static required
reference and thus always set BEFORE the component is activate. Thus we now can
safely assume that when the component is active, the servlet context is available.
Likewise, for symmetry, servlets are destroyed when the component is deactivated.

Modified:
    incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java

Modified: incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java?rev=609642&r1=609641&r2=609642&view=diff
==============================================================================
--- incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
(original)
+++ incubator/sling/whiteboard/fmeschbe/resource/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/SlingServletResolver.java
Mon Jan  7 07:51:20 2008
@@ -339,74 +339,50 @@
                 }
             }
         }
-    }
+        
+        Collection<ServiceReference> refs;
+        synchronized (this) {
 
-    protected synchronized void bindServlet(ServiceReference reference) {
-        if (context == null || servletContext == null) {
-            pendingServlets.add(reference);
-        } else {
-            createServlet(servletContext, reference);
-        }
-    }
+            refs = pendingServlets;
+            pendingServlets = new ArrayList<ServiceReference>();
+            
+            // register servlets immediately from now on
+            this.context = context;
 
-    protected synchronized void unbindServlet(ServiceReference reference) {
-        if (context == null || servletContext == null) {
-            pendingServlets.remove(reference);
-        } else {
-            destroyServlet(reference);
         }
-    }
 
-    protected void bindServletContext(ServletContext newServletContext) {
+        createAllServlets(refs);
+    }
 
-        boolean destroy;
+    protected void deactivate(ComponentContext context) {
+        
+        // destroy all active servlets
         Collection<ServiceReference> refs;
-
         synchronized (this) {
-
-            if (this.servletContext == null) {
-
-                refs = pendingServlets;
-                pendingServlets = new ArrayList<ServiceReference>();
-                destroy = false;
-
-            } else {
-
-                refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
-                destroy = true;
-
-            }
-
-            this.servletContext = newServletContext;
+            refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
+            this.context = null;
         }
 
-        if (destroy) {
-            destroyAllServlets(refs);
+        // destroy all servlets
+        destroyAllServlets(refs);
+    }
+    
+    protected synchronized void bindServlet(ServiceReference reference) {
+        if (context == null) {
+            pendingServlets.add(reference);
+        } else {
+            createServlet(servletContext, reference);
         }
-
-        createAllServlets(this.servletContext, refs);
     }
 
-    protected void unbindServletContext(ServletContext oldServletContext) {
-
-        if (this.servletContext == oldServletContext) {
-
-            Collection<ServiceReference> refs;
-            synchronized (this) {
-                refs = new ArrayList<ServiceReference>(servletsByReference.keySet());
-                pendingServlets.addAll(refs);
-                this.servletContext = null;
-            }
-
-            // destroy all servlets
-            destroyAllServlets(refs);
-        }
+    protected synchronized void unbindServlet(ServiceReference reference) {
+        pendingServlets.remove(reference);
+        destroyServlet(reference);
     }
 
     // ---------- Servlet Management -------------------------------------------
 
-    private void createAllServlets(ServletContext servletContext,
-            Collection<ServiceReference> pendingServlets) {
+    private void createAllServlets(Collection<ServiceReference> pendingServlets) {
         for (ServiceReference serviceReference : pendingServlets) {
             createServlet(servletContext, serviceReference);
         }



Mime
View raw message