Search in sources :

Example 81 with ServiceRegistration

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

the class MockBundleContextDynamicReferencesTest method testAddRemoveOptionalMultipleService.

@Test
public void testAddRemoveOptionalMultipleService() {
    ServiceRegistration reg3a = bundleContext.registerService(ServiceInterface3.class.getName(), dependency3a, null);
    assertDependencies3(dependency3a);
    ServiceRegistration reg3b = bundleContext.registerService(ServiceInterface3.class.getName(), dependency3b, null);
    assertDependencies3(dependency3a, dependency3b);
    reg3a.unregister();
    assertDependencies3(dependency3b);
    reg3b.unregister();
    assertDependencies3();
}
Also used : ServiceInterface3(org.apache.sling.testing.mock.osgi.OsgiServiceUtilTest.ServiceInterface3) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 82 with ServiceRegistration

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

the class AbstractSlingLaunchpadOakTestSupport method testOsgiResourceEvents.

@Test
public void testOsgiResourceEvents() throws RepositoryException {
    final ResourceEventListener listener = new ResourceEventListener();
    final ServiceRegistration reg = listener.register(bundleContext, SlingConstants.TOPIC_RESOURCE_ADDED);
    final Session s = slingRepository.loginAdministrative(null);
    final int nPaths = 2500 * TEST_SCALE;
    final int timeoutMsec = 2 * nPaths;
    final String prefix = uniqueName("testOsgiResourceEvents");
    // for each of them
    try {
        for (int i = 0; i < nPaths; i++) {
            s.getRootNode().addNode(prefix + i);
        }
        s.save();
        logger.info("Added {} nodes, checking what ResourceEventListener got...", nPaths);
        final long timeout = System.currentTimeMillis() + timeoutMsec;
        final Set<String> missing = new HashSet<String>();
        while (System.currentTimeMillis() < timeout) {
            missing.clear();
            final Set<String> paths = listener.getPaths();
            for (int i = 0; i < nPaths; i++) {
                final String path = "/" + prefix + i;
                if (!paths.contains(path)) {
                    missing.add(path);
                }
            }
            if (missing.isEmpty()) {
                break;
            }
        }
        if (!missing.isEmpty()) {
            final String missingStr = missing.size() > 10 ? missing.size() + " paths missing" : missing.toString();
            fail("OSGi add resource events are missing for " + missing.size() + "/" + nPaths + " paths after " + timeoutMsec + " msec: " + missingStr);
        }
    } finally {
        reg.unregister();
        s.logout();
    }
    logger.info("Successfuly detected OSGi observation events for " + nPaths + " paths");
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration) Session(javax.jcr.Session) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 83 with ServiceRegistration

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

the class PostOperationProxyProvider method unregister.

/**
     * Unregister proxy and unget SlingPostOperation service
     * <p>
     * Called by serviceChanged
     */
private void unregister(final ServiceReference serviceReference) {
    final ServiceRegistration proxyRegistration;
    synchronized (this.proxies) {
        proxyRegistration = this.proxies.remove(serviceReference);
    }
    if (proxyRegistration != null) {
        log.debug("Unregistering {}", proxyRegistration);
        this.bundleContext.ungetService(serviceReference);
        proxyRegistration.unregister();
    }
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 84 with ServiceRegistration

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

the class LogTracer method deactivate.

@Deactivate
private void deactivate() {
    if (logServlet != null) {
        logServlet.unregister();
    }
    if (slingFilterRegistration != null) {
        slingFilterRegistration.unregister();
        slingFilterRegistration = null;
    }
    if (filterRegistration != null) {
        filterRegistration.unregister();
        filterRegistration = null;
    }
    ServiceRegistration reg = logCollectorReg.getAndSet(null);
    if (reg != null) {
        reg.unregister();
    }
    requestContextHolder.remove();
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration) Deactivate(org.apache.felix.scr.annotations.Deactivate)

Example 85 with ServiceRegistration

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

the class StartupFilterImplTest method setup.

@Before
public void setup() {
    activeFilterCount = new AtomicInteger();
    mockery = new Mockery();
    request = mockery.mock(HttpServletRequest.class);
    response = mockery.mock(HttpServletResponse.class);
    chain = mockery.mock(FilterChain.class);
    serviceRegistration = mockery.mock(ServiceRegistration.class);
    filter = new TestFilterImpl();
    requestPath = "/NO_PATH_YET";
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Mockery(org.jmock.Mockery) ServiceRegistration(org.osgi.framework.ServiceRegistration) Before(org.junit.Before)

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