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);
}
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));
}
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);
}
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();
}
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");
}
}
Aggregations