use of org.apache.aries.util.tracker.RecursiveBundleTracker in project aries by apache.
the class BlueprintExtender method start.
public void start(BundleContext ctx) {
LOGGER.debug("Starting blueprint extender...");
this.context = ctx;
boolean useSystemContext = Boolean.parseBoolean(ctx.getProperty("org.apache.aries.blueprint.use.system.context"));
BundleContext trackingContext = useSystemContext ? ctx.getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext() : ctx;
handlers = new NamespaceHandlerRegistryImpl(trackingContext);
executors = new ScheduledExecutorServiceWrapper(ctx, "Blueprint Extender", new ScheduledExecutorServiceFactory() {
public ScheduledExecutorService create(String name) {
return Executors.newScheduledThreadPool(3, new BlueprintThreadFactory(name));
}
});
eventDispatcher = new BlueprintEventDispatcher(ctx, executors);
// Ideally we'd want to only track STARTING and ACTIVE bundle, but this is not supported
// when using equinox composites. This would ensure that no STOPPING event is lost while
// tracking the initial bundles. To work around this issue, we need to register
// a synchronous bundle listener that will ensure the stopping event will be correctly
// handled.
context.addBundleListener(this);
int mask = Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.STOPPING | Bundle.ACTIVE;
bt = useSystemContext ? new BundleTracker(trackingContext, mask, this) : new RecursiveBundleTracker(ctx, mask, this);
proxyManager = new SingleServiceTracker<ProxyManager>(ctx, ProxyManager.class, new SingleServiceListener() {
public void serviceFound() {
LOGGER.debug("Found ProxyManager service, starting to process blueprint bundles");
if (bt instanceof BundleTracker) {
((BundleTracker) bt).open();
} else if (bt instanceof RecursiveBundleTracker) {
((RecursiveBundleTracker) bt).open();
}
}
public void serviceLost() {
while (!containers.isEmpty()) {
for (Bundle bundle : getBundlesToDestroy()) {
destroyContainer(bundle);
}
}
if (bt instanceof BundleTracker) {
((BundleTracker) bt).close();
} else if (bt instanceof RecursiveBundleTracker) {
((RecursiveBundleTracker) bt).close();
}
}
public void serviceReplaced() {
}
});
proxyManager.open();
// Determine if the ParserService should ignore unknown namespace handlers
boolean ignoreUnknownNamespaceHandlers = Boolean.parseBoolean(ctx.getProperty("org.apache.aries.blueprint.parser.service.ignore.unknown.namespace.handlers"));
// Create and publish a ParserService
parserServiceReg = ctx.registerService(ParserService.class.getName(), new ParserServiceImpl(handlers, ignoreUnknownNamespaceHandlers), new Hashtable<String, Object>());
// Create and publish a BlueprintContainerService
blueprintServiceReg = ctx.registerService(BlueprintExtenderService.class.getName(), new BlueprintContainerServiceImpl(), new Hashtable<String, Object>());
try {
ctx.getBundle().loadClass(QUIESCE_PARTICIPANT_CLASS);
//Class was loaded, register
quiesceParticipantReg = ctx.registerService(QUIESCE_PARTICIPANT_CLASS, new BlueprintQuiesceParticipant(ctx, this), new Hashtable<String, Object>());
} catch (ClassNotFoundException e) {
LOGGER.info("No quiesce support is available, so blueprint components will not participate in quiesce operations");
}
LOGGER.debug("Blueprint extender started");
}
use of org.apache.aries.util.tracker.RecursiveBundleTracker in project aries by apache.
the class EJBExtender method start.
public void start(BundleContext context) throws Exception {
//Internal setup
OSGiTransactionManager.init(context);
AriesProxyService.init(context);
try {
AriesPersistenceContextIntegration.init(context);
} catch (NoClassDefFoundError ncdfe) {
//TODO log that no JPA Context integration is available
}
//Setup OpenEJB with our own extensions
setupOpenEJB();
tracker = new RecursiveBundleTracker(context, Bundle.INSTALLED | Bundle.RESOLVED | Bundle.STARTING | Bundle.ACTIVE | Bundle.STOPPING, this);
tracker.open();
}
use of org.apache.aries.util.tracker.RecursiveBundleTracker in project aries by apache.
the class BlueprintExtender method stop.
public void stop(BundleContext context) {
LOGGER.debug("Stopping blueprint extender...");
stopping = true;
ServiceUtil.safeUnregisterService(parserServiceReg);
ServiceUtil.safeUnregisterService(blueprintServiceReg);
ServiceUtil.safeUnregisterService(quiesceParticipantReg);
// Orderly shutdown of containers
while (!containers.isEmpty()) {
for (Bundle bundle : getBundlesToDestroy()) {
destroyContainer(bundle);
}
}
if (bt instanceof BundleTracker) {
((BundleTracker) bt).close();
} else if (bt instanceof RecursiveBundleTracker) {
((RecursiveBundleTracker) bt).close();
}
proxyManager.close();
this.eventDispatcher.destroy();
this.handlers.destroy();
executors.shutdown();
LOGGER.debug("Blueprint extender stopped");
}
Aggregations