felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rickh...@apache.org
Subject svn commit: r956029 - in /felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework: BundleImpl.java Felix.java VirtualModuleContextImpl.java ext/VirtualModuleContext.java
Date Fri, 18 Jun 2010 15:52:51 GMT
Author: rickhall
Date: Fri Jun 18 15:52:51 2010
New Revision: 956029

URL: http://svn.apache.org/viewvc?rev=956029&view=rev
Log:
Implement virtual module context.

Modified:
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/BundleImpl.java
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/VirtualModuleContextImpl.java
    felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualModuleContext.java

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/BundleImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/BundleImpl.java?rev=956029&r1=956028&r2=956029&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/BundleImpl.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/BundleImpl.java
Fri Jun 18 15:52:51 2010
@@ -28,6 +28,7 @@ import org.apache.felix.framework.cache.
 import org.apache.felix.framework.resolver.Module;
 import org.apache.felix.framework.ext.SecurityProvider;
 import org.apache.felix.framework.ext.VirtualModule;
+import org.apache.felix.framework.ext.VirtualModuleContext;
 import org.apache.felix.framework.util.StringMap;
 import org.osgi.framework.*;
 
@@ -38,10 +39,11 @@ class BundleImpl implements Bundle
 
     private final BundleArchive m_archive;
     private final List<Module> m_modules = new ArrayList<Module>(0);
-    private volatile int m_state;
-    private boolean m_useDeclaredActivationPolicy;
+    private volatile int m_state = Bundle.INSTALLED;
+    private boolean m_useDeclaredActivationPolicy = false;
     private BundleActivator m_activator = null;
     private volatile BundleContext m_context = null;
+    private volatile VirtualModuleContext m_vmc = null;
     private final Map m_cachedHeaders = new HashMap();
     private long m_cachedHeadersTimestamp;
 
@@ -60,22 +62,12 @@ class BundleImpl implements Bundle
     {
         __m_felix = null;
         m_archive = null;
-        m_state = Bundle.INSTALLED;
-        m_useDeclaredActivationPolicy = false;
-        m_stale = false;
-        m_activator = null;
-        m_context = null;
     }
 
     BundleImpl(Felix felix, BundleArchive archive, VirtualModule vm) throws Exception
     {
         __m_felix = felix;
         m_archive = archive;
-        m_state = Bundle.INSTALLED;
-        m_useDeclaredActivationPolicy = false;
-        m_stale = false;
-        m_activator = null;
-        m_context = null;
 
         Module module = createModule(vm);
         addModule(module);
@@ -217,6 +209,16 @@ class BundleImpl implements Bundle
         m_context = context;
     }
 
+    VirtualModuleContext getVirtualModuleContext()
+    {
+        return m_vmc;
+    }
+
+    void setVirtualModuleContext(VirtualModuleContext vmc)
+    {
+        m_vmc = vmc;
+    }
+
     public long getBundleId()
     {
         try

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java?rev=956029&r1=956028&r2=956029&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/Felix.java
Fri Jun 18 15:52:51 2010
@@ -2371,6 +2371,12 @@ ex.printStackTrace();
             setBundleStateAndNotify(bundle, Bundle.UNINSTALLED);
             bundle.setLastModified(System.currentTimeMillis());
 
+            // If this is a virtual bundle, then invalidate its context.
+            if (bundle.getVirtualModuleContext() != null)
+            {
+                ((VirtualModuleContextImpl) bundle.getVirtualModuleContext()).invalidate();
+            }
+
             // If this bundle is a fragment, unmerge it from any
             // unresolved hosts.
             bundle.cleanAfterUninstall();
@@ -2642,6 +2648,7 @@ ex.printStackTrace();
         BundleImpl manager, String location, Map headers, VirtualModule vm)
         throws BundleException
     {
+        VirtualModuleContext vmc = null;
         BundleImpl bundle = null;
 
         if ((location == null) || (headers == null) || (vm == null))
@@ -2699,6 +2706,8 @@ ex.printStackTrace();
                 try
                 {
                     bundle = new BundleImpl(this, ba, vm);
+                    vmc = new VirtualModuleContextImpl(this, bundle);
+                    bundle.setVirtualModuleContext(vmc);
 // TODO: VB - Fix this hack. Perhaps with RFC-154.
                     ((ManagedModuleImpl) manager.getCurrentModule())
                         .addDependentVirtual(bundle.getCurrentModule());
@@ -2785,12 +2794,14 @@ ex.printStackTrace();
         fireBundleEvent(BundleEvent.INSTALLED, bundle);
 
         // Return virtual module context.
-        return new VirtualModuleContextImpl(bundle);
+        return vmc;
     }
 
     VirtualModuleContext reinstallBundle(BundleImpl manager, BundleImpl vb, VirtualModule
vm)
         throws BundleException
     {
+        VirtualModuleContext vmc = null;
+
         // Acquire bundle lock.
         try
         {
@@ -2810,6 +2821,11 @@ ex.printStackTrace();
             if (vb.getCurrentModule() instanceof UnmanagedModuleImpl)
             {
                 ((UnmanagedModuleImpl) vb.getCurrentModule()).setVirtualModule(vm);
+                vmc = new VirtualModuleContextImpl(this, vb);
+                vb.setVirtualModuleContext(vmc);
+// TODO: VB - Fix this hack. Perhaps with RFC-154.
+                    ((ManagedModuleImpl) manager.getCurrentModule())
+                        .addDependentVirtual(vb.getCurrentModule());
             }
             else
             {
@@ -2828,7 +2844,7 @@ ex.printStackTrace();
         fireBundleEvent(BundleEvent.INSTALLED, vb);
 
         // Return virtual module context.
-        return new VirtualModuleContextImpl(vb);
+        return vmc;
     }
 
     /**

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/VirtualModuleContextImpl.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/VirtualModuleContextImpl.java?rev=956029&r1=956028&r2=956029&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/VirtualModuleContextImpl.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/VirtualModuleContextImpl.java
Fri Jun 18 15:52:51 2010
@@ -24,10 +24,13 @@ import org.osgi.framework.Bundle;
 
 public class VirtualModuleContextImpl implements VirtualModuleContext
 {
-    private final Bundle m_bundle;
+    private final Felix m_felix;
+    private final BundleImpl m_bundle;
+    private volatile boolean m_valid = true;
 
-    VirtualModuleContextImpl(Bundle bundle)
+    VirtualModuleContextImpl(Felix felix, BundleImpl bundle)
     {
+        m_felix = felix;
         m_bundle = bundle;
     }
 
@@ -36,8 +39,33 @@ public class VirtualModuleContextImpl im
         return m_bundle;
     }
 
-    public File getDataFile()
+    public File getDataFile(String s)
     {
-        throw new UnsupportedOperationException("Not supported yet.");
+        checkValidity();
+
+        return m_felix.getDataFile(m_bundle, s);
+    }
+
+    void invalidate()
+    {
+        m_valid = false;
+    }
+
+    private void checkValidity()
+    {
+        if (m_valid)
+        {
+            switch (m_bundle.getState())
+            {
+                case Bundle.ACTIVE:
+                case Bundle.STARTING:
+                case Bundle.STOPPING:
+                case Bundle.RESOLVED:
+                case Bundle.INSTALLED:
+                    return;
+            }
+        }
+
+        throw new IllegalStateException("Invalid BundleContext.");
     }
 }
\ No newline at end of file

Modified: felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualModuleContext.java
URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualModuleContext.java?rev=956029&r1=956028&r2=956029&view=diff
==============================================================================
--- felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualModuleContext.java
(original)
+++ felix/sandbox/rickhall/vb/framework-vb/src/main/java/org/apache/felix/framework/ext/VirtualModuleContext.java
Fri Jun 18 15:52:51 2010
@@ -24,5 +24,5 @@ import org.osgi.framework.Bundle;
 public interface VirtualModuleContext
 {
     Bundle getBundle();
-    File getDataFile();
+    File getDataFile(String s);
 }
\ No newline at end of file



Mime
View raw message