本文整理汇总了Java中org.osgi.service.cm.ManagedService类的典型用法代码示例。如果您正苦于以下问题:Java ManagedService类的具体用法?Java ManagedService怎么用?Java ManagedService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ManagedService类属于org.osgi.service.cm包,在下文中一共展示了ManagedService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRegistersManagedEMF
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Test
public void testRegistersManagedEMF() throws InvalidSyntaxException, ConfigurationException {
AriesEntityManagerFactoryBuilder emfb = new AriesEntityManagerFactoryBuilder(
containerContext, provider, providerBundle, punit);
verify(containerContext).registerService(eq(ManagedService.class),
any(ManagedService.class), argThat(servicePropsMatcher(
SERVICE_PID, "org.apache.aries.jpa.test-props")));
// No EMF created as incomplete
verifyZeroInteractions(msReg, provider);
emfb.close();
verify(msReg).unregister();
}
示例2: registerManagedService
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
public static ServiceRegistration registerManagedService(BundleContext bundleContext, ManagedService listener,
String pid) {
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_PID, pid);
Bundle bundle = bundleContext.getBundle();
props.put(Constants.BUNDLE_SYMBOLICNAME, OsgiStringUtils.nullSafeSymbolicName(bundle));
props.put(Constants.BUNDLE_VERSION, OsgiBundleUtils.getBundleVersion(bundle));
return bundleContext.registerService(ManagedService.class.getName(), listener, props);
}
示例3: init
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Override
public void init(BundleContext bc, DependencyManager manager) throws Exception {
Properties properties = new Properties();
properties.setProperty(Constants.SERVICE_PID, PID);
manager.add(createComponent()
.setInterface(new String[]{
DeviceDriverManager.class.getName(),
ManagedService.class.getName()},
properties)
.setImplementation(DriverManagerImpl.class)
.add(createServiceDependency()
.setService(DirectoryService.class)
.setRequired(true))
.add(createConfigurationDependency().setPid(PID)));
}
示例4: start
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
/**
* Called when this bundle is started by OSGi Framework.
* Determines underlying platform and loads the relevant service
* which implements <code>GPIO</code> interface.
*/
public void start(BundleContext context) throws Exception {
/* Linux user space GPIO implementation, "sysfs" based */
if (System.getProperty("os.name").toLowerCase().startsWith("linux")) {
GPIOLinux gpioLinux = new GPIOLinux();
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put("service.pid", "org.openhab.gpio");
context.registerService(GPIO.class, gpioLinux, null);
context.registerService(ManagedService.class, gpioLinux, properties);
} else {
/* Throwing exception is not implemented because it's causing Equinox to constantly trying to start the bundle */
logger.error("No supported operating system was found, GPIO service won't be available");
}
}
示例5: doActivate
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Activate
public void doActivate(ComponentContext ctx) {
log.info("Start");
context = ctx.getBundleContext();
context.addBundleListener(this);
context.addServiceListener(this);
// configuration
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put(Constants.SERVICE_PID, CONFIG_PID);
configUpdaterReg = context.registerService(ManagedService.class.getName(), new ConfigUpdater(this) , properties);
if (enabled) refreshAll();
}
示例6: PiService
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
/**
* PiService creator. Record itself as a managed service.
*
*/
public PiService() {
gpioController = GpioFactory.getInstance();
String[] clazzes = new String[] { ManagedService.class.getName() };
// register the class as a managed service.
Hashtable<String, Object> properties = new Hashtable<String,Object>();
properties.put(Constants.SERVICE_PID, this.getClass().getName());
Activator.bc.registerService(clazzes, this, properties);
Activator.log(LogService.LOG_INFO, "Registered "
+ this.getClass().getName() + ", Pid = "
+ (String) properties.get(Constants.SERVICE_PID));
}
示例7: start
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
/**
* Called when this bundle is started by OSGi Framework.
* Determines underlying platform and loads the relevant service
* which implements <code>GPIO</code> interface.
*/
public void start(BundleContext context) throws Exception {
/* Linux user space GPIO implementation, "sysfs" based */
if (System.getProperty("os.name").toLowerCase().startsWith("linux")) {
GPIOLinux gpioLinux = new GPIOLinux();
Dictionary<String, String> properties = new Hashtable<String, String>();
properties.put("service.pid", "org.openhab.gpio");
context.registerService(GPIO.class, gpioLinux, null);
context.registerService(ManagedService.class, gpioLinux, properties);
} else {
/*
* Throwing exception is not implemented because it's causing Equinox to constantly trying to start the
* bundle
*/
logger.error("No supported operating system was found, GPIO service won't be available");
}
}
示例8: registerManagedService
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
private void registerManagedService(BundleContext containerContext, PersistenceUnitInfo persistenceUnit) {
Dictionary<String, Object> configuration = new Hashtable<String, Object>(); // NOSONAR
configuration.put(Constants.SERVICE_PID, JPA_CONFIGURATION_PREFIX + persistenceUnit.getPersistenceUnitName());
configReg = containerContext.registerService(ManagedService.class,
new ManagedEMF(this, persistenceUnit.getPersistenceUnitName()), configuration);
}
示例9: setup
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {
when(punit.getPersistenceUnitName()).thenReturn("test-props");
when(punit.getPersistenceProviderClassName())
.thenReturn(ECLIPSE_PERSISTENCE_PROVIDER);
when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA);
when(punit.getBundle()).thenReturn(punitBundle);
when(punit.getProperties()).thenReturn(punitProperties);
when(punitBundle.getBundleContext()).thenReturn(punitContext);
when(punitBundle.getVersion()).thenReturn(Version.parseVersion("1.2.3"));
when(containerContext.registerService(eq(ManagedService.class),
any(ManagedService.class), any(Dictionary.class))).thenReturn(msReg);
when(containerContext.getService(dsfRef)).thenReturn(dsf);
when(containerContext.getService(dsRef)).thenReturn(ds);
when(containerContext.createFilter(Mockito.anyString()))
.thenAnswer(new Answer<Filter>() {
@Override
public Filter answer(InvocationOnMock i) throws Throwable {
return FrameworkUtil.createFilter(i.getArguments()[0].toString());
}
});
when(punitContext.registerService(eq(EntityManagerFactory.class), any(EntityManagerFactory.class),
any(Dictionary.class))).thenReturn(emfReg);
when(emf.isOpen()).thenReturn(true);
Properties jdbcProps = new Properties();
jdbcProps.setProperty("url", JDBC_URL);
jdbcProps.setProperty("user", JDBC_USER);
jdbcProps.setProperty("password", JDBC_PASSWORD);
when(dsf.createDataSource(jdbcProps)).thenReturn(ds);
}
示例10: start
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
bundleContext = context;
scheduled.set(true);
Hashtable<String, Object> props = new Hashtable<>();
props.put(Constants.SERVICE_PID, getPid());
managedServiceRegistration = bundleContext.registerService(ManagedService.class, this::updated, props);
scheduled.set(false);
reconfigure();
}
示例11: setUp
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
protected void setUp() throws Exception {
adminControl = createControl();
admin = adminControl.createMock(ConfigurationAdmin.class);
cfg = createMock(Configuration.class);
config = new Hashtable<String, Object>();
expect(admin.getConfiguration(persistentId)).andReturn(cfg).atLeastOnce();
expect(cfg.getProperties()).andReturn(config).atLeastOnce();
adminControl.replay();
replay(cfg);
bundleContext = new MockBundleContext() {
// add Configuration admin support
@Override
public Object getService(ServiceReference reference) {
return admin;
}
// ManagedService registration
@Override
public ServiceRegistration registerService(String clazz, Object service, Dictionary properties) {
// save the callback
if (ManagedService.class.getName().equals(clazz)) {
msCallback = (ManagedService) service;
}
return super.registerService(clazz, service, properties);
}
};
appContext = new GenericApplicationContext();
appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
// reader.setEventListener(this.listener);
reader.loadBeanDefinitions(new ClassPathResource("configProperties.xml", getClass()));
appContext.refresh();
}
示例12: registerManagedService
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
private void registerManagedService(final String persistentId) {
// Register a ManagedService so we get updates from the ConfigAdmin when the cfg file corresponding
// to the persistentId changes.
final ManagedService managedService = new ManagedService() {
private volatile boolean initialUpdate = true;
@Override
public void updated(final Dictionary<String, ?> properties) {
LOG.debug("{}: ManagedService updated for persistentId {}, properties: {}, initialUpdate: {}",
logName(), persistentId, properties, initialUpdate);
// The first update occurs when the service is registered so ignore it as we want subsequent
// updates when it changes. The ConfigAdmin will send an update even if the cfg file doesn't
// yet exist.
if (initialUpdate) {
initialUpdate = false;
} else {
blueprintContainerRestartService.restartContainerAndDependents(bundle);
}
}
};
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.SERVICE_PID, persistentId);
props.put(Constants.BUNDLE_SYMBOLICNAME, bundle.getSymbolicName());
props.put(Constants.BUNDLE_VERSION, bundle.getHeaders().get(Constants.BUNDLE_VERSION));
managedServiceRegs.add(bundle.getBundleContext().registerService(ManagedService.class.getName(),
managedService, props));
}
示例13: start
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
public synchronized void start(BundleContext bc) throws Exception {
zkd = new ZooKeeperDiscovery(bc);
bc.registerService(ManagedService.class, zkd, configProperties(PID_DISCOVERY_ZOOKEEPER));
zkStarter = new ZookeeperStarter(bc);
bc.registerService(ManagedService.class, zkStarter, configProperties(PID_ZOOKEEPER_SERVER));
}
示例14: init
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Override
public void init(BundleContext bc, DependencyManager manager)
throws Exception {
Properties properties = new Properties();
properties.setProperty(Constants.SERVICE_PID, PID);
manager.add(createComponent()
.setInterface(new String[]{
DirectoryService.class.getName(),
ManagedService.class.getName()
}, properties)
.setImplementation(DirectoryServiceImpl.class)
.add(createConfigurationDependency().setPid(PID)));
}
示例15: start
import org.osgi.service.cm.ManagedService; //导入依赖的package包/类
@Override
public void start(BundleContext context) {
handler = new GenericControllerHandler<ExperimentsController>(context, ExperimentsController.class.getName());
String pid = "com.recalot.views.experiments";
Dictionary config = new Hashtable();
config.put(pid + ".path", new String("/experiments"));
service = new WebService(pid, context, new Servlet(handler), config);
context.registerService(ManagedService.class.getName(), service, config);
service.initialize();
}