Author: thomas.diesler(a)jboss.com
Date: 2009-10-06 12:13:42 -0400 (Tue, 06 Oct 2009)
New Revision: 94421
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
Log:
Add option for synchronous event delivery
Modified:
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java
===================================================================
---
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-10-06
15:39:12 UTC (rev 94420)
+++
projects/jboss-osgi/projects/runtime/microcontainer/trunk/src/main/java/org/jboss/osgi/framework/plugins/internal/FrameworkEventsPluginImpl.java 2009-10-06
16:13:42 UTC (rev 94421)
@@ -65,6 +65,9 @@
/** The executor service */
private ExecutorService executorService;
+
+ /** True for synchronous event delivery */
+ private boolean synchronous;
/** The bundle listeners */
private final Map<Bundle, List<BundleListener>> bundleListeners = new
ConcurrentHashMap<Bundle, List<BundleListener>>();
@@ -82,6 +85,11 @@
this.executorService = Executors.newCachedThreadPool();
}
+ public void setSynchronous(boolean synchronous)
+ {
+ this.synchronous = synchronous;
+ }
+
public void addBundleListener(Bundle bundle, BundleListener listener)
{
if (listener == null)
@@ -298,7 +306,7 @@
};
// Fire the event in a runnable
- executorService.execute(runnable);
+ fireEvent(runnable, synchronous);
}
public void fireFrameworkEvent(final Bundle bundle, final int type, final Throwable
throwable)
@@ -358,7 +366,7 @@
};
// Fire the event in a runnable
- executorService.execute(runnable);
+ fireEvent(runnable, synchronous);
}
public void fireServiceEvent(Bundle bundle, int type, final OSGiServiceState service)
@@ -415,7 +423,7 @@
};
// Fire the event in a runnable
- executorService.execute(runnable);
+ fireEvent(runnable, synchronous);
}
private Bundle assertBundle(Bundle bundle)
@@ -430,6 +438,18 @@
return bundle;
}
+ private void fireEvent(Runnable runnable, boolean synchronous)
+ {
+ if (synchronous)
+ {
+ runnable.run();
+ }
+ else
+ {
+ executorService.execute(runnable);
+ }
+ }
+
/**
* Filter and AccessControl for service events
*/
Show replies by date