Package org.apache.felix.dm

Examples of org.apache.felix.dm.ServiceDependency


            // remove our internal dependency, replace it with one that points to the specific service that just was passed in.
            dependencies.remove(0);
            Properties serviceProperties = getServiceProperties(ref);
            String[] serviceInterfaces = getServiceInterfaces();
           
            ServiceDependency aspectDependency = (ServiceDependencyImpl)
                    m_manager.createServiceDependency().setService(m_aspectInterface, createAspectFilter(ref)).setRequired(true);

//            aspectDependency.setDebug("AspectDependency#" +
//                    (m_serviceImpl instanceof Class ? (((Class) m_serviceImpl).getSimpleName()) : m_serviceImpl));
           
            aspectDependency.setCallbacks(new CallbackProxy(aspectDependency, ref),
                            m_add != null ? "addAspect" : null,
                            "changeAspect", // We have to propagate in case aspect does not have a change callback
                            m_remove != null ? "removeAspect" : null,
                            m_swap != null ? "swapAspect" : null);
           
            if (m_autoConfig != null) {
                aspectDependency.setAutoConfig(m_autoConfig);
            } else if (m_add == null && m_change == null && m_remove == null && m_swap == null) {
                // Since we have set callbacks, we must reactivate setAutoConfig because user has not specified any callbacks.
                aspectDependency.setAutoConfig(true);
            }
           
            Component service = m_manager.createComponent()
                .setInterface(serviceInterfaces, serviceProperties)
                .setImplementation(m_serviceImpl)
View Full Code Here


        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a resource provider
       
        Component component = m.createComponent().setInterface(MyService2.class.getName(), null).setImplementation(new MyComponent(e));
        ServiceDependency dependency = m.createServiceDependency().setService(MyService.class).setRequired(true);
        ServiceDependency dependency2 = m.createServiceDependency().setService(MyService.class).setRequired(true);
        ServiceTracker st = new ServiceTracker(context, MyService2.class.getName(), null);
        st.open();
        Component component2 = m.createComponent().setInterface(MyService.class.getName(), null).setImplementation(new MyImpl(e));
       
        // add the component: it has no dependencies so it should be activated immediately
        m.add(component);
        Assert.assertNotNull("service should be available", st.getService());
               
        // add a required dependency that is not available, so the component should be deactivated
        component.add(dependency);
        Assert.assertNull("service should no longer be available", st.getService());
        // remove the dependency again, so the component should be activated again
        component.remove(dependency);
        Assert.assertNotNull("service should be available", st.getService());
        // make the dependency instance bound
        dependency.setInstanceBound(true);
       
        // add it again, the component was already active so even though the dependency
        // is required, the component will *NOT* go through the destroy life cycle methods
        component.add(dependency);
        Assert.assertNull("service should no longer be available", st.getService());
        component.remove(dependency);
        Assert.assertNotNull("service should be available", st.getService());
       
        // make the second dependency instance bound too
        dependency2.setInstanceBound(true);
       
        // activate the service we depend on
        m.add(component2);
        // init and start should be invoked here, so wait for them to complete
        e.waitForStep(10, 5000);
View Full Code Here

        DependencyManager m = new DependencyManager(context);
        // helper class that ensures certain steps get executed in sequence
        Ensure e = new Ensure();
        // create a service provider and consumer
        Component provider = m.createComponent().setImplementation(new ServiceProvider()).setInterface(ServiceInterface.class.getName(), null);
        ServiceDependency dependency = m.createServiceDependency().setService(ServiceInterface.class).setRequired(true);
        Component consumer1 = m.createComponent().setImplementation(new ServiceConsumer(e, 1)).add(dependency);
        Component consumer2 = m.createComponent().setImplementation(new ServiceConsumer(e, 4)).add(dependency);
       
        m.add(provider);
        m.add(consumer1);
View Full Code Here

            ServiceReference ref = (ServiceReference) properties[0];
            Object aspect = ref.getProperty(DependencyManager.ASPECT);           
            String serviceIdToTrack = (aspect != null) ? aspect.toString() : ref.getProperty(Constants.SERVICE_ID).toString();
            List dependencies = m_component.getDependencies();
            dependencies.remove(0);
            ServiceDependency dependency = m_manager.createServiceDependency()
               // create a dependency on both the service id we're adapting and possible aspects for this given service id
               .setService(m_adapteeInterface, "(|(" + Constants.SERVICE_ID + "=" + serviceIdToTrack
                     + ")(" + DependencyManager.ASPECT + "=" + serviceIdToTrack + "))")
                 .setRequired(true);
            if (m_autoConfig != null) {
                dependency.setAutoConfig(m_autoConfig);
            }
            if (m_add != null || m_change != null || m_remove != null || m_swap != null) {
                dependency.setCallbacks(m_add, m_change, m_remove, m_swap);
            }
            dependency.setPropagate(this, "propagateAdapteeProperties");
           
//            dependency.setDebug("AdapterDependency#" + m_adapteeInterface.getSimpleName());

            Component service = m_manager.createComponent()
                .setInterface(m_serviceInterfaces, getServiceProperties(ref))
View Full Code Here

    private Dependency createServiceDependency(DependencyManager dm, Class<?> serviceClass,
        String serviceFilter, Class<?> defaultServiceImplClass, String added,
        String changed, String removed, String autoConfigField, long timeout, boolean required,
        boolean instanceBound, boolean propagate)
    {
        ServiceDependency sd = timeout != -1 ? dm.createTemporalServiceDependency()
            : dm.createServiceDependency();
        sd.setService(serviceClass, serviceFilter);
        if (defaultServiceImplClass != null)
        {
            sd.setDefaultImplementation(defaultServiceImplClass);
        }
        sd.setCallbacks(added, changed, removed);
        if (autoConfigField != null)
        {
            sd.setAutoConfig(autoConfigField);
        }
        if (timeout != -1)
        {
            ((TemporalServiceDependency) sd).setTimeout(timeout);
            // Set required flag (always true for a temporal dependency)
            sd.setRequired(true);
        }
        else
        {
            // for ServiceDependency, get required flag.
            sd.setRequired(required);
        }
       
        sd.setInstanceBound(instanceBound);
        sd.setPropagate(propagate);
        return sd;
    }
View Full Code Here

        for (Map.Entry<String, Class<?>> entry : services.entrySet())
        {
            String serviceProperty = entry.getKey();
            Class<?> service = entry.getValue();
            boolean serviceActive = "true".equalsIgnoreCase(context.getProperty(serviceProperty));
            ServiceDependency serviceDep =
                    serviceActive ? createTemporalServiceDependency()
                                 : createServiceDependency().setRequired(false);
            serviceDep.setService(service).setAutoConfig(true);
            component.add(serviceDep);
        }
        dm.add( component );
    }
View Full Code Here

TOP

Related Classes of org.apache.felix.dm.ServiceDependency

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.