FELIX-4060 : Implement HTTP Service Update (RFC-189) - clean up manager implementations by moving code where it belongs
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1670915 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
index 7b74a4a..546b2f4 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/ServletContextHelperManager.java
@@ -58,6 +58,16 @@
import org.apache.felix.http.base.internal.runtime.dto.RegistryRuntime;
import org.apache.felix.http.base.internal.runtime.dto.ServletContextHelperRuntime;
import org.apache.felix.http.base.internal.util.MimeTypes;
+import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestAttributeListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestListenerTracker;
+import org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
@@ -69,6 +79,7 @@
import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.runtime.HttpServiceRuntime;
import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
+import org.osgi.util.tracker.ServiceTracker;
public final class ServletContextHelperManager
{
@@ -92,17 +103,18 @@
private volatile ServiceRegistration<ServletContextHelper> defaultContextRegistration;
+ private final List<ServiceTracker<?, ?>> trackers = new ArrayList<ServiceTracker<?, ?>>();
+
/**
* Create a new servlet context helper manager
* and the default context
*/
public ServletContextHelperManager(final BundleContext bundleContext,
- final WhiteboardHttpService httpService,
- final ListenerRegistry listenerRegistry)
+ final HandlerRegistry registry)
{
this.bundleContext = bundleContext;
- this.httpService = httpService;
- this.listenerRegistry = listenerRegistry;
+ this.httpService = new WhiteboardHttpService(this.bundleContext, registry);
+ this.listenerRegistry = new ListenerRegistry(bundleContext.getBundle());
}
public void start(ServletContext webContext, ServiceReference<HttpServiceRuntime> httpServiceRuntime)
@@ -145,13 +157,38 @@
// nothing to do
}
}, props);
+ addTracker(new FilterTracker(this.bundleContext, this));
+ addTracker(new ServletTracker(this.bundleContext, this));
+ addTracker(new ResourceTracker(this.bundleContext, this));
+
+ addTracker(new HttpSessionListenerTracker(this.bundleContext, this));
+ addTracker(new HttpSessionAttributeListenerTracker(this.bundleContext, this));
+
+ addTracker(new ServletContextHelperTracker(this.bundleContext, this));
+ addTracker(new ServletContextListenerTracker(this.bundleContext, this));
+ addTracker(new ServletContextAttributeListenerTracker(this.bundleContext, this));
+
+ addTracker(new ServletRequestListenerTracker(this.bundleContext, this));
+ addTracker(new ServletRequestAttributeListenerTracker(this.bundleContext, this));
+ }
+
+ private void addTracker(ServiceTracker<?, ?> tracker)
+ {
+ this.trackers.add(tracker);
+ tracker.open();
}
/**
- * Clean up the instance
+ * Stop the instance
*/
- public void close()
+ public void stop()
{
+ for(final ServiceTracker<?, ?> t : this.trackers)
+ {
+ t.close();
+ }
+ this.trackers.clear();
+
// TODO cleanup
if (this.defaultContextRegistration != null)
{
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
index acf0a86..f750db2 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
@@ -16,9 +16,7 @@
*/
package org.apache.felix.http.base.internal.whiteboard;
-import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -30,28 +28,15 @@
import org.apache.felix.http.base.internal.handler.HttpSessionWrapper;
import org.apache.felix.http.base.internal.service.HttpServiceFactory;
import org.apache.felix.http.base.internal.service.HttpServiceRuntimeImpl;
-import org.apache.felix.http.base.internal.whiteboard.tracker.FilterTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.HttpSessionListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ResourceTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextHelperTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletContextListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestAttributeListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletRequestListenerTracker;
-import org.apache.felix.http.base.internal.whiteboard.tracker.ServletTracker;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.http.runtime.HttpServiceRuntime;
import org.osgi.service.http.runtime.HttpServiceRuntimeConstants;
-import org.osgi.util.tracker.ServiceTracker;
public final class WhiteboardManager
{
private final BundleContext bundleContext;
- private final List<ServiceTracker<?, ?>> trackers = new ArrayList<ServiceTracker<?, ?>>();
-
private final HttpServiceFactory httpServiceFactory;
private final HttpServiceRuntimeImpl serviceRuntime;
@@ -64,7 +49,7 @@
* Create a new whiteboard http manager
* @param bundleContext
* @param httpServiceFactory
- * @param registry
+ * @param registry
*/
public WhiteboardManager(final BundleContext bundleContext,
final HttpServiceFactory httpServiceFactory,
@@ -72,9 +57,7 @@
{
this.bundleContext = bundleContext;
this.httpServiceFactory = httpServiceFactory;
- WhiteboardHttpService whiteboardHttpService = new WhiteboardHttpService(this.bundleContext, registry);
- ListenerRegistry listenerRegistry = new ListenerRegistry(bundleContext.getBundle());
- this.contextManager = new ServletContextHelperManager(bundleContext, whiteboardHttpService, listenerRegistry);
+ this.contextManager = new ServletContextHelperManager(bundleContext, registry);
this.serviceRuntime = new HttpServiceRuntimeImpl(registry, this.contextManager);
}
@@ -88,34 +71,11 @@
this.serviceRuntime.getAttributes());
this.contextManager.start(context, this.runtimeServiceReg.getReference());
-
- addTracker(new FilterTracker(this.bundleContext, contextManager));
- addTracker(new ServletTracker(this.bundleContext, this.contextManager));
- addTracker(new ResourceTracker(this.bundleContext, this.contextManager));
-
- addTracker(new HttpSessionListenerTracker(this.bundleContext, this.contextManager));
- addTracker(new HttpSessionAttributeListenerTracker(this.bundleContext, this.contextManager));
-
- addTracker(new ServletContextHelperTracker(this.bundleContext, this.contextManager));
- addTracker(new ServletContextListenerTracker(this.bundleContext, this.contextManager));
- addTracker(new ServletContextAttributeListenerTracker(this.bundleContext, this.contextManager));
-
- addTracker(new ServletRequestListenerTracker(this.bundleContext, this.contextManager));
- addTracker(new ServletRequestAttributeListenerTracker(this.bundleContext, this.contextManager));
}
public void stop()
{
- for(final ServiceTracker<?, ?> t : this.trackers)
- {
- t.close();
- }
- this.trackers.clear();
-
- if ( this.contextManager != null )
- {
- this.contextManager.close();
- }
+ this.contextManager.stop();
if ( this.runtimeServiceReg != null )
{
@@ -124,12 +84,6 @@
}
}
- private void addTracker(ServiceTracker<?, ?> tracker)
- {
- this.trackers.add(tracker);
- tracker.open();
- }
-
public void setProperties(final Hashtable<String, Object> props)
{
// runtime service gets the same props for now