Search in sources :

Example 6 with ServiceComponentRuntime

use of org.osgi.service.component.runtime.ServiceComponentRuntime in project felix by apache.

the class ComponentTestBase method findComponentConfigurationsByName.

protected Collection<ComponentConfigurationDTO> findComponentConfigurationsByName(Bundle b, String name, int expected) {
    ServiceComponentRuntime scr = scrTracker.getService();
    if (scr == null) {
        TestCase.fail("no ServiceComponentRuntime");
    }
    ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
    Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
    if (expected != 0) {
        String sep = "[";
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<Integer, String> entry : STATES.entrySet()) {
            if ((expected & entry.getKey()) != 0) {
                sb.append(sep).append(entry.getValue());
                sep = ", ";
            }
        }
        sb.append("]");
        for (ComponentConfigurationDTO cc : ccs) {
            Assert.assertTrue("for ComponentConfiguration name: " + cc.description.name + " properties" + cc.properties + "Expected one of state " + sb.toString() + " but was " + STATES.get(cc.state), (expected & cc.state) == cc.state);
        }
    }
    return ccs;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) Map(java.util.Map) HashMap(java.util.HashMap) ServiceComponentRuntime(org.osgi.service.component.runtime.ServiceComponentRuntime)

Example 7 with ServiceComponentRuntime

use of org.osgi.service.component.runtime.ServiceComponentRuntime in project felix by apache.

the class ComponentTestBase method checkConfigurationCount.

protected ComponentDescriptionDTO checkConfigurationCount(Bundle b, String name, int count, int expectedState) {
    ServiceComponentRuntime scr = scrTracker.getService();
    if (scr == null) {
        TestCase.fail("no ServiceComponentRuntime");
    }
    ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
    Assert.assertTrue("Expected component enabled", scr.isComponentEnabled(cd));
    Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
    Assert.assertEquals(count, ccs.size());
    if (expectedState != -1) {
        for (ComponentConfigurationDTO cc : ccs) {
            Assert.assertEquals("Expected state " + STATES.get(expectedState) + " but was " + STATES.get(cc.state), expectedState, cc.state);
        }
    }
    return cd;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) ServiceComponentRuntime(org.osgi.service.component.runtime.ServiceComponentRuntime)

Example 8 with ServiceComponentRuntime

use of org.osgi.service.component.runtime.ServiceComponentRuntime in project felix by apache.

the class ComponentTestBase method getConfigurationsDisabledThenEnable.

protected Collection<ComponentConfigurationDTO> getConfigurationsDisabledThenEnable(Bundle b, String name, int count, int initialState) throws InvocationTargetException, InterruptedException {
    ServiceComponentRuntime scr = scrTracker.getService();
    if (scr == null) {
        TestCase.fail("no ServiceComponentRuntime");
    }
    ComponentDescriptionDTO cd = scr.getComponentDescriptionDTO(b, name);
    Assert.assertFalse("Expected component disabled", scr.isComponentEnabled(cd));
    scr.enableComponent(cd).getValue();
    Assert.assertTrue("Expected component enabled", scr.isComponentEnabled(cd));
    Collection<ComponentConfigurationDTO> ccs = scr.getComponentConfigurationDTOs(cd);
    Assert.assertEquals(count, ccs.size());
    for (ComponentConfigurationDTO cc : ccs) {
        Assert.assertEquals("Expected state " + STATES.get(initialState) + " but was " + STATES.get(cc.state), initialState, cc.state);
    }
    return ccs;
}
Also used : ComponentDescriptionDTO(org.osgi.service.component.runtime.dto.ComponentDescriptionDTO) ComponentConfigurationDTO(org.osgi.service.component.runtime.dto.ComponentConfigurationDTO) ServiceComponentRuntime(org.osgi.service.component.runtime.ServiceComponentRuntime)

Example 9 with ServiceComponentRuntime

use of org.osgi.service.component.runtime.ServiceComponentRuntime in project felix by apache.

the class Activator method start.

public void start(final BundleContext context) throws Exception {
    this.runtimeTracker = new ServiceTracker<ServiceComponentRuntime, ServiceComponentRuntime>(context, ServiceComponentRuntime.class, new ServiceTrackerCustomizer<ServiceComponentRuntime, ServiceComponentRuntime>() {

        public ServiceComponentRuntime addingService(final ServiceReference<ServiceComponentRuntime> reference) {
            final ServiceComponentRuntime runtime = context.getService(reference);
            if (runtime != null) {
                final Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Constants.SERVICE_DESCRIPTION, "Apache Felix Compat ScrService");
                props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
                final ScrService service = new ScrServiceImpl(context, runtime);
                scrServiceRegMap.put((Long) reference.getProperty(Constants.SERVICE_ID), context.registerService(ScrService.class, service, props));
            }
            return runtime;
        }

        public void modifiedService(final ServiceReference<ServiceComponentRuntime> reference, final ServiceComponentRuntime service) {
        // nothing to do
        }

        public void removedService(final ServiceReference<ServiceComponentRuntime> reference, final ServiceComponentRuntime service) {
            final ServiceRegistration<ScrService> reg = scrServiceRegMap.remove(reference.getProperty(Constants.SERVICE_ID));
            if (reg != null) {
                reg.unregister();
            }
            context.ungetService(reference);
        }
    });
    this.runtimeTracker.open();
    this.infoTracker = new ServiceTracker<org.apache.felix.scr.info.ScrInfo, org.apache.felix.scr.info.ScrInfo>(context, org.apache.felix.scr.info.ScrInfo.class, new ServiceTrackerCustomizer<org.apache.felix.scr.info.ScrInfo, org.apache.felix.scr.info.ScrInfo>() {

        public org.apache.felix.scr.info.ScrInfo addingService(final ServiceReference<org.apache.felix.scr.info.ScrInfo> reference) {
            final org.apache.felix.scr.info.ScrInfo runtime = context.getService(reference);
            if (runtime != null) {
                final Dictionary<String, Object> props = new Hashtable<String, Object>();
                props.put(Constants.SERVICE_DESCRIPTION, "Apache Felix Compat SCR Info service");
                props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation");
                final ScrInfo info = new ScrCommand(runtime);
                scrCommandRegMap.put((Long) reference.getProperty(Constants.SERVICE_ID), context.registerService(ScrInfo.class, info, props));
            }
            return runtime;
        }

        public void modifiedService(final ServiceReference<org.apache.felix.scr.info.ScrInfo> reference, final org.apache.felix.scr.info.ScrInfo service) {
        // nothing to do
        }

        public void removedService(final ServiceReference<org.apache.felix.scr.info.ScrInfo> reference, final org.apache.felix.scr.info.ScrInfo service) {
            final ServiceRegistration<ScrInfo> reg = scrCommandRegMap.remove(reference.getProperty(Constants.SERVICE_ID));
            if (reg != null) {
                reg.unregister();
            }
            context.ungetService(reference);
        }
    });
    this.infoTracker.open();
}
Also used : ServiceTrackerCustomizer(org.osgi.util.tracker.ServiceTrackerCustomizer) Hashtable(java.util.Hashtable) ScrInfo(org.apache.felix.scr.ScrInfo) ServiceReference(org.osgi.framework.ServiceReference) ScrService(org.apache.felix.scr.ScrService) ServiceComponentRuntime(org.osgi.service.component.runtime.ServiceComponentRuntime)

Example 10 with ServiceComponentRuntime

use of org.osgi.service.component.runtime.ServiceComponentRuntime in project felix by apache.

the class Activator method doStart.

@Override
protected void doStart() throws Exception {
    // prepare component registry
    m_componentBundles = new HashMap<Long, BundleComponentActivator>();
    m_componentRegistry = new ComponentRegistry(this);
    final ServiceComponentRuntime runtime = new ServiceComponentRuntimeImpl(m_globalContext, m_componentRegistry);
    m_runtime_reg = m_context.registerService(ServiceComponentRuntime.class, runtime, null);
    // log SCR startup
    log(LogService.LOG_INFO, m_bundle, " Version = {0}", new Object[] { m_bundle.getVersion().toString() }, null);
    // create and start the component actor
    m_componentActor = new ComponentActorThread(this);
    Thread t = new Thread(m_componentActor, "SCR Component Actor");
    t.setDaemon(true);
    t.start();
    super.doStart();
    m_scrCommand = ScrCommand.register(m_context, runtime, m_configuration);
    m_configuration.setScrCommand(m_scrCommand);
}
Also used : ServiceComponentRuntimeImpl(org.apache.felix.scr.impl.runtime.ServiceComponentRuntimeImpl) ServiceComponentRuntime(org.osgi.service.component.runtime.ServiceComponentRuntime)

Aggregations

ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)10 ComponentConfigurationDTO (org.osgi.service.component.runtime.dto.ComponentConfigurationDTO)3 ComponentDescriptionDTO (org.osgi.service.component.runtime.dto.ComponentDescriptionDTO)3 Hashtable (java.util.Hashtable)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 InventoryPrinter (org.apache.felix.inventory.InventoryPrinter)1 ScrInfo (org.apache.felix.scr.ScrInfo)1 ScrService (org.apache.felix.scr.ScrService)1 ServiceComponentRuntimeImpl (org.apache.felix.scr.impl.runtime.ServiceComponentRuntimeImpl)1 SimpleWebConsolePlugin (org.apache.felix.webconsole.SimpleWebConsolePlugin)1 BundleInfoProvider (org.apache.felix.webconsole.bundleinfo.BundleInfoProvider)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1