use of org.osgi.service.cdi.CdiContainer 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.service.cdi.CdiContainer in project aries by apache.
the class CdiExtenderTests method testStopExtender.
public void testStopExtender() throws Exception {
Bundle cdiExtenderBundle = getCdiExtenderBundle();
ServiceTracker<CdiContainer, CdiContainer> serviceTracker = getServiceTracker(cdiBundle.getBundleId());
try {
assertNotNull(serviceTracker.waitForService(timeout));
cdiExtenderBundle.stop();
assertTrue(serviceTracker.isEmpty());
cdiExtenderBundle.start();
assertNotNull(serviceTracker.waitForService(timeout));
} finally {
serviceTracker.close();
}
}
use of org.osgi.service.cdi.CdiContainer in project aries by apache.
the class CdiContainerState method updateState.
private synchronized void updateState(CdiEvent event) {
Type type = event.getType();
ServiceReference<CdiContainer> reference = _cdiContainerRegistration.getReference();
if (type == reference.getProperty(CdiConstants.CDI_CONTAINER_STATE)) {
return;
}
_lastState = type;
Hashtable<String, Object> properties = new Hashtable<>();
for (String key : reference.getPropertyKeys()) {
properties.put(key, reference.getProperty(key));
}
properties.put(CdiConstants.CDI_CONTAINER_STATE, type);
_cdiContainerRegistration.setProperties(properties);
}
Aggregations