Search in sources :

Example 96 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project ddf by codice.

the class ActionProviderRegistryProxy method bind.

public void bind(ServiceReference<MetacardTransformer> reference) {
    LOGGER.info("New service registered [{}]", reference);
    String transformerId = null;
    if (reference.getProperty(Constants.SERVICE_ID) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_ID).toString();
    // backwards compatibility
    }
    if (StringUtils.isBlank(transformerId) && reference.getProperty(Constants.SERVICE_SHORTNAME) != null) {
        transformerId = reference.getProperty(Constants.SERVICE_SHORTNAME).toString();
    }
    if (StringUtils.isBlank(transformerId)) {
        return;
    }
    String actionProviderId = ACTION_ID_PREFIX + transformerId;
    String attributeName = getAttributeName(reference);
    ActionProvider provider = actionFactory.createActionProvider(actionProviderId, transformerId, attributeName);
    Dictionary actionProviderProperties = new Hashtable<String, String>();
    actionProviderProperties.put(Constants.SERVICE_ID, actionProviderId);
    ServiceRegistration actionServiceRegistration = getBundleContext().registerService(PROVIDER_INTERFACE_NAME, provider, actionProviderProperties);
    LOGGER.info("Registered new {} [{}]", PROVIDER_INTERFACE_NAME, actionServiceRegistration);
    actionProviderRegistry.put(reference, actionServiceRegistration);
}
Also used : ActionProvider(ddf.action.ActionProvider) Dictionary(java.util.Dictionary) Hashtable(java.util.Hashtable) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 97 with ServiceRegistration

use of org.osgi.framework.ServiceRegistration in project ddf by codice.

the class TestCswSource method testAddingContentTypesOnQueries.

@Test
public void testAddingContentTypesOnQueries() throws CswException, UnsupportedQueryException, SecurityServiceException {
    Csw mockCsw = createMockCsw();
    List<String> expectedNames = new LinkedList<>(Arrays.asList("a", "b", "c", "d", "e", "f", "g", "h", "i", "j"));
    ServiceRegistration<?> mockRegisteredMetacardType = (ServiceRegistration<?>) mock(ServiceRegistration.class);
    LOGGER.info("mockRegisteredMetacardType: {}", mockRegisteredMetacardType);
    doReturn(mockRegisteredMetacardType).when(mockContext).registerService(eq(MetacardType.class.getName()), any(MetacardType.class), Matchers.any());
    ServiceReference<?> mockServiceReference = (ServiceReference<?>) mock(ServiceReference.class);
    doReturn(mockServiceReference).when(mockRegisteredMetacardType).getReference();
    when(mockServiceReference.getProperty(eq(Metacard.CONTENT_TYPE))).thenReturn(expectedNames);
    AbstractCswSource source = getCswSource(mockCsw, mockContext);
    assertThat(source.getContentTypes(), hasSize(10));
    Set<ContentType> expected = generateContentType(expectedNames);
    assertThat(source.getContentTypes(), is(expected));
    CswRecordCollection collection = generateCswCollection("/getRecordsResponse.xml");
    when(mockCsw.getRecords(any(GetRecordsType.class))).thenReturn(collection);
    QueryImpl propertyIsLikeQuery = new QueryImpl(builder.attribute(Metacard.ANY_TEXT).is().like().text("*"));
    expectedNames.add("dataset");
    expectedNames.add("dataset 2");
    expectedNames.add("dataset 3");
    expected = generateContentType(expectedNames);
    source.query(new QueryRequestImpl(propertyIsLikeQuery));
    assertThat(source.getContentTypes(), hasSize(13));
    assertThat(source.getContentTypes(), is(expected));
}
Also used : ContentType(ddf.catalog.data.ContentType) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) MetacardType(ddf.catalog.data.MetacardType) ServiceReference(org.osgi.framework.ServiceReference) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 98 with ServiceRegistration

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

the class Activator method registerJmxBean.

private void registerJmxBean(BundleContext context) throws MalformedObjectNameException {
    Hashtable<String, String> jmxProps = new Hashtable<String, String>();
    jmxProps.put("type", "Installer");
    jmxProps.put("name", "Sling OSGi Installer");
    final Hashtable<String, Object> mbeanProps = new Hashtable<String, Object>();
    mbeanProps.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Installer Controller Service");
    mbeanProps.put(Constants.SERVICE_VENDOR, VENDOR);
    mbeanProps.put("jmx.objectname", new ObjectName("org.apache.sling.installer", jmxProps));
    ServiceRegistration mbeanReg = context.registerService(new String[] { InstallerMBean.class.getName(), InstallationListener.class.getName() }, new InstallerMBeanImpl(osgiControllerService), mbeanProps);
    registrations.add(mbeanReg);
}
Also used : InstallerMBean(org.apache.sling.installer.api.jmx.InstallerMBean) InstallationListener(org.apache.sling.installer.api.event.InstallationListener) Hashtable(java.util.Hashtable) ObjectName(javax.management.ObjectName) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 99 with ServiceRegistration

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

the class Activator method stop.

/**
     * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
     */
public void stop(final BundleContext context) {
    // stop osgi installer service
    if (this.osgiControllerService != null) {
        this.osgiControllerService.deactivate();
        this.osgiControllerService = null;
    }
    if (this.osgiControllerServiceReg != null) {
        this.osgiControllerServiceReg.unregister();
        this.osgiControllerServiceReg = null;
    }
    // unregister services
    for (final ServiceRegistration reg : this.registrations) {
        reg.unregister();
    }
    this.registrations.clear();
    // stop services
    for (final InternalService service : this.services) {
        service.deactivate();
    }
    this.services.clear();
}
Also used : ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 100 with ServiceRegistration

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

the class DistributionEventDistributeDistributionTrigger method register.

public void register(@Nonnull DistributionRequestHandler requestHandler) throws DistributionException {
    // register an event handler on distribution package install (on a certain path) which triggers the chain distribution of that same package
    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    // TODO : make it possible to configure the type of event handled here, currently 'package-installed' is hardcoded
    properties.put(EventConstants.EVENT_TOPIC, DistributionEventTopics.AGENT_PACKAGE_DISTRIBUTED);
    log.info("handler {} will chain distribute on path '{}'", requestHandler, pathPrefix);
    if (bundleContext != null) {
        ServiceRegistration triggerPathEventRegistration = bundleContext.registerService(EventHandler.class.getName(), new TriggerAgentEventListener(requestHandler, pathPrefix), properties);
        if (triggerPathEventRegistration != null) {
            registrations.put(requestHandler.toString(), triggerPathEventRegistration);
        }
    } else {
        throw new DistributionException("cannot register trigger since bundle context is null");
    }
}
Also used : Hashtable(java.util.Hashtable) EventHandler(org.osgi.service.event.EventHandler) DistributionException(org.apache.sling.distribution.common.DistributionException) 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