use of org.osgi.framework.BundleEvent 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.framework.BundleEvent in project aries by apache.
the class BundleEventDataTest method testToCompositeData.
@Test
public void testToCompositeData() throws Exception {
BundleEvent event = mock(BundleEvent.class);
Bundle bundle = mock(Bundle.class);
when(event.getBundle()).thenReturn(bundle);
when(bundle.getSymbolicName()).thenReturn("test");
when(bundle.getBundleId()).thenReturn(new Long(4));
when(bundle.getLocation()).thenReturn("location");
when(event.getType()).thenReturn(BundleEvent.INSTALLED);
BundleEventData eventData = new BundleEventData(event);
CompositeData eventCompositeData = eventData.toCompositeData();
assertEquals(new Long(4), (Long) eventCompositeData.get(IDENTIFIER));
assertEquals("test", (String) eventCompositeData.get(SYMBOLIC_NAME));
assertEquals(new Integer(BundleEvent.INSTALLED), (Integer) eventCompositeData.get(EVENT));
assertEquals("location", (String) eventCompositeData.get(LOCATION));
}
use of org.osgi.framework.BundleEvent in project aries by apache.
the class RecursiveBundleTrackerTest method testCompositeLifeCycle.
@Test
public void testCompositeLifeCycle() {
makeSUT();
CompositeBundle cb = composite("test.composite", "1.0.0");
assertNoTrackers();
// full lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTING, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STARTED, cb), cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.STOPPING, cb), cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.STOPPED, cb), cb);
assertNoTrackers();
// short lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.modifiedBundle(cb, new BundleEvent(BundleEvent.RESOLVED, cb), cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.UNRESOLVED, cb), cb);
assertNoTrackers();
// shortest lifecycle
sut.addingBundle(cb, new BundleEvent(BundleEvent.INSTALLED, cb));
assertTracker(cb);
sut.removedBundle(cb, new BundleEvent(BundleEvent.UNINSTALLED, cb), cb);
assertNoTrackers();
}
use of org.osgi.framework.BundleEvent in project aries by apache.
the class BlueprintContainerUseSystemContextTest method regiserHook.
@Before
public void regiserHook() {
final BundleContext systemContext = context().getBundle(Constants.SYSTEM_BUNDLE_LOCATION).getBundleContext();
eventHook = context().registerService(EventHook.class, new EventHook() {
@Override
public void event(BundleEvent event, Collection contexts) {
if ("org.apache.aries.blueprint.sample".equals(event.getBundle().getSymbolicName())) {
// hide sample from everything but the system bundle
// TODO on R6 we should be able to even try hiding from the system bundle
// R5 it was not clear if hooks could hide from the system bundle
// equinox R5 does allow hiding from system bundle
contexts.retainAll(Collections.singleton(systemContext));
}
}
}, null);
findHook = context().registerService(FindHook.class, new FindHook() {
@Override
public void find(BundleContext context, Collection bundles) {
if (context.equals(systemContext)) {
// equinox R5 does allow hiding from system bundle
return;
}
for (Iterator iBundles = bundles.iterator(); iBundles.hasNext(); ) {
if ("org.apache.aries.blueprint.sample".equals(((Bundle) iBundles.next()).getSymbolicName())) {
// hide sample from everything
iBundles.remove();
}
}
}
}, null);
}
use of org.osgi.framework.BundleEvent in project bnd by bndtools.
the class GC method start.
@Override
public void start(BundleContext context) throws Exception {
this.context = context;
context.addBundleListener(new BundleListener() {
@Override
public void bundleChanged(BundleEvent event) {
if (event.getType() == BundleEvent.UNINSTALLED) {
Bundle b = event.getBundle();
String embedded = b.getHeaders().get("Bnd-Embedded");
if (embedded != null) {
uninstalled(b);
}
}
}
});
}
Aggregations