FELIX-4781 : Implement various listeners. Ignore new whiteboard listeners for Http Service

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1659549 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/AbstractListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/AbstractListenerManager.java
index 7ca8ff7..10bfeb1 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/AbstractListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/AbstractListenerManager.java
@@ -21,22 +21,21 @@
 import java.util.ArrayList;
 import java.util.Iterator;
 
-
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.Filter;
 import org.osgi.framework.ServiceReference;
 import org.osgi.util.tracker.ServiceTracker;
 
-public class AbstractListenerManager<ListenerType> extends ServiceTracker
+public class AbstractListenerManager<ListenerType> extends ServiceTracker<ListenerType, ListenerType>
 {
 
     private ArrayList<ListenerType> allContextListeners;
 
-    private final Object lock;
+    private final Object lock = new Object();
 
-    protected AbstractListenerManager(BundleContext context, Class<ListenerType> clazz)
+    protected AbstractListenerManager(final BundleContext context, final Filter filter)
     {
-        super(context, clazz.getName(), null);
-        lock = new Object();
+        super(context, filter, null);
     }
 
     @SuppressWarnings("unchecked")
@@ -74,7 +73,7 @@
     }
 
     @Override
-    public Object addingService(ServiceReference reference)
+    public ListenerType addingService(ServiceReference<ListenerType> reference)
     {
         synchronized (lock)
         {
@@ -85,7 +84,7 @@
     }
 
     @Override
-    public void modifiedService(ServiceReference reference, Object service)
+    public void modifiedService(ServiceReference<ListenerType> reference, ListenerType service)
     {
         synchronized (lock)
         {
@@ -96,7 +95,7 @@
     }
 
     @Override
-    public void removedService(ServiceReference reference, Object service)
+    public void removedService(ServiceReference<ListenerType> reference, ListenerType service)
     {
         synchronized (lock)
         {
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionAttributeListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionAttributeListenerManager.java
index 1bad90d..81ef246 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionAttributeListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionAttributeListenerManager.java
@@ -24,6 +24,8 @@
 import javax.servlet.http.HttpSessionBindingEvent;
 
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
  * The <code>ProxyListener</code> implements the Servlet API 2.4 listener
@@ -33,12 +35,27 @@
 public class HttpSessionAttributeListenerManager extends AbstractListenerManager<HttpSessionAttributeListener>
     implements HttpSessionAttributeListener
 {
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+    {
+        try
+        {
+            return btx.createFilter(String.format("(&(objectClass=%s)(!(%s=*)))",
+                    HttpSessionAttributeListener.class.getName(),
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+        }
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if we get an NPE which is fine
+    }
 
     public HttpSessionAttributeListenerManager(BundleContext context)
     {
-        super(context, HttpSessionAttributeListener.class);
+        super(context, createFilter(context));
     }
 
+    @Override
     public void attributeAdded(final HttpSessionBindingEvent se)
     {
         final Iterator<HttpSessionAttributeListener> listeners = getContextListeners();
@@ -48,6 +65,7 @@
         }
     }
 
+    @Override
     public void attributeRemoved(final HttpSessionBindingEvent se)
     {
         final Iterator<HttpSessionAttributeListener> listeners = getContextListeners();
@@ -57,6 +75,7 @@
         }
     }
 
+    @Override
     public void attributeReplaced(final HttpSessionBindingEvent se)
     {
         final Iterator<HttpSessionAttributeListener> listeners = getContextListeners();
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionListenerManager.java
index 890dc48..9887003 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/HttpSessionListenerManager.java
@@ -24,6 +24,8 @@
 import javax.servlet.http.HttpSessionListener;
 
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
  * The <code>ProxyListener</code> implements the Servlet API 2.4 listener
@@ -33,12 +35,27 @@
 public class HttpSessionListenerManager extends AbstractListenerManager<HttpSessionListener> implements
     HttpSessionListener
 {
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+    {
+        try
+        {
+            return btx.createFilter(String.format("(&(objectClass=%s)(!(%s=*)))",
+                    HttpSessionListener.class.getName(),
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+        }
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if we get an NPE which is fine
+    }
 
     public HttpSessionListenerManager(BundleContext context)
     {
-        super(context, HttpSessionListener.class);
+        super(context, createFilter(context));
     }
 
+    @Override
     public void sessionCreated(final HttpSessionEvent se)
     {
         final Iterator<HttpSessionListener> listeners = getContextListeners();
@@ -48,6 +65,7 @@
         }
     }
 
+    @Override
     public void sessionDestroyed(final HttpSessionEvent se)
     {
         final Iterator<HttpSessionListener> listeners = getContextListeners();
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletContextAttributeListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletContextAttributeListenerManager.java
index e65704e..e071be6 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletContextAttributeListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletContextAttributeListenerManager.java
@@ -22,7 +22,10 @@
 
 import javax.servlet.ServletContextAttributeEvent;
 import javax.servlet.ServletContextAttributeListener;
+
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
  * The <code>ProxyListener</code> implements the Servlet API 2.4 listener
@@ -32,12 +35,27 @@
 public class ServletContextAttributeListenerManager extends AbstractListenerManager<ServletContextAttributeListener>
     implements ServletContextAttributeListener
 {
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+    {
+        try
+        {
+            return btx.createFilter(String.format("(&(objectClass=%s)(!(%s=*)))",
+                    ServletContextAttributeListener.class.getName(),
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+        }
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if we get an NPE which is fine
+    }
 
     public ServletContextAttributeListenerManager(BundleContext context)
     {
-        super(context, ServletContextAttributeListener.class);
+        super(context, createFilter(context));
     }
 
+    @Override
     public void attributeAdded(final ServletContextAttributeEvent scab)
     {
         final Iterator<ServletContextAttributeListener> listeners = getContextListeners();
@@ -47,6 +65,7 @@
         }
     }
 
+    @Override
     public void attributeRemoved(final ServletContextAttributeEvent scab)
     {
         final Iterator<ServletContextAttributeListener> listeners = getContextListeners();
@@ -56,6 +75,7 @@
         }
     }
 
+    @Override
     public void attributeReplaced(final ServletContextAttributeEvent scab)
     {
         final Iterator<ServletContextAttributeListener> listeners = getContextListeners();
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestAttributeListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestAttributeListenerManager.java
index 25c1710..3faa0db 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestAttributeListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestAttributeListenerManager.java
@@ -24,6 +24,8 @@
 import javax.servlet.ServletRequestAttributeListener;
 
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
  * The <code>ProxyListener</code> implements the Servlet API 2.4 listener
@@ -32,10 +34,24 @@
  */
 public class ServletRequestAttributeListenerManager extends AbstractListenerManager<ServletRequestAttributeListener>
 {
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+    {
+        try
+        {
+            return btx.createFilter(String.format("(&(objectClass=%s)(!(%s=*)))",
+                    ServletRequestAttributeListener.class.getName(),
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+        }
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if we get an NPE which is fine
+    }
 
     public ServletRequestAttributeListenerManager(BundleContext context)
     {
-        super(context, ServletRequestAttributeListener.class);
+        super(context, createFilter(context));
     }
 
     public void attributeAdded(final ServletRequestAttributeEvent srae)
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestListenerManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestListenerManager.java
index 627ec5a..3ecd699 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestListenerManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/listener/ServletRequestListenerManager.java
@@ -24,6 +24,8 @@
 import javax.servlet.ServletRequestListener;
 
 import org.osgi.framework.BundleContext;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.http.whiteboard.HttpWhiteboardConstants;
 
 /**
  * The <code>ProxyListener</code> implements the Servlet API 2.4 listener
@@ -32,10 +34,24 @@
  */
 public class ServletRequestListenerManager extends AbstractListenerManager<ServletRequestListener>
 {
+    private static org.osgi.framework.Filter createFilter(final BundleContext btx)
+    {
+        try
+        {
+            return btx.createFilter(String.format("(&(objectClass=%s)(!(%s=*)))",
+                    ServletRequestListener.class.getName(),
+                    HttpWhiteboardConstants.HTTP_WHITEBOARD_LISTENER));
+        }
+        catch ( final InvalidSyntaxException ise)
+        {
+            // we can safely ignore it as the above filter is a constant
+        }
+        return null; // we never get here - and if we get an NPE which is fine
+    }
 
     public ServletRequestListenerManager(BundleContext context)
     {
-        super(context, ServletRequestListener.class);
+        super(context, createFilter(context));
     }
 
     public void requestDestroyed(final ServletRequestEvent sre)