felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r418718 - in /incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework: BundleContextImpl.java Felix.java
Date Mon, 03 Jul 2006 09:13:19 GMT
Author: rickhall
Date: Mon Jul  3 02:13:18 2006
New Revision: 418718

URL: http://svn.apache.org/viewvc?rev=418718&view=rev
Log:
The bundle context was implemented such that it was invalid when a bundle
was in a stopped state, but that it could become valid again if the bundle
was re-started. It appears that the spec should be interpreted such that
a bundle context can never become valid again, like the bundle activator.
This patch implements this behavior.

Modified:
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
    incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java?rev=418718&r1=418717&r2=418718&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/BundleContextImpl.java
Mon Jul  3 02:13:18 2006
@@ -27,6 +27,7 @@
 {
     private Felix m_felix = null;
     private BundleImpl m_bundle = null;
+    private boolean m_valid = true;
 
     protected BundleContextImpl(Felix felix, BundleImpl bundle)
     {
@@ -34,6 +35,11 @@
         m_bundle = bundle;
     }
 
+    protected void invalidate()
+    {
+        m_valid = false;
+    }
+
     public void addImportPackage() throws BundleException
     {
         throw new BundleException("Not implemented yet.");
@@ -56,14 +62,14 @@
 
     public String getProperty(String name)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.getProperty(name);
     }
 
     public Bundle getBundle()
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_bundle;
     }
@@ -71,7 +77,7 @@
     public Filter createFilter(String expr)
         throws InvalidSyntaxException
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return new FilterImpl(m_felix.getLogger(), expr);
     }
@@ -85,35 +91,35 @@
     public Bundle installBundle(String location, InputStream is)
         throws BundleException
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.installBundle(location, is);
     }
 
     public Bundle getBundle(long id)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.getBundle(id);
     }
 
     public Bundle[] getBundles()
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.getBundles();
     }
 
     public void addBundleListener(BundleListener l)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.addBundleListener(m_bundle, l);
     }
 
     public void removeBundleListener(BundleListener l)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.removeBundleListener(l);
     }
@@ -133,28 +139,28 @@
     public void addServiceListener(ServiceListener l, String s)
         throws InvalidSyntaxException
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.addServiceListener(m_bundle, l, s);
     }
 
     public void removeServiceListener(ServiceListener l)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.removeServiceListener(l);
     }
 
     public void addFrameworkListener(FrameworkListener l)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.addFrameworkListener(m_bundle, l);
     }
 
     public void removeFrameworkListener(FrameworkListener l)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         m_felix.removeFrameworkListener(l);
     }
@@ -168,14 +174,14 @@
     public ServiceRegistration registerService(
         String[] clazzes, Object svcObj, Dictionary dict)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.registerService(m_bundle, clazzes, svcObj, dict);
     }
 
     public ServiceReference getServiceReference(String clazz)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         try
         {
@@ -275,7 +281,7 @@
 
     public ServiceReference[] getAllServiceReferences(String clazz, String filter) throws
InvalidSyntaxException
     {
-        checkBundleContextValid();
+        checkValidity();
         
         // TODO: Implement BundleContext.getAllServiceReferences()
         return null;
@@ -284,14 +290,14 @@
     public ServiceReference[] getServiceReferences(String clazz, String filter)
         throws InvalidSyntaxException
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.getServiceReferences(m_bundle, clazz, filter);
     }
 
     public Object getService(ServiceReference ref)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         if (ref == null)
         {
@@ -302,7 +308,7 @@
 
     public boolean ungetService(ServiceReference ref)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         if (ref == null)
         {
@@ -315,19 +321,22 @@
 
     public File getDataFile(String s)
     {
-        checkBundleContextValid();
+        checkValidity();
         
         return m_felix.getDataFile(m_bundle, s);
     }
 
-    private void checkBundleContextValid()
+    private void checkValidity()
     {
-        switch(m_bundle.getState())
+        if (m_valid)
         {
-            case Bundle.ACTIVE:
-            case Bundle.STARTING:
-            case Bundle.STOPPING:
-                return;
+            switch (m_bundle.getState())
+            {
+                case Bundle.ACTIVE:
+                case Bundle.STARTING:
+                case Bundle.STOPPING:
+                    return;
+            }
         }
         
         throw new IllegalStateException("Invalid BundleContext.");

Modified: incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java?rev=418718&r1=418717&r2=418718&view=diff
==============================================================================
--- incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ incubator/felix/trunk/org.apache.felix.framework/src/main/java/org/apache/felix/framework/Felix.java
Mon Jul  3 02:13:18 2006
@@ -1362,6 +1362,13 @@
             // then reset its state to RESOLVED.
             info.setState(Bundle.RESOLVED);
 
+            // Clean up the bundle context, if necessary.
+            if (info.getContext() != null)
+            {
+                ((BundleContextImpl) info.getContext()).invalidate();
+                info.setContext(null);
+            }
+
             // Unregister any services offered by this bundle.
             m_registry.unregisterServices(bundle);
 
@@ -1655,6 +1662,13 @@
             rethrow = th;
         }
                   
+        // Clean up the bundle context, if necessary.
+        if (info.getContext() != null)
+        {
+            ((BundleContextImpl) info.getContext()).invalidate();
+            info.setContext(null);
+        }
+
         // Unregister any services offered by this bundle.
         m_registry.unregisterServices(bundle);
         



Mime
View raw message