[jboss-cvs] JBossAS SVN: r92874 - in projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade: plugins and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Aug 27 11:44:03 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-08-27 11:44:03 -0400 (Thu, 27 Aug 2009)
New Revision: 92874

Modified:
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
   projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
Log:
WIP

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java	2009-08-27 15:40:41 UTC (rev 92873)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/AbstractBundleState.java	2009-08-27 15:44:03 UTC (rev 92874)
@@ -683,9 +683,8 @@
    {
       if (bundleManager != null && this.bundleManager != null)
          throw new IllegalStateException("Bundle " + this + " is already installed");
+      
       this.bundleManager = bundleManager;
-      if (bundleManager == null)
-         changeState(Bundle.UNINSTALLED);
    }
 
    /**
@@ -752,8 +751,11 @@
       this.state.set(state);
       log.debug(this + " change state=" + ConstantsHelper.bundleState(state));
       
-      FrameworkEventsPlugin plugin = getBundleManager().getPlugin(FrameworkEventsPlugin.class);
-      plugin.fireBundleEvent(this, type);
+      if (bundleManager.isActive())
+      {
+         FrameworkEventsPlugin plugin = bundleManager.getPlugin(FrameworkEventsPlugin.class);
+         plugin.fireBundleEvent(this, type);
+      }
    }
 
    /**

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-27 15:40:41 UTC (rev 92873)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/bundle/OSGiBundleManager.java	2009-08-27 15:44:03 UTC (rev 92874)
@@ -899,18 +899,18 @@
          return;
 
       systemBundle.changeState(Bundle.STOPPING);
-      for (AbstractBundleState bundle : getBundles())
+      for (AbstractBundleState bundleState : getBundles())
       {
-         if (bundle != systemBundle)
+         if (bundleState != systemBundle)
          {
             try
             {
                // [TODO] don't change the  persistent state
-               bundle.stop();
+               bundleState.stop();
             }
             catch (Throwable t)
             {
-               fireWarning(bundle, "stopping bundle", t);
+               fireWarning(bundleState, "stopping bundle", t);
             }
          }
       }
@@ -926,26 +926,26 @@
       if (systemBundle.getState() != Bundle.ACTIVE)
          return;
 
-      for (AbstractBundleState bundle : getBundles())
+      for (AbstractBundleState bundleState : getBundles())
       {
-         if (bundle != systemBundle && bundle.getState() == Bundle.ACTIVE)
+         if (bundleState != systemBundle && bundleState.getState() == Bundle.ACTIVE)
          {
             try
             {
                // [TODO] don't change the  persistent state
-               bundle.stop();
+               bundleState.stop();
             }
             catch (Throwable t)
             {
-               fireWarning(bundle, "stopping bundle", t);
+               fireWarning(bundleState, "stopping bundle", t);
             }
             try
             {
-               bundle.start();
+               bundleState.start();
             }
             catch (Throwable t)
             {
-               fireError(bundle, "starting bundle", t);
+               fireError(bundleState, "starting bundle", t);
             }
          }
       }
@@ -956,14 +956,13 @@
     * 
     * @param t the throwable
     */
-   void fireError(AbstractBundleState bundleState, String context, Throwable t)
+   void fireError(Bundle bundle, String context, Throwable t)
    {
-      OSGiSystemState systemBundle = getSystemBundle();
       FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
       if (t instanceof BundleException)
-         plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.ERROR, t);
-      else if (bundleState != null)
-         plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+         plugin.fireFrameworkEvent(bundle, FrameworkEvent.ERROR, t);
+      else if (bundle != null)
+         plugin.fireFrameworkEvent(bundle, FrameworkEvent.ERROR, new BundleException("Error " + context + " bundle: " + bundle, t));
       else
          plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.ERROR, new BundleException("Error " + context, t));
    }
@@ -973,14 +972,13 @@
     * 
     * @param t the throwable
     */
-   void fireWarning(AbstractBundleState bundleState, String context, Throwable t)
+   void fireWarning(Bundle bundle, String context, Throwable t)
    {
-      OSGiSystemState systemBundle = getSystemBundle();
       FrameworkEventsPlugin plugin = getPlugin(FrameworkEventsPlugin.class);
       if (t instanceof BundleException)
-         plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.WARNING, t);
-      else if (bundleState != null)
-         plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundleState.getCanonicalName(), t));
+         plugin.fireFrameworkEvent(bundle, FrameworkEvent.WARNING, t);
+      else if (bundle != null)
+         plugin.fireFrameworkEvent(bundle, FrameworkEvent.WARNING, new BundleException("Error " + context + " bundle: " + bundle, t));
       else
          plugin.fireFrameworkEvent(systemBundle, FrameworkEvent.WARNING, new BundleException("Error " + context, t));
    }

Modified: projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java
===================================================================
--- projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java	2009-08-27 15:40:41 UTC (rev 92873)
+++ projects/jboss-osgi/projects/runtime/microcontainer/branches/tdiesler/src/main/java/org/jboss/osgi/plugins/facade/plugins/FrameworkEventsPluginImpl.java	2009-08-27 15:44:03 UTC (rev 92874)
@@ -31,6 +31,7 @@
 
 import org.jboss.logging.Logger;
 import org.jboss.osgi.plugins.facade.api.FrameworkEventsPlugin;
+import org.jboss.osgi.plugins.facade.bundle.AbstractBundleState;
 import org.jboss.osgi.plugins.facade.bundle.OSGiBundleManager;
 import org.jboss.osgi.plugins.facade.bundle.OSGiServiceState;
 import org.osgi.framework.Bundle;
@@ -71,25 +72,40 @@
    @Override
    public void addBundleListener(BundleListener listener)
    {
-      // TODO Auto-generated method stub
-      
+      bundleListeners.add(listener);
    }
 
    @Override
+   public void removeBundleListener(BundleListener listener)
+   {
+      bundleListeners.remove(listener);
+   }
+
+   @Override
    public void addFrameworkListener(FrameworkListener listener)
    {
-      // TODO Auto-generated method stub
-      
+      frameworkListeners.add(listener);
    }
 
    @Override
+   public void removeFrameworkListener(FrameworkListener listener)
+   {
+      frameworkListeners.remove(listener);
+   }
+
+   @Override
    public void addServiceListener(ServiceListener listener, Filter filter)
    {
-      // TODO Auto-generated method stub
-      
+      serviceListeners.put(listener, new ServiceListenerRegistration(filter));
    }
 
    @Override
+   public void removeServiceListener(ServiceListener listener)
+   {
+      serviceListeners.remove(listener);
+   }
+   
+   @Override
    public void fireBundleEvent(Bundle bundle, int type)
    {
       // Nobody is interested
@@ -100,6 +116,10 @@
       if (getBundleManager().isActive() == false)
          return;
 
+      // Expose the wrapper not the state itself
+      if (bundle instanceof AbstractBundleState)
+         bundle = ((AbstractBundleState)bundle).getBundleInternal();
+      
       BundleEvent event = new BundleEvent(type, bundle);
       
       // Synchronous listeners first
@@ -144,6 +164,10 @@
       // Are we active?
       if (getBundleManager().isActive() == false)
          return;
+      
+      // Expose the wrapper not the state itself
+      if (bundle instanceof AbstractBundleState)
+         bundle = ((AbstractBundleState)bundle).getBundleInternal();
 
       // Call the listeners
       FrameworkEvent event = new FrameworkEvent(type, bundle, throwable);
@@ -174,6 +198,10 @@
       if (getBundleManager().isActive() == false)
          return;
 
+      // Expose the wrapper not the state itself
+      if (bundle instanceof AbstractBundleState)
+         bundle = ((AbstractBundleState)bundle).getBundleInternal();
+      
       ServiceEvent event = new ServiceEvent(type, service.getReferenceInternal());
 
       // Call the listeners
@@ -196,25 +224,4 @@
          }
       }
    }
-
-   @Override
-   public void removeBundleListener(BundleListener listener)
-   {
-      // TODO Auto-generated method stub
-      
-   }
-
-   @Override
-   public void removeFrameworkListener(FrameworkListener listener)
-   {
-      // TODO Auto-generated method stub
-      
-   }
-
-   @Override
-   public void removeServiceListener(ServiceListener listener)
-   {
-      // TODO Auto-generated method stub
-      
-   }
 }
\ No newline at end of file




More information about the jboss-cvs-commits mailing list