本文整理匯總了Java中org.osgi.framework.ServiceRegistration類的典型用法代碼示例。如果您正苦於以下問題:Java ServiceRegistration類的具體用法?Java ServiceRegistration怎麽用?Java ServiceRegistration使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServiceRegistration類屬於org.osgi.framework包,在下文中一共展示了ServiceRegistration類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testUpdateableProperties
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
public void testUpdateableProperties() throws Exception {
UpdateableProperties properties = new UpdateableProperties();
properties.setProperty("steve", "vai");
exporter.setServiceProperties(properties);
exporter.setTarget("string");
exporter.setBeanName("string");
exporter.setInterfaces(new Class<?>[]{Serializable.class});
beanFactoryControl.replay();
exporter.afterPropertiesSet();
ServiceRegistration reg = exporter.getObject();
assertEquals("vai", reg.getReference().getProperty("steve"));
assertNull(reg.getReference().getProperty("updated"));
properties.setProperty("steve", "jobs");
properties.setProperty("updated", "true");
properties.update();
assertEquals("jobs", reg.getReference().getProperty("steve"));
assertNotNull(reg.getReference().getProperty("updated"));
}
示例2: registerConnection
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
/**
* Register the current connection as an OSGi service
*/
private EntryImpl registerConnection ( final ConnectionDescriptor connectionDescriptor, final ConnectionService connectionService )
{
final Class<?>[] interfaces = connectionService.getSupportedInterfaces ();
final String[] clazzes = new String[interfaces.length];
int i = 0;
for ( final Class<?> iface : interfaces )
{
clazzes[i] = iface.getName ();
i++;
}
final Dictionary<String, String> properties = new Hashtable<String, String> ();
properties.put ( ConnectionService.CONNECTION_URI, connectionDescriptor.getConnectionInformation ().toString () );
if ( connectionDescriptor.getServiceId () != null )
{
properties.put ( Constants.SERVICE_PID, connectionDescriptor.getServiceId () );
}
final ServiceRegistration<?> serviceRegistration = this.context.registerService ( clazzes, connectionService, properties );
return new EntryImpl ( connectionDescriptor, connectionService, serviceRegistration );
}
示例3: dispose
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
public synchronized void dispose ()
{
if ( this.registrations != null )
{
for ( final ServiceRegistration<?> reg : this.registrations )
{
reg.unregister ();
}
this.registrations = null;
}
if ( this.connectionService != null )
{
if ( this.connectionStateListener != null )
{
this.connectionService.getConnection ().removeConnectionStateListener ( this.connectionStateListener );
}
this.connectionService.dispose ();
this.connectionService = null;
}
}
示例4: registerService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
private void registerService ( final String id, final String uri, final ConnectionService service )
{
final Dictionary<String, Object> properties = new Hashtable<String, Object> ();
properties.put ( Constants.SERVICE_PID, id );
properties.put ( ConnectionService.CONNECTION_URI, uri );
final Class<?>[] clazzes = service.getSupportedInterfaces ();
final String[] clazzStr = new String[clazzes.length];
for ( int i = 0; i < clazzes.length; i++ )
{
clazzStr[i] = clazzes[i].getName ();
}
final ServiceRegistration<?> handle = getBundle ().getBundleContext ().registerService ( clazzStr, service, properties );
this.registrations.add ( handle );
}
示例5: createService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
protected Entry<ComponentFactory> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception
{
final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters );
final String xml = cfg.getStringNonEmpty ( "configuration" );
final XMIResource xmi = new XMIResourceImpl ();
final Map<?, ?> options = new HashMap<Object, Object> ();
final InputSource is = new InputSource ( new StringReader ( xml ) );
xmi.load ( is, options );
final Object c = EcoreUtil.getObjectByType ( xmi.getContents (), ParserPackage.Literals.COMPONENT );
if ( ! ( c instanceof Component ) )
{
throw new RuntimeException ( String.format ( "Configuration did not contain an object of type %s", Component.class.getName () ) );
}
final ComponentFactoryWrapper wrapper = new ComponentFactoryWrapper ( this.executor, (Component)c );
final Dictionary<String, ?> properties = new Hashtable<> ();
final ServiceRegistration<ComponentFactory> handle = context.registerService ( ComponentFactory.class, wrapper, properties );
return new Entry<ComponentFactory> ( configurationId, wrapper, handle );
}
示例6: createService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
protected Entry<ProxyEventQuery> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception
{
logger.info ( "Creating new proxy query: {}", configurationId );
final ConfigurationDataHelper cfg = new ConfigurationDataHelper ( parameters );
final int poolSize = cfg.getIntegerChecked ( "poolSize", "'poolSize' must be set" );
if ( poolSize <= 0 )
{
throw new IllegalArgumentException ( "'poolSize' must be a positive integer greater zero" );
}
final ProxyEventQuery service = new ProxyEventQuery ( context, this.executor, poolSize, parameters );
final Hashtable<String, Object> properties = new Hashtable<String, Object> ();
properties.put ( Constants.SERVICE_PID, configurationId );
final ServiceRegistration<EventQuery> handle = context.registerService ( EventQuery.class, service, properties );
return new Entry<ProxyEventQuery> ( configurationId, service, handle );
}
示例7: createService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
protected Entry<JdbcAuthenticationService> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception
{
logger.debug ( "Creating new service: {}", configurationId );
final JdbcAuthenticationService service = new JdbcAuthenticationService ( context, configurationId );
service.update ( parameters );
final Dictionary<String, Object> properties = new Hashtable<String, Object> ();
properties.put ( Constants.SERVICE_DESCRIPTION, "JDBC based authenticator" );
properties.put ( Constants.SERVICE_PID, configurationId );
properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
final ServiceRegistration<?> handle;
if ( service.isUserManager () )
{
handle = context.registerService ( new String[] { AuthenticationService.class.getName () }, service, properties );
}
else
{
handle = context.registerService ( new String[] { AuthenticationService.class.getName (), UserManagerService.class.getName () }, service, properties );
}
return new Entry<JdbcAuthenticationService> ( configurationId, service, handle );
}
示例8: delete
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
public synchronized void delete ( final UserInformation information, final String configurationId ) throws Exception
{
final ServiceRegistration<?> reg = this.regs.remove ( configurationId );
if ( reg != null )
{
reg.unregister ();
}
final Service service = this.instances.remove ( configurationId );
if ( service != null )
{
service.dispose ();
}
}
示例9: createService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Override
protected Entry<BeanServiceInstance> createService ( final UserInformation userInformation, final String configurationId, final BundleContext context, final Map<String, String> parameters ) throws Exception
{
final BeanServiceInstance bean = new BeanServiceInstance ( this.beanClazz.newInstance () );
if ( this.mergeIdField )
{
parameters.put ( "id", configurationId );
}
bean.update ( parameters );
final ServiceRegistration<?> reg = context.registerService ( this.beanClazz.getName (), bean.getTargetBean (), bean.getProperties () );
return new Entry<BeanServiceInstance> ( configurationId, bean, reg );
}
示例10: setUp
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
protected void setUp() throws Exception {
actualRegistration = createMock(ServiceRegistration.class);
final ListenerNotifier notifier =
new ListenerNotifier(
new OsgiServiceRegistrationListener[] { new SimpleOsgiServiceRegistrationListener() });
ServiceRegistrationDecorator registrationDecorator = new ServiceRegistrationDecorator(actualRegistration);
registrationDecorator.setNotifier(new UnregistrationNotifier() {
public void unregister(Map properties) {
notifier.callUnregister(null, properties);
}
});
registration = registrationDecorator;
SimpleOsgiServiceRegistrationListener.REGISTERED = 0;
SimpleOsgiServiceRegistrationListener.UNREGISTERED = 0;
}
示例11: testRegisterService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@Test
public void testRegisterService() throws Exception {
final BundleContext bundleContext = mock(BundleContext.class);
ServiceRegistration<?> registration = mockServiceRegistration();
doReturn(registration).when(bundleContext).registerService(String.class, "string", null);
ServiceRegistration<?> registration2 = mockServiceRegistration();
doReturn(registration2).when(bundleContext).registerService(Object.class, "string", null);
AutoCloseable aggregatedRegister = OsgiRegistrationUtil.registerService(bundleContext, "string", String.class,
Object.class);
aggregatedRegister.close();
InOrder inOrder = Mockito.inOrder(registration, registration2);
inOrder.verify(registration2).unregister();
inOrder.verify(registration).unregister();
}
示例12: registerService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
@SuppressWarnings("rawtypes")
public ServiceRegistration registerService(String[] clazzes, final Object service, Dictionary properties) {
MockServiceRegistration reg = new MockServiceRegistration(properties);
MockServiceReference ref = new MockServiceReference(getBundle(), properties, reg, clazzes) {
@Override
public Object getProperty(String key) {
if (SERVICE_PROPERTY.equals(key)) {
return service;
} else {
return super.getProperty(key);
}
}
};
ServiceEvent event = new ServiceEvent(ServiceEvent.REGISTERED, ref);
for (Iterator iter = serviceListeners.iterator(); iter.hasNext();) {
ServiceListener listener = (ServiceListener) iter.next();
listener.serviceChanged(event);
}
return reg;
}
示例13: registerManagedService
import org.osgi.framework.ServiceRegistration; //導入依賴的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);
}
示例14: updateRegistrations
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
public synchronized void updateRegistrations(
final Map<ServiceInterfaceAnnotation, String /* service ref name */> newAnnotationMapping,
final BundleContext bundleContext, final AutoCloseable newInstance) {
boolean notEquals = !this.instance.equals(newInstance);
notEquals |= !newAnnotationMapping.equals(serviceNamesToAnnotations);
if (notEquals) {
// FIXME: changing from old state to new state can be improved by computing the
// diff
LOG.debug("Detected change in service registrations for {}: old: {}, new: {}", moduleIdentifier,
serviceNamesToAnnotations, newAnnotationMapping);
close();
this.instance = newInstance;
Set<ServiceRegistration<?>> newRegs = registerToSR(instance, bundleContext, newAnnotationMapping);
serviceRegistrations.clear();
serviceRegistrations.addAll(newRegs);
}
}
示例15: getService
import org.osgi.framework.ServiceRegistration; //導入依賴的package包/類
/**
* Called if a bundle requests a service for the first time (start the
* scope).
*
* @see org.osgi.framework.ServiceFactory#getService(org.osgi.framework.Bundle,
* org.osgi.framework.ServiceRegistration)
*/
public Object getService(Bundle bundle, ServiceRegistration registration) {
try {
// tell the scope, it's an outside bundle that does the call
EXTERNAL_BUNDLE.set(Boolean.TRUE);
// create the new object (call the container)
Object obj = decoratedServiceFactory.getService(bundle, registration);
// get callback (registered through the scope)
Object passedObject = OsgiBundleScope.EXTERNAL_BUNDLE.get();
// make sure it's not the marker object
if (passedObject != null && passedObject instanceof Runnable) {
Runnable callback = (Runnable) OsgiBundleScope.EXTERNAL_BUNDLE.get();
if (callback != null)
callbacks.put(bundle, callback);
}
return obj;
}
finally {
// clean ThreadLocal
OsgiBundleScope.EXTERNAL_BUNDLE.set(null);
}
}