當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。