当前位置: 首页>>代码示例>>Java>>正文


Java ServiceRegistration类代码示例

本文整理汇总了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"));
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:23,代码来源:OsgiServiceFactoryBeanTest.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:ConnectionManager.java

示例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;
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:24,代码来源:ConnectionLoginHandler.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:18,代码来源:Activator.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:FactoryImpl.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:22,代码来源:ProxyEventQueryFactory.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:JdbcAuthenticationServiceFactory.java

示例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 ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:AbstractServiceFactory.java

示例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 );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:BeanConfigurationFactory.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:ServiceRegistrationWrapperTest.java

示例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();
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:17,代码来源:OsgiRegistrationUtilTest.java

示例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;
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:26,代码来源:ListListenerAdapterTest.java

示例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);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:12,代码来源:CMUtils.java

示例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);
    }
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:18,代码来源:BeanToOsgiServiceManager.java

示例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);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:32,代码来源:OsgiBundleScope.java


注:本文中的org.osgi.framework.ServiceRegistration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。