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


Java ServiceReference类代码示例

本文整理汇总了Java中org.osgi.framework.ServiceReference的典型用法代码示例。如果您正苦于以下问题:Java ServiceReference类的具体用法?Java ServiceReference怎么用?Java ServiceReference使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ServiceReference类属于org.osgi.framework包,在下文中一共展示了ServiceReference类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ProxyValueSource

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
public ProxyValueSource ( final BundleContext context, final String id, final ProxyHistoricalItem item, final int priority ) throws InvalidSyntaxException
{

    this.item = item;
    this.priority = priority;

    this.listener = new SingleServiceListener<HistoricalItem> () {

        @Override
        public void serviceChange ( final ServiceReference<HistoricalItem> reference, final HistoricalItem service )
        {
            setService ( service );
        }
    };

    this.tracker = new SingleServiceTracker<HistoricalItem> ( context, FilterUtil.createClassAndPidFilter ( HistoricalItem.class.getName (), id ), this.listener );
    this.tracker.open ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:19,代码来源:ProxyValueSource.java

示例2: setUp

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
protected void setUp() throws Exception {
	BundleContext bundleContext = new MockBundleContext() {
		// service reference already registered
		public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
			return new ServiceReference[] { new MockServiceReference(new String[] { Serializable.class.getName() }) };
		}
	};

	appContext = new GenericApplicationContext();
	appContext.getBeanFactory().addBeanPostProcessor(new BundleContextAwareProcessor(bundleContext));
	appContext.setClassLoader(getClass().getClassLoader());

	XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(appContext);
	reader.loadBeanDefinitions(new ClassPathResource("osgiDefaults.xml", getClass()));
	appContext.refresh();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:17,代码来源:OsgiDefaultsTests.java

示例3: start

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
@Override
public void start ( final BundleContext bundleContext ) throws Exception
{
    Activator.context = bundleContext;

    this.tracker = new SingleServiceTracker<Service> ( context, Service.class, new SingleServiceListener<Service> () {

        @Override
        public void serviceChange ( final ServiceReference<Service> reference, final Service service )
        {
            handleServiceChange ( service );
        }

    } );
    this.tracker.open ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:Activator.java

示例4: setUp

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
protected void setUp() throws Exception {
	services = new LinkedHashMap();

	BundleContext ctx = new MockBundleContext() {

		public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
			return new ServiceReference[0];
		}

		public Object getService(ServiceReference reference) {
			Object service = services.get(reference);
			return (service == null ? new Object() : service);
		}

	};

	ClassLoader cl = getClass().getClassLoader();
	proxyCreator =
			new StaticServiceProxyCreator(new Class<?>[] { Cloneable.class }, cl, cl, ctx,
					ImportContextClassLoaderEnum.UNMANAGED, false, false);
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:OsgiServiceCollectionProxiesTest.java

示例5: removedService

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
@Override
public void removedService ( final ServiceReference<HistoricalItem> reference, final HistoricalItem service )
{
    final String itemId = (String)reference.getProperty ( Constants.SERVICE_PID );

    synchronized ( this )
    {
        final HistoricalItem item = this.items.remove ( itemId );
        if ( item != null )
        {
            this.context.ungetService ( reference );
            this.itemInformations.remove ( item.getInformation () );
            fireListChanged ( null, new HashSet<String> ( Arrays.asList ( itemId ) ), false );
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:ServiceImpl.java

示例6: addOrReplaceBlock

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
protected void addOrReplaceBlock ( final ServiceReference<?> reference, final BlockConfiguration block )
{
    logger.info ( String.format ( "Adding or replace block - ref: %s, block: %s", new Object[] { reference, block } ) );

    final String oldBlock = this.blocks.put ( reference, block.getId () );

    if ( oldBlock != null )
    {
        logger.info ( "Replacing exisiting block" );
        this.device.removeBlock ( oldBlock );
    }

    final AbstractRequestBlock deviceBlock = makeBlock ( block );
    try
    {
        this.device.addBlock ( block.getId (), deviceBlock );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to add block", e );
        deviceBlock.dispose ();
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:24,代码来源:DaveBlockConfigurator.java

示例7: update

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
/**
 * Gather all ConnectionInformation objects and set them as connections
 */
private void update ()
{
    final Set<ConnectionDescriptor> infos = new HashSet<ConnectionDescriptor> ();
    for ( final ServiceReference<?> ref : this.references )
    {
        final ConnectionInformation ci = fromReference ( ref );
        if ( ci != null )
        {
            final Object o = ref.getProperty ( Constants.SERVICE_PID );
            final String id = o != null ? o.toString () : null;
            final Object description = ref.getProperty ( Constants.SERVICE_DESCRIPTION );
            final ConnectionDescriptor cd = new ConnectionDescriptor ( ci, id, description == null ? null : description.toString () );
            infos.add ( cd );
        }
    }
    setConnections ( infos );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:21,代码来源:ServiceDiscoverer.java

示例8: callListenersUnbind

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
public static void callListenersUnbind(Object serviceProxy, ServiceReference reference,
		OsgiServiceLifecycleListener[] listeners) {
	if (!ObjectUtils.isEmpty(listeners)) {
		boolean debug = log.isDebugEnabled();
		// get a Dictionary implementing a Map
		Dictionary properties =
				(reference != null ? OsgiServiceReferenceUtils.getServicePropertiesSnapshot(reference) : null);
		for (int i = 0; i < listeners.length; i++) {
			if (debug)
				log.debug("Calling unbind on " + listeners[i] + " w/ reference " + reference);
			try {
				listeners[i].unbind(serviceProxy, (Map) properties);
			} catch (Exception ex) {
				log.warn("Unbind method on listener " + listeners[i] + " threw exception ", ex);
			}
			if (debug)
				log.debug("Called unbind on " + listeners[i] + " w/ reference " + reference);
		}
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:21,代码来源:OsgiServiceBindingUtils.java

示例9: getConfiguration

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
@Override
public Configuration getConfiguration ()
{
    final List<ConfigurationGroup> groups = new LinkedList<ConfigurationGroup> ();

    Long lastRanking = null;
    ConfigurationGroupImpl lastGroup = null;

    for ( final Map.Entry<ServiceReference<AuthenticationService>, AuthenticationService> entry : this.tracker.getTracked ().entrySet () )
    {
        final Object o = entry.getKey ().getProperty ( Constants.SERVICE_RANKING );
        final long ranking = o instanceof Number ? ( (Number)o ).longValue () : 0;

        if ( lastRanking == null || lastRanking != ranking )
        {
            lastGroup = new ConfigurationGroupImpl ();
            groups.add ( lastGroup );
            lastRanking = ranking;
        }

        lastGroup.add ( entry.getValue () );
    }

    return new ConfigurationImpl ( groups );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:26,代码来源:ConfigurationManagerImpl.java

示例10: start

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.scheduler = Executors.newSingleThreadScheduledExecutor ( new NamedThreadFactory ( context.getBundle ().getSymbolicName () ) );
    final String driver = DataSourceHelper.getDriver ( DS_PREFIX, DataSourceHelper.DEFAULT_PREFIX );

    if ( driver == null )
    {
        logger.error ( "JDBC driver is not set" );
        throw new IllegalStateException ( "JDBC driver name is not set" );
    }

    this.dataSourceFactoryTracker = new DataSourceFactoryTracker ( context, driver, new SingleServiceListener<DataSourceFactory> () {

        @Override
        public void serviceChange ( final ServiceReference<DataSourceFactory> reference, final DataSourceFactory service )
        {
            unregister ();
            if ( service != null )
            {
                register ( service, context );
            }
        }
    } );
    this.dataSourceFactoryTracker.open ( true );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:27,代码来源:Activator.java

示例11: unexportService

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
@Override
protected void unexportService ( final ServiceReference<?> serviceReference )
{
    final Endpoint e;
    synchronized ( this )
    {
        e = this.endpoints.remove ( serviceReference );
    }

    if ( e != null )
    {
        if ( e.isPublished () )
        {
            try
            {
                e.stop ();
            }
            catch ( final Exception ex )
            {
                logger.warn ( "Failed to stop export", ex );
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:25,代码来源:EndpointExporter.java

示例12: initializeServiceRunnerInvocationMethods

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
/**
 * Determines through reflection the methods used for invoking the TestRunnerService.
 *
 * @throws Exception
 */
private void initializeServiceRunnerInvocationMethods() throws Exception {
    // get JUnit test service reference
    // this is a loose reference - update it if the JUnitTestActivator class is changed.

    BundleContext ctx = getRuntimeBundleContext();

    ServiceReference reference = ctx.getServiceReference(ACTIVATOR_REFERENCE);
    Assert.notNull(reference, "no OSGi service reference found at " + ACTIVATOR_REFERENCE);

    service = ctx.getService(reference);
    Assert.notNull(service, "no service found for reference: " + reference);

    serviceTrigger = service.getClass().getDeclaredMethod("executeTest", new Class[0]);
    ReflectionUtils.makeAccessible(serviceTrigger);
    Assert.notNull(serviceTrigger, "no executeTest() method found on: " + service.getClass());
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:22,代码来源:AbstractOsgiTests.java

示例13: init

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
public void init () throws InvalidSyntaxException
{
    final String filter = String.format ( "(%s=%s)", JaxWsExporter.EXPORT_ENABLED, true );
    synchronized ( this )
    {
        this.context.addServiceListener ( this, filter );
        final ServiceReference<?>[] refs = this.context.getServiceReferences ( (String)null, filter );
        if ( refs != null )
        {
            for ( final ServiceReference<?> ref : refs )
            {
                addService ( ref );
            }
        }
    }
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:17,代码来源:AbstractExporter.java

示例14: testInvocationWhenServiceNA

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
public void testInvocationWhenServiceNA() throws Throwable {
	// service n/a
	ServiceReference reference = new MockServiceReference() {
		public Bundle getBundle() {
			return null;
		}
	};

	interceptor = new ServiceStaticInterceptor(new MockBundleContext(), reference);

	Object target = new Object();
	Method m = target.getClass().getDeclaredMethod("hashCode", null);

	MethodInvocation invocation = new MockMethodInvocation(m);
	try {
		interceptor.invoke(invocation);
		fail("should have thrown exception");
	}
	catch (ServiceUnavailableException ex) {
		// expected
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:23,代码来源:OsgiServiceStaticInterceptorTest.java

示例15: setUp

import org.osgi.framework.ServiceReference; //导入依赖的package包/类
protected void setUp() throws Exception {
	services = new LinkedHashMap();

	context = new MockBundleContext() {

		public ServiceReference[] getServiceReferences(String clazz, String filter) throws InvalidSyntaxException {
			return new ServiceReference[0];
		}

		public Object getService(ServiceReference reference) {
			Object service = services.get(reference);
			return (service == null ? new Object() : service);
		}
	};

	col = createCollection();
	col.setRequiredAtStartup(false);
	col.afterPropertiesSet();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:20,代码来源:AbstractOsgiCollectionTest.java


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