incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r964314 - in /sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl: SlingMainServlet.java helper/RequestListenerManager.java
Date Thu, 15 Jul 2010 06:43:17 GMT
Author: cziegeler
Date: Thu Jul 15 06:43:16 2010
New Revision: 964314

URL: http://svn.apache.org/viewvc?rev=964314&view=rev
Log:
Code formatting and close service tracker on deactivate

Modified:
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
    sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java?rev=964314&r1=964313&r2=964314&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/SlingMainServlet.java
Thu Jul 15 06:43:16 2010
@@ -173,8 +173,8 @@ public class SlingMainServlet extends Ge
     private SlingFilterChainHelper requestFilterChain = new SlingFilterChainHelper();
 
     private SlingFilterChainHelper innerFilterChain = new SlingFilterChainHelper();
-    
-    private RequestListenerManager requestListenerManager; 
+
+    private RequestListenerManager requestListenerManager;
 
     private boolean allowTrace = DEFAULT_ALLOW_TRACE;
 
@@ -187,10 +187,10 @@ public class SlingMainServlet extends Ge
 
         if (req instanceof HttpServletRequest
             && res instanceof HttpServletResponse) {
-        	
+
             HttpServletRequest request = (HttpServletRequest) req;
 
-        	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(), 
+        	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(),
         			request, SlingRequestEvent.EventType.EVENT_INIT ) );
 
             // set the thread name according to the request
@@ -245,7 +245,7 @@ public class SlingMainServlet extends Ge
 
             } finally {
 
-            	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(),

+            	requestListenerManager.sendEvent( new SlingRequestEvent( getServletContext(),
             			request, SlingRequestEvent.EventType.EVENT_DESTROY ) );
                 // reset the thread name
                 if (threadName != null) {
@@ -630,7 +630,7 @@ public class SlingMainServlet extends Ge
                 initFilter(componentContext, serviceReference);
             }
         }
-        
+
         // initialize requestListenerManager
         requestListenerManager = new RequestListenerManager( bundleContext );
 
@@ -650,6 +650,11 @@ public class SlingMainServlet extends Ge
             this.printerRegistration = null;
         }
 
+        if ( this.requestListenerManager != null ) {
+            this.requestListenerManager.dispose();
+            this.requestListenerManager = null;
+        }
+
         // first destroy the filters
         destroyFilters(innerFilterChain);
         destroyFilters(requestFilterChain);

Modified: sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java?rev=964314&r1=964313&r2=964314&view=diff
==============================================================================
--- sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
(original)
+++ sling/trunk/bundles/engine/src/main/java/org/apache/sling/engine/impl/helper/RequestListenerManager.java
Thu Jul 15 06:43:16 2010
@@ -16,50 +16,32 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-
 package org.apache.sling.engine.impl.helper;
 
 import org.apache.sling.api.request.SlingRequestEvent;
 import org.apache.sling.api.request.SlingRequestListener;
 import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
 
 public class RequestListenerManager  {
-	
-    /** default log */
-    private final Logger log = LoggerFactory.getLogger(getClass());
-    
-    private ServiceTracker serviceTracker;
 
-	public RequestListenerManager ( BundleContext context )
-	{
+    private final ServiceTracker serviceTracker;
+
+	public RequestListenerManager( final BundleContext context ) {
 		serviceTracker = new ServiceTracker( context, SlingRequestListener.SERVICE_NAME, null );
 		serviceTracker.open();
-		
 	}
-	
-	public void sendEvent ( SlingRequestEvent event )
-	{
-		Object[] services = serviceTracker.getServices();
-		if ( services != null )
-		{
-			for ( Object service : services )
-			{
-				if ( service instanceof SlingRequestListener )
-				{
-					( (SlingRequestListener) service ).onEvent( event );
-				}
-				else
-				{
-					log.error( "Implementation of service named " + SlingRequestListener.SERVICE_NAME +

-							" does not implement service interface " + SlingRequestListener.class.getName() +
"." );
-				}
+
+	public void sendEvent ( final SlingRequestEvent event ) {
+		final Object[] services = serviceTracker.getServices();
+		if ( services != null ) {
+			for ( final Object service : services ) {
+				( (SlingRequestListener) service ).onEvent( event );
 			}
 		}
 	}
-	
 
+	public void dispose() {
+	    this.serviceTracker.close();
+	}
 }



Mime
View raw message