public void added(Bundle bundle) throws Exception { Component newService = createService(new Object[] { bundle }); m_services.put(bundle, newService); m_manager.add(newService); }
private void unregisterFactoryService() { Component component = m_factoryComponent; m_factoryComponent = null; if (component != null) { m_dependencyManager.remove(component); } }
private void addListener(final Object implementation, final String... topics) { Properties props = new Properties(); props.put(EventConstants.EVENT_TOPIC, topics); props.put(EventConstants.EVENT_FILTER, "(" + SessionFactory.SERVICE_SID + "=" + m_sessionID + ")"); Component component = m_manager.createComponent() .setInterface(EventHandler.class.getName(), props) .setImplementation(implementation); synchronized (m_eventHandlers) { m_eventHandlers.add(component); } m_manager.add(component); }
public FactoryConfigurationAdapterImpl(DependencyManager dm) { super(dm.createComponent()); m_logger = dm.getLogger(); }
@SuppressWarnings("unchecked") private <T extends RepositoryObject> Component[] registerRepository(Class<? extends ObjectRepository<T>> iface, ObjectRepositoryImpl<?, T> imp, String[] topics) { Component repositoryService = m_manager.createComponent() .setInterface(iface.getName(), m_sessionProps) .setImplementation(imp) .add(m_manager.createServiceDependency().setService(LogService.class).setRequired(false)); Dictionary topic = new Hashtable(); topic.put(EventConstants.EVENT_TOPIC, topics); topic.put(EventConstants.EVENT_FILTER, "(" + SessionFactory.SERVICE_SID + "=" + m_sessionID + ")"); Component handlerService = m_manager.createComponent() .setInterface(EventHandler.class.getName(), topic) .setImplementation(imp); m_manager.add(repositoryService); m_manager.add(handlerService); return new Component[] {repositoryService, handlerService}; }
@Test public void testComponentThatDependsOnAOtheComponentShouldRegisterAsFailure() { OUT.println("testComponentThatDependsOnAOtheComponentShouldRegisterAsFailure"); setupEmptyBundles(); DependencyManager dm = new DependencyManager(m_bundleContext); DependencyManager.getDependencyManagers().add(dm); Component component = dm.createComponent() .setImplementation(Object.class) .setInterface(Object.class.getName(), null) .add(dm.createServiceDependency().setService(Math.class).setRequired(true)); dm.add(component); dme.wtf(); String output = outContent.toString(); assertTrue(output.contains("1 unregistered")); assertTrue(output.contains("java.lang.Math")); // remove the mess dm.remove(component); }
@Test public void testCanFindRootFailure() { OUT.println("testCanFindRootFailure"); setupEmptyBundles(); Component component1 = dm.createComponent() .setImplementation(Object.class) .setInterface(Object.class.getName(), null) .add(dm.createServiceDependency().setService(Math.class).setRequired(true)); dm.add(component1); Component component2 = dm.createComponent() .setImplementation(Math.class) .setInterface(Math.class.getName(), null) .add(dm.createServiceDependency().setService(String.class).setRequired(true)); dm.add(component2); dme.wtf(); String output = outContent.toString(); assertTrue(output.contains("2 unregistered")); assertTrue(output.contains("java.lang.String")); // remove the mess dm.remove(component1); dm.remove(component2); }
final DependencyManager dm = new DependencyManager( this.bundleContext ); final Component comp = dm.createComponent(); .add( dm.createServiceDependency() // .setService( ConfigurationAdmin.class ) // .setRequired( true ) ) // dm.add( comp );
public void start(BundleContext context) { try { this.dm = new DependencyManager(context); if (c == null) { try { c = this.dm.createComponent(); c.addStateListener(new ListenerComponentStates()); this.dm.add(c); } catch (Exception nex) { logger.error("During creation of a Global "
private FactoryConfigurationAdapterImpl createConfigurationDependency(Object service, Class<?> configType) { BundleContext bc = mock(BundleContext.class); DependencyManager dm = new DependencyManager(bc); Component result = dm.createFactoryConfigurationAdapterService("does.not.matter", "updated", false, service, configType); // Normally, when creating a factory pid adapter, you specify the class of the adapter implementation which will be instantiated // for each created factory pid. To do so, you invoke the setImplementation(Object impl) method, and this methods // accepts a class parameter, or an object instance. Usually, you always pass a class, because the intent of a factory pid adapter is to // create a component instance for each created factory pid. But in our case, the "service" parameter represents our adapter instance, // so just use it as the factory adapter implementation instance: result.setImplementation(service); // *Important note:* the semantic of the factory conf pid adapter is really similar to a ManagedServiceFactory: // - when the factory pid is created, a component is created; called in updated; and called in start(). // - when the factory pid is updated, the component is called in updated(). // - but when the factory pid is removed, updated(null) is not invoked (unlike in case of ConfigurationDependency), and the component is simply // stopped. This is actually the same semantic as ManagedServiceFactory: when factory pid is removed, ManagedServiceFactory.deleted() is called // and the deleted() method is assumed to stop and unregister the service that was registered for the pid being removed. dm.add(result); return (FactoryConfigurationAdapterImpl) result; }
public ContainerServiceDependency(DependencyManager manager, String containerName) { this.m_dep = manager.createServiceDependency(); this.containerName = containerName; }
/** * Creates a new Bundle Adapter Service implementation. */ public BundleAdapterImpl(DependencyManager dm) { super(dm.createComponent()); // This service will be filtered by our super class, allowing us to take control. }
/** * Creates a new dependency manager. * * @param context the bundle context * @param logger */ public DependencyManager(BundleContext context) { m_delegate = new org.apache.felix.dm.DependencyManager(context); }
/** * Called by Dependency Manager upon initialization of this component. */ public void init( final Component aComponent ) throws Exception { Dictionary<?, ?> bundleProps = this.bundle.getHeaders(); String entry = ( String )bundleProps.get( this.headerKey ); if ( ( entry == null ) || "".equals( entry ) ) { throw new IllegalArgumentException( "No such header given: " + this.headerKey ); } Class<?> implClass = this.bundle.loadClass( entry ); Properties serviceProps = copyOlsProperties( bundleProps ); this.serviceComponent = this.manager.createComponent() // .setInterface( this.serviceClass.getName(), serviceProps ) // .setImplementation( implClass ) // .add( this.manager.createServiceDependency() // .setService( LogService.class ) // .setRequired( false ) // ); this.manager.add( this.serviceComponent ); }
@Test public void testComponentThatHaveCycliclyDependencyOnAOtheComponentShouldRegisterAsFailure() { OUT.println("testComponentThatHaveCycliclyDependencyOnAOtheComponentShouldRegisterAsFailure"); setupEmptyBundles(); DependencyManager dm = new DependencyManager(m_bundleContext); DependencyManager.getDependencyManagers().add(dm); Component component1 = dm.createComponent() .setImplementation(Cipher.class) .setInterface(Cipher.class.getName(), null) .add(dm.createServiceDependency().setService(Math.class).setRequired(true)); dm.add(component1); Component component2 = dm.createComponent() .setImplementation(Math.class) .setInterface(Math.class.getName(), null) .add(dm.createServiceDependency().setService(Cipher.class).setRequired(true)); dm.add(component2); dme.wtf(); String output = outContent.toString(); assertTrue(output.contains("-> java.lang.Math -> javax.crypto.Cipher -> java.lang.Math") || output.contains("-> javax.crypto.Cipher -> java.lang.Math -> javax.crypto.Cipher")); // remove the mess dm.remove(component1); dm.remove(component2); }
@Test public void testCanFindRootFailureWithTwoFailures() { OUT.println("testCanFindRootFailureWithTwoFailures"); setupEmptyBundles(); Component component1 = dm.createComponent() .setImplementation(Object.class) .setInterface(Object.class.getName(), null) .add(dm.createServiceDependency().setService(Math.class).setRequired(true)) .add(dm.createServiceDependency().setService(Long.class).setRequired(true)); dm.add(component1); dme.wtf(); String output = outContent.toString(); assertTrue(output.contains("1 unregistered")); assertTrue(output.contains("java.lang.Math")); assertTrue(output.contains("java.lang.Long")); // remove the mess dm.remove(component1); }
/** * Return a ServiceDependency as provided by Dependency Manager as it's * * * @return a ServiceDependency */ protected ServiceDependency createServiceDependency() { return this.dm.createServiceDependency(); } }
/** * Creates a new Adapter Service implementation. */ public AdapterServiceImpl(DependencyManager dm) { super(dm.createComponent()); }
public ModuleApplicationContextExtension(Bundle bundle) { _bundle = bundle; _dependencyManager = new DependencyManager( bundle.getBundleContext()); }
public void added(URL resource) throws Exception { Component newService = createService(new Object[] { resource }); m_services.put(resource, newService); m_manager.add(newService); }