Search in sources :

Example 31 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jackrabbit-oak by apache.

the class StatisticsProviderFactory method deactivate.

@Deactivate
private void deactivate() throws IOException {
    for (ServiceRegistration reg : regs) {
        reg.unregister();
    }
    regs.clear();
    if (statisticsProvider instanceof Closeable) {
        ((Closeable) statisticsProvider).close();
    }
    new ExecutorCloser(executor).close();
}
Also used : Closeable(java.io.Closeable) ExecutorCloser(org.apache.jackrabbit.oak.commons.concurrent.ExecutorCloser) ServiceRegistration(org.osgi.framework.ServiceRegistration) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Example 32 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jackrabbit-oak by apache.

the class SecurityProviderRegistration method maybeRegister.

private void maybeRegister() {
    BundleContext context;
    log.info("Trying to register a SecurityProvider...");
    synchronized (this) {
        if (this.context == null) {
            log.info("Aborting: no BundleContext is available");
            return;
        }
        if (!preconditions.areSatisfied()) {
            log.info("Aborting: preconditions are not satisfied: {}", preconditions);
            return;
        }
        if (registration != null) {
            log.info("Aborting: a SecurityProvider is already registered");
            return;
        }
        if (registering) {
            log.info("Aborting: a SecurityProvider is already being registered");
            return;
        }
        // Mark the start of a registration process.
        registering = true;
        // Save the BundleContext for local usage.
        context = this.context;
    }
    // Register the SecurityProvider.
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put("type", "default");
    ServiceRegistration registration = context.registerService(SecurityProvider.class.getName(), createSecurityProvider(context), properties);
    synchronized (this) {
        this.registration = registration;
        this.registering = false;
    }
    log.info("SecurityProvider instance registered");
}
Also used : Hashtable(java.util.Hashtable) SecurityProvider(org.apache.jackrabbit.oak.spi.security.SecurityProvider) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 33 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jackrabbit-oak by apache.

the class SecurityProviderRegistration method deactivate.

@Deactivate
public void deactivate() {
    ServiceRegistration registration;
    synchronized (this) {
        registration = this.registration;
        this.registration = null;
        this.registering = false;
        this.context = null;
        this.preconditions.clearPreconditions();
    }
    if (registration != null) {
        registration.unregister();
    }
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Example 34 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jackrabbit-oak by apache.

the class SecurityProviderRegistration method maybeUnregister.

private void maybeUnregister() {
    ServiceRegistration registration;
    log.info("Trying to unregister the SecurityProvider...");
    synchronized (this) {
        if (this.registration == null) {
            log.info("Aborting: no SecurityProvider is registered");
            return;
        }
        if (preconditions.areSatisfied()) {
            log.info("Aborting: preconditions are satisfied");
            return;
        }
        // Save the ServiceRegistration for local use.
        registration = this.registration;
        this.registration = null;
    }
    registration.unregister();
    log.info("SecurityProvider instance unregistered");
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 35 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jackrabbit-oak by apache.

the class SegmentCachingDataStoreStatsTest method testUseCachingBlobStore.

@Test
public void testUseCachingBlobStore() {
    ServiceRegistration delegateReg = context.bundleContext().registerService(AbstractSharedCachingDataStore.class.getName(), mock(AbstractSharedCachingDataStore.class), null);
    assertNotNull(context.getService(AbstractSharedCachingDataStore.class));
    registerBlobStore();
    registerSegmentNodeStoreService(true);
    assertServiceActivated();
    ConsolidatedDataStoreCacheStats dataStoreStats = context.registerInjectActivateService(new ConsolidatedDataStoreCacheStats());
    assertNotNull(context.getService(ConsolidatedDataStoreCacheStatsMBean.class));
    deactivate(dataStoreStats, context.bundleContext());
    unregisterSegmentNodeStoreService();
    unregisterBlobStore();
    delegateReg.unregister();
}
Also used : AbstractSharedCachingDataStore(org.apache.jackrabbit.oak.plugins.blob.AbstractSharedCachingDataStore) ConsolidatedDataStoreCacheStats(org.apache.jackrabbit.oak.plugins.blob.ConsolidatedDataStoreCacheStats) ConsolidatedDataStoreCacheStatsMBean(org.apache.jackrabbit.oak.api.jmx.ConsolidatedDataStoreCacheStatsMBean) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Aggregations

ServiceRegistration (org.osgi.framework.ServiceRegistration)188 Test (org.junit.Test)80 Hashtable (java.util.Hashtable)61 BundleContext (org.osgi.framework.BundleContext)35 Bundle (org.osgi.framework.Bundle)26 Dictionary (java.util.Dictionary)23 Properties (java.util.Properties)22 HashMap (java.util.HashMap)21 ServiceReference (org.osgi.framework.ServiceReference)21 ArrayList (java.util.ArrayList)18 Map (java.util.Map)13 IOException (java.io.IOException)8 ServiceFactory (org.osgi.framework.ServiceFactory)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 URL (java.net.URL)6 HashSet (java.util.HashSet)6 List (java.util.List)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ObjectName (javax.management.ObjectName)5 InitialContext (javax.naming.InitialContext)5