/** * 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); }
public ModuleApplicationContextExtension(Bundle bundle) { _bundle = bundle; _dependencyManager = new DependencyManager( bundle.getBundleContext()); }
/** * Our Activator is starting. */ @Override public void start(BundleContext context) throws Exception { m_manager = new DependencyManager(context); init(context, m_manager); }
/** * Start method of the bundle activator. Initializes the dependency manager * and calls <code>init()</code>. * * @param context the bundle context */ public void start(BundleContext context) throws Exception { m_context = context; m_logger = new Logger(context); m_manager = new DependencyManager(context, m_logger); setDependencyManager(m_manager); init(m_context, m_manager); }
@Before public void setUp() throws Exception { m_bundleContext = mock(BundleContext.class); Bundle bundle = mock(Bundle.class); when(m_bundleContext.getBundle()).thenReturn(bundle); System.setOut(new PrintStream(outContent)); System.setErr(new PrintStream(errContent)); dm = new DependencyManager(m_bundleContext); dme = new DMCommand(m_bundleContext); }
if (dm == null) dm = new DependencyManager(b.getBundleContext()); m_managers.put(b, dm);
public void start(BundleContext context) { try { this.dm = new DependencyManager(context);
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; }
@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); }
final DependencyManager dm = new DependencyManager( this.bundleContext ); final Component comp = dm.createComponent();
@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); }