geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r767238 - in /geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint: Activator.java context/DefaultModuleContextEventSender.java
Date Tue, 21 Apr 2009 17:43:06 GMT
Author: gnodet
Date: Tue Apr 21 17:43:06 2009
New Revision: 767238

URL: http://svn.apache.org/viewvc?rev=767238&view=rev
Log:
Support for ModuleContextListener, remove a TODO

Modified:
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/Activator.java
    geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultModuleContextEventSender.java

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/Activator.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/Activator.java?rev=767238&r1=767237&r2=767238&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/Activator.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/Activator.java
Tue Apr 21 17:43:06 2009
@@ -36,7 +36,6 @@
 import org.osgi.framework.BundleActivator;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.BundleEvent;
-import org.osgi.framework.BundleListener;
 import org.osgi.framework.SynchronousBundleListener;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -81,7 +80,6 @@
         for (Bundle bundle : bundles) {
             destroyContext(bundle);
         }
-        // TODO: destroy all contexts
         context.removeBundleListener(this);
         this.sender.destroy();
         this.handlers.destroy();

Modified: geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultModuleContextEventSender.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultModuleContextEventSender.java?rev=767238&r1=767237&r2=767238&view=diff
==============================================================================
--- geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultModuleContextEventSender.java
(original)
+++ geronimo/sandbox/blueprint/blueprint-core/src/main/java/org/apache/geronimo/blueprint/context/DefaultModuleContextEventSender.java
Tue Apr 21 17:43:06 2009
@@ -31,6 +31,7 @@
 import org.osgi.service.event.EventConstants;
 import org.osgi.service.blueprint.context.ModuleContextEventConstants;
 import org.osgi.service.blueprint.context.ModuleContext;
+import org.osgi.service.blueprint.context.ModuleContextListener;
 import org.apache.geronimo.blueprint.BlueprintConstants;
 import org.apache.geronimo.blueprint.ModuleContextEventSender;
 
@@ -44,11 +45,14 @@
 
     private final Bundle extenderBundle;
     private final ServiceTracker eventAdminServiceTracker;
+    private final ServiceTracker contextListenerTracker;
 
     public DefaultModuleContextEventSender(BundleContext bundleContext) {
         this.extenderBundle = bundleContext.getBundle();
         this.eventAdminServiceTracker = new ServiceTracker(bundleContext, EventAdmin.class.getName(),
null);
         this.eventAdminServiceTracker.open();
+        this.contextListenerTracker = new ServiceTracker(bundleContext, ModuleContextListener.class.getName(),
null);
+        this.contextListenerTracker.open();
     }
 
     public void sendCreating(ModuleContext moduleContext) {
@@ -80,6 +84,22 @@
     }
 
     public void sendEvent(ModuleContext moduleContext, String topic, Throwable cause, String[]
serviceObjectClass, String serviceFilter) {
+
+        if (topic == TOPIC_CREATED || topic == TOPIC_FAILURE) {
+            Object[] listeners = contextListenerTracker.getServices();
+            for (Object listener : listeners) {
+                try {
+                    if (topic == TOPIC_CREATED) {
+                        ((ModuleContextListener) listener).contextCreated(moduleContext.getBundleContext().getBundle());
+                    } else if (topic == TOPIC_FAILURE) {
+                        ((ModuleContextListener) listener).contextCreationFailed(moduleContext.getBundleContext().getBundle(),
cause);
+                    }
+                } catch (Throwable t) {
+                    t.printStackTrace(); // TODO: log
+                }
+            }
+        }
+
         EventAdmin eventAdmin = getEventAdmin();
         if (eventAdmin == null) {
             return;
@@ -127,5 +147,6 @@
 
     public void destroy() {
         this.eventAdminServiceTracker.close();
+        this.contextListenerTracker.close();
     }
 }



Mime
View raw message