use of org.osgi.util.tracker.BundleTracker in project aries by apache.
the class Activator method start.
/*
* (non-Javadoc)
*
* @see
* org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext
* )
*/
public void start(BundleContext context) throws Exception {
System.out.println("bundle helloIsolation start");
SecurityManager security = System.getSecurityManager();
if (security != null) {
System.out.println("HelloIsolationImpl: system manager is not null");
} else {
System.out.println("HelloIsolationImpl: system manager is still null");
}
sr = context.registerService(HelloIsolation.class.getName(), new HelloIsolationImpl(), null);
bt = new BundleTracker(context, Bundle.INSTALLED | Bundle.UNINSTALLED | Bundle.ACTIVE, new BundleTrackerCustomizer() {
public synchronized Object addingBundle(Bundle bundle, BundleEvent event) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - adding Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
addEventCount++;
return bundle;
}
public synchronized void modifiedBundle(Bundle bundle, BundleEvent event, Object object) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - modifying Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - modifying Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
modifyEventCount++;
}
public synchronized void removedBundle(Bundle bundle, BundleEvent event, Object object) {
if (event == null) {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: null");
} else {
System.out.println("HelloIsolation " + bundle.getSymbolicName() + "_" + bundle.getVersion().toString() + " - removing Bundle: " + bundle.getSymbolicName() + " event: " + event.getType());
}
removeEventCount++;
}
});
bt.open();
}
use of org.osgi.util.tracker.BundleTracker in project tomee by apache.
the class ServiceManagerExtender method init.
@Override
public void init() throws Exception {
if (started != null && started.equals(Boolean.TRUE)) {
throw new IllegalStateException("ServiceManager is already initialized");
}
final DiscoveryRegistry registry = new DiscoveryRegistry();
SystemInstance.get().setComponent(DiscoveryRegistry.class, registry);
started = Boolean.FALSE;
stopped = false;
final ServerServiceTracker t = new ServerServiceTracker();
tracker = new BundleTracker(bundleContext, Bundle.ACTIVE | Bundle.STOPPING, t);
tracker.open();
}
use of org.osgi.util.tracker.BundleTracker 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");
}
use of org.osgi.util.tracker.BundleTracker in project aries by apache.
the class JndiExtensionTests method testDisableExtensionAndCDIContainerWaits.
public void testDisableExtensionAndCDIContainerWaits() throws Exception {
BundleTracker<Bundle> bt = new BundleTracker<>(bundle.getBundleContext(), Bundle.RESOLVED | Bundle.ACTIVE, new BundleTrackerCustomizer<Bundle>() {
@Override
public Bundle addingBundle(Bundle bundle, BundleEvent arg1) {
List<BundleCapability> capabilities = bundle.adapt(BundleWiring.class).getCapabilities(CdiConstants.CDI_EXTENSION_NAMESPACE);
if (capabilities.isEmpty()) {
return null;
}
for (Capability capability : capabilities) {
if (capability.getAttributes().containsValue("jndi")) {
return bundle;
}
}
return null;
}
@Override
public void modifiedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
@Override
public void removedBundle(Bundle bundle, BundleEvent arg1, Bundle arg2) {
}
});
bt.open();
assertFalse(bt.isEmpty());
Bundle extensionBundle = bt.getBundles()[0];
Collection<ServiceReference<CdiContainer>> serviceReferences = bundleContext.getServiceReferences(CdiContainer.class, "(&(objectClass=" + CdiContainer.class.getName() + ")(service.bundleid=" + cdiBundle.getBundleId() + "))");
assertNotNull(serviceReferences);
assertFalse(serviceReferences.isEmpty());
ServiceReference<CdiContainer> serviceReference = serviceReferences.iterator().next();
CdiEvent.Type state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
extensionBundle.stop();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.WAITING_FOR_EXTENSIONS, state);
extensionBundle.start();
state = (CdiEvent.Type) serviceReference.getProperty(CdiConstants.CDI_CONTAINER_STATE);
assertEquals(CdiEvent.Type.CREATED, state);
}
use of org.osgi.util.tracker.BundleTracker in project aries by apache.
the class InternalRecursiveBundleTracker method customizedProcessBundle.
protected void customizedProcessBundle(BundleTrackerCustomizer btc, Bundle b, BundleEvent event, boolean removing) {
if (b instanceof CompositeBundle) {
CompositeBundle cb = (CompositeBundle) b;
// check if the compositeBundle is already tracked in the
// BundleTrackerFactory
String bundleScope = cb.getSymbolicName() + "_" + cb.getVersion().toString();
List<BundleTracker> btList = BundleTrackerFactory.getBundleTrackerList(bundleScope);
// or when the tracker is being closed.
if (event == null && !!!removing) {
if (cb.getState() == Bundle.INSTALLED || cb.getState() == Bundle.RESOLVED || cb.getState() == Bundle.STARTING || cb.getState() == Bundle.ACTIVE) {
openTracker(btc, cb, bundleScope, mask);
}
} else {
// if we are removing, or the event is of the right type then we need to shutdown.
if (removing || event.getType() == BundleEvent.STOPPED || event.getType() == BundleEvent.UNRESOLVED || event.getType() == BundleEvent.UNINSTALLED) {
// if CompositeBundle is being stopped, let's remove the bundle
// tracker(s) associated with the composite bundle
String bundleId = b.getSymbolicName() + "/" + b.getVersion();
alreadyRecursedContexts.remove(bundleId);
if (btList != null) {
// unregister the bundlescope off the factory and close
// bundle trackers
BundleTrackerFactory.unregisterAndCloseBundleTracker(bundleScope);
}
} else if (event.getType() == BundleEvent.INSTALLED || event.getType() == BundleEvent.RESOLVED || event.getType() == BundleEvent.STARTING) {
openTracker(btc, cb, bundleScope, mask);
}
}
}
}
Aggregations