Search in sources :

Example 1 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project jetty.project by eclipse.

the class AbstractOSGiApp method registerAsOSGiService.

/* ------------------------------------------------------------ */
public void registerAsOSGiService() throws Exception {
    if (_registration == null) {
        Dictionary<String, String> properties = new Hashtable<String, String>();
        properties.put(OSGiWebappConstants.WATERMARK, OSGiWebappConstants.WATERMARK);
        if (getBundleSymbolicName() != null)
            properties.put(OSGiWebappConstants.OSGI_WEB_SYMBOLICNAME, getBundleSymbolicName());
        if (getBundleVersionAsString() != null)
            properties.put(OSGiWebappConstants.OSGI_WEB_VERSION, getBundleVersionAsString());
        properties.put(OSGiWebappConstants.OSGI_WEB_CONTEXTPATH, getContextPath());
        ServiceRegistration rego = FrameworkUtil.getBundle(this.getClass()).getBundleContext().registerService(ContextHandler.class.getName(), getContextHandler(), properties);
        setRegistration(rego);
    }
}
Also used : ContextHandler(org.eclipse.jetty.server.handler.ContextHandler) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 2 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project opennms by OpenNMS.

the class ApplicationFactoryServiceTracker method removedService.

@Override
public void removedService(ServiceReference reference, Object service) {
    ApplicationFactory factory = (ApplicationFactory) context.getService(reference);
    final ServiceRegistration servletRegistration = m_serviceRegistration.remove(factory);
    if (servletRegistration != null) {
        servletRegistration.unregister();
    }
    super.removedService(reference, service);
}
Also used : ApplicationFactory(org.opennms.vaadin.extender.ApplicationFactory) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 3 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 4 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 5 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)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