Search in sources :

Example 1 with ScrService

use of org.apache.felix.scr.ScrService 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 2 with ScrService

use of org.apache.felix.scr.ScrService in project fabric8 by fabric8io.

the class ScrState method checkBundle.

@Override
protected Check checkBundle(Bundle bundle) {
    if (bundle.getHeaders().get("Service-Component") == null) {
        return null;
    }
    ScrService svc = tracker.getService();
    if (svc == null) {
        return new Check("scr-state", "No ScrService found");
    }
    Component[] components = svc.getComponents(bundle);
    if (components != null) {
        for (Component component : components) {
            int state = component.getState();
            if (state != Component.STATE_ACTIVE && state != Component.STATE_REGISTERED && state != Component.STATE_FACTORY) {
                return new Check("scr-state", "SCR bundle " + bundle.getBundleId() + " is in state " + getState(state));
            }
        }
    }
    return null;
}
Also used : Check(io.fabric8.karaf.checks.Check) ScrService(org.apache.felix.scr.ScrService) Component(org.apache.felix.scr.Component)

Aggregations

ScrService (org.apache.felix.scr.ScrService)2 Check (io.fabric8.karaf.checks.Check)1 Hashtable (java.util.Hashtable)1 Component (org.apache.felix.scr.Component)1 ScrInfo (org.apache.felix.scr.ScrInfo)1 ServiceReference (org.osgi.framework.ServiceReference)1 ServiceComponentRuntime (org.osgi.service.component.runtime.ServiceComponentRuntime)1 ServiceTrackerCustomizer (org.osgi.util.tracker.ServiceTrackerCustomizer)1