felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r1152217 - in /felix/trunk/framework/src/main/java/org/apache/felix/framework: Felix.java util/EventDispatcher.java util/ListenerInfo.java
Date Fri, 29 Jul 2011 13:36:41 GMT
Author: rickhall
Date: Fri Jul 29 13:36:40 2011
New Revision: 1152217

URL: http://svn.apache.org/viewvc?rev=1152217&view=rev
Log:
Revert some refactoring that removed the bundle reference from the listener info
object, since there are some corner cases where the bundle context becomes
invalid and we can no longer reach the bundle. (FELIX-3056)

Modified:
    felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
    felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ListenerInfo.java

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java?rev=1152217&r1=1152216&r2=1152217&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java (original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/Felix.java Fri Jul 29 13:36:40
2011
@@ -3091,7 +3091,7 @@ public class Felix extends BundleImpl im
         if (oldFilter != null)
         {
             final Collection removed = Collections.singleton(
-                new ListenerInfo(bundle._getBundleContext(),
+                new ListenerInfo(bundle, bundle._getBundleContext(),
                     ServiceListener.class, l, oldFilter, null, true));
             for (ServiceReference<org.osgi.framework.hooks.service.ListenerHook> sr
: listenerHooks)
             {
@@ -3117,7 +3117,7 @@ public class Felix extends BundleImpl im
 
         // Invoke the ListenerHook.added() on all hooks.
         final Collection added = Collections.singleton(
-            new ListenerInfo(bundle.getBundleContext(),
+            new ListenerInfo(bundle, bundle._getBundleContext(),
                 ServiceListener.class, l, newFilter, null, false));
         for (ServiceReference<org.osgi.framework.hooks.service.ListenerHook> sr : listenerHooks)
         {

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java?rev=1152217&r1=1152216&r2=1152217&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/EventDispatcher.java
Fri Jul 29 13:36:40 2011
@@ -224,7 +224,8 @@ public class EventDispatcher
             }
 
             // Add listener.
-            ListenerInfo info = new ListenerInfo(bc, clazz, l, filter, acc, false);
+            ListenerInfo info =
+                new ListenerInfo(bc.getBundle(), bc, clazz, l, filter, acc, false);
             listeners = addListenerInfo(listeners, info);
 
             if (clazz == FrameworkListener.class)
@@ -394,6 +395,7 @@ public class EventDispatcher
                         // The spec says to update the filter in this case.
                         Filter oldFilter = info.getParsedFilter();
                         ListenerInfo newInfo = new ListenerInfo(
+                            info.getBundle(),
                             info.getBundleContext(),
                             info.getListenerClass(),
                             info.getListener(),
@@ -746,7 +748,7 @@ public class EventDispatcher
             {
                 for (ListenerInfo info : entry.getValue())
                 {
-                    BundleContext bc = info.getBundleContext();
+                    Bundle bundle = info.getBundle();
                     EventListener l = info.getListener();
                     Filter filter = info.getParsedFilter();
                     Object acc = info.getSecurityContext();
@@ -755,16 +757,16 @@ public class EventDispatcher
                     {
                         if (type == Request.FRAMEWORK_EVENT)
                         {
-                            invokeFrameworkListenerCallback(bc.getBundle(), l, event);
+                            invokeFrameworkListenerCallback(bundle, l, event);
                         }
                         else if (type == Request.BUNDLE_EVENT)
                         {
-                            invokeBundleListenerCallback(bc.getBundle(), l, event);
+                            invokeBundleListenerCallback(bundle, l, event);
                         }
                         else if (type == Request.SERVICE_EVENT)
                         {
                             invokeServiceListenerCallback(
-                                bc.getBundle(), l, filter, acc, event, oldProps);
+                                bundle, l, filter, acc, event, oldProps);
                         }
                     }
                     catch (Throwable th)
@@ -772,11 +774,11 @@ public class EventDispatcher
                         if ((type != Request.FRAMEWORK_EVENT)
                             || (((FrameworkEvent) event).getType() != FrameworkEvent.ERROR))
                         {
-                            dispatcher.m_logger.log(bc.getBundle(),
+                            dispatcher.m_logger.log(bundle,
                                 Logger.LOG_ERROR,
                                 "EventDispatcher: Error during dispatch.", th);
                             dispatcher.fireFrameworkEvent(
-                                new FrameworkEvent(FrameworkEvent.ERROR, bc.getBundle(),
th));
+                                new FrameworkEvent(FrameworkEvent.ERROR, bundle, th));
                         }
                     }
                 }

Modified: felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ListenerInfo.java
URL: http://svn.apache.org/viewvc/felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ListenerInfo.java?rev=1152217&r1=1152216&r2=1152217&view=diff
==============================================================================
--- felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ListenerInfo.java
(original)
+++ felix/trunk/framework/src/main/java/org/apache/felix/framework/util/ListenerInfo.java
Fri Jul 29 13:36:40 2011
@@ -27,6 +27,7 @@ import org.osgi.framework.hooks.service.
 
 public class ListenerInfo implements ListenerHook.ListenerInfo
 {
+    private final Bundle m_bundle;
     private final BundleContext m_context;
     private final Class m_listenerClass;
     private final EventListener m_listener;
@@ -35,9 +36,13 @@ public class ListenerInfo implements Lis
     private final boolean m_removed;
 
     public ListenerInfo(
-        BundleContext context, Class listenerClass, EventListener listener,
+        Bundle bundle, BundleContext context, Class listenerClass, EventListener listener,
         Filter filter, Object acc, boolean removed)
     {
+        // Technically, we could get the bundle from the bundle context, but
+        // there are some corner cases where the bundle context might become
+        // invalid and we still need the bundle.
+        m_bundle = bundle;
         m_context = context;
         m_listenerClass = listenerClass;
         m_listener = listener;
@@ -48,6 +53,7 @@ public class ListenerInfo implements Lis
 
     public ListenerInfo(ListenerInfo info, boolean removed)
     {
+        m_bundle = info.m_bundle;
         m_context = info.m_context;
         m_listenerClass = info.m_listenerClass;
         m_listener = info.m_listener;
@@ -56,6 +62,11 @@ public class ListenerInfo implements Lis
         m_removed = removed;
     }
 
+    public Bundle getBundle()
+    {
+        return m_bundle;
+    }
+
     public BundleContext getBundleContext()
     {
         return m_context;
@@ -109,21 +120,22 @@ public class ListenerInfo implements Lis
         }
 
         ListenerInfo other = (ListenerInfo) obj;
-        return (other.m_context == m_context)
+        return (other.m_bundle == m_bundle)
+            && (other.m_context == m_context)
             && (other.m_listenerClass == m_listenerClass)
             && (other.m_listener == m_listener)
             && (m_filter == null ? other.m_filter == null : m_filter.equals(other.m_filter));
     }
 
-
     @Override
     public int hashCode()
     {
         int hash = 7;
-        hash = 71 * hash + (this.m_context != null ? this.m_context.hashCode() : 0);
-        hash = 71 * hash + (this.m_listenerClass != null ? this.m_listenerClass.hashCode()
: 0);
-        hash = 71 * hash + (this.m_listener != null ? this.m_listener.hashCode() : 0);
-        hash = 71 * hash + (this.m_filter != null ? this.m_filter.hashCode() : 0);
+        hash = 59 * hash + (this.m_bundle != null ? this.m_bundle.hashCode() : 0);
+        hash = 59 * hash + (this.m_context != null ? this.m_context.hashCode() : 0);
+        hash = 59 * hash + (this.m_listenerClass != null ? this.m_listenerClass.hashCode()
: 0);
+        hash = 59 * hash + (this.m_listener != null ? this.m_listener.hashCode() : 0);
+        hash = 59 * hash + (this.m_filter != null ? this.m_filter.hashCode() : 0);
         return hash;
     }
 }
\ No newline at end of file



Mime
View raw message