Search in sources :

Example 46 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class ConfigurationManager method stop.

@Override
public void stop(BundleContext bundleContext) {
    // stop handling bundle events immediately
    handleBundleEvents = false;
    // stop handling ManagedService[Factory] services
    managedServiceFactoryTracker.close();
    managedServiceTracker.close();
    // see FELIX-2813 for details
    if (updateThread != null) {
        updateThread.terminate();
    }
    if (eventThread != null) {
        eventThread.terminate();
    }
    // immediately unregister the Configuration Admin before cleaning up
    // clearing the field before actually unregistering the service
    // prevents IllegalStateException in getServiceReference() if
    // the field is not null but the service already unregistered
    final ServiceRegistration caReg = configurationAdminRegistration;
    configurationAdminRegistration = null;
    if (caReg != null) {
        caReg.unregister();
    }
    // consider inactive after unregistering such that during
    // unregistration the manager is still alive and can react
    isActive = false;
    // don't care for PersistenceManagers any more
    persistenceManagerTracker.close();
    // shutdown the file persistence manager
    final ServiceRegistration filePmReg = filepmRegistration;
    filepmRegistration = null;
    if (filePmReg != null) {
        filePmReg.unregister();
    }
    // stop listening for events
    bundleContext.removeBundleListener(this);
    if (configurationListenerTracker != null) {
        configurationListenerTracker.close();
    }
    if (syncConfigurationListenerTracker != null) {
        syncConfigurationListenerTracker.close();
    }
    if (logTracker != null) {
        logTracker.close();
    }
    // just ensure the configuration cache is empty
    synchronized (configurations) {
        configurations.clear();
    }
    this.bundleContext = null;
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 47 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class AspectAnnotationTest method testAspectChain.

public void testAspectChain() throws Throwable {
    Ensure e = new Ensure();
    // Activate service consumer
    ServiceRegistration scSequencer = register(e, ServiceConsumer.ENSURE);
    // Activate service provider
    ServiceRegistration spSequencer = register(e, ServiceProvider.ENSURE);
    // Activate service aspect 2
    ServiceRegistration sa2Sequencer = register(e, ServiceAspect2.ENSURE);
    // Activate service aspect 3
    ServiceRegistration sa3Sequencer = register(e, ServiceAspect3.ENSURE);
    // Activate service aspect 1
    ServiceRegistration sa1Sequencer = register(e, ServiceAspect1.ENSURE);
    e.step();
    e.waitForStep(6, 10000);
    // Deactivate service provider
    spSequencer.unregister();
    // Make sure that service aspect 1 has been called in ts removed and stop callbacks
    e.waitForStep(8, 10000);
    e.ensure();
    scSequencer.unregister();
    sa1Sequencer.unregister();
    sa2Sequencer.unregister();
    sa3Sequencer.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 48 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class AspectLifecycleAnnotationTest method testAnnotatedAspect.

public void testAnnotatedAspect() {
    Ensure e = new Ensure();
    // Provide the Sequencer server to the ServiceProvider service
    ServiceRegistration sr1 = register(e, ServiceProvider.ENSURE);
    // Check if the ServiceProvider has been injected in the AspectTest service.
    e.waitForStep(1, 10000);
    // Provide the Sequencer server to the ServiceProviderAspect service
    ServiceRegistration sr2 = register(e, ServiceProviderAspect.ENSURE);
    // Check if the AspectTest has been injected with the aspect
    e.waitForStep(3, 10000);
    // Stop the ServiceProviderAspect service.
    sr2.unregister();
    // And check if the aspect has been called in its stop/destroy methods.
    e.waitForStep(7, 10000);
    sr1.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 49 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class AspectLifecycleWithDynamicProxyAnnotationTest method testAnnotatedAspect.

public void testAnnotatedAspect() {
    Ensure e = new Ensure();
    // Provide the Sequencer server to the ServiceProvider service
    ServiceRegistration sr1 = register(e, ServiceProvider.ENSURE);
    // Check if the ServiceProvider has been injected in the AspectTest service.
    e.waitForStep(1, 10000);
    // Provide the Sequencer server to the ServiceProviderAspect service
    ServiceRegistration sr2 = register(e, ServiceProviderAspect.ENSURE);
    // Check if the AspectTest has been injected with the aspect
    e.waitForStep(3, 10000);
    // Remove the ServiceProviderAspect service
    sr2.unregister();
    // And check if the aspect has been called in its stop/destroy methods.
    e.waitForStep(7, 10000);
    sr1.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 50 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project felix by apache.

the class BundleDependencyAnnotationTest method testBundleAdapterServiceAnnotation.

/**
 * Tests a Bundle Adapter, which adapts the dependency manager bundle to a "ServiceInterface" service.
 * @throws Throwable
 */
public void testBundleAdapterServiceAnnotation() throws Throwable {
    Ensure e = new Ensure();
    ServiceRegistration sr = register(e, BundleDependencyAnnotation.ENSURE_ADAPTER);
    e.waitForStep(3, 10000);
    e.ensure();
    sr.unregister();
}
Also used : Ensure(org.apache.felix.dm.itest.util.Ensure) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Aggregations

ServiceRegistration (org.osgi.framework.ServiceRegistration)365 Test (org.junit.Test)106 Hashtable (java.util.Hashtable)94 Bundle (org.osgi.framework.Bundle)64 BundleContext (org.osgi.framework.BundleContext)64 Dictionary (java.util.Dictionary)62 Ensure (org.apache.felix.dm.itest.util.Ensure)42 Properties (java.util.Properties)39 ServiceReference (org.osgi.framework.ServiceReference)38 ArrayList (java.util.ArrayList)34 HashMap (java.util.HashMap)28 ServiceFactory (org.osgi.framework.ServiceFactory)21 IOException (java.io.IOException)16 Map (java.util.Map)15 List (java.util.List)12 ServiceEvent (org.osgi.framework.ServiceEvent)12 HashSet (java.util.HashSet)11 CountDownLatch (java.util.concurrent.CountDownLatch)10 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)10 Collection (java.util.Collection)9