Search in sources :

Example 6 with CdiContainer

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);
}
Also used : BundleCapability(org.osgi.framework.wiring.BundleCapability) Capability(org.osgi.resource.Capability) Bundle(org.osgi.framework.Bundle) BundleTracker(org.osgi.util.tracker.BundleTracker) ServiceReference(org.osgi.framework.ServiceReference) BundleEvent(org.osgi.framework.BundleEvent) List(java.util.List) CdiEvent(org.osgi.service.cdi.CdiEvent) CdiContainer(org.osgi.service.cdi.CdiContainer)

Example 7 with CdiContainer

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();
    }
}
Also used : Bundle(org.osgi.framework.Bundle) CdiContainer(org.osgi.service.cdi.CdiContainer)

Example 8 with CdiContainer

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);
}
Also used : Type(org.osgi.service.cdi.CdiEvent.Type) Hashtable(java.util.Hashtable) CdiContainer(org.osgi.service.cdi.CdiContainer)

Aggregations

CdiContainer (org.osgi.service.cdi.CdiContainer)8 Bundle (org.osgi.framework.Bundle)6 Hashtable (java.util.Hashtable)4 Filter (org.osgi.framework.Filter)4 ServiceTracker (org.osgi.util.tracker.ServiceTracker)4 BeanService (org.apache.aries.cdi.test.interfaces.BeanService)3 Configuration (org.osgi.service.cm.Configuration)3 Callable (java.util.concurrent.Callable)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 List (java.util.List)1 Map (java.util.Map)1 BundleEvent (org.osgi.framework.BundleEvent)1 ServiceReference (org.osgi.framework.ServiceReference)1 BundleCapability (org.osgi.framework.wiring.BundleCapability)1 Capability (org.osgi.resource.Capability)1 CdiEvent (org.osgi.service.cdi.CdiEvent)1 Type (org.osgi.service.cdi.CdiEvent.Type)1 BundleTracker (org.osgi.util.tracker.BundleTracker)1