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


Java BundleContext.addServiceListener方法代码示例

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


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

示例1: start

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.context = context;
    addService ( context.getServiceReference ( HttpService.class ) );
    context.addServiceListener ( this, String.format ( "(%s=%s)", Constants.OBJECTCLASS, HttpService.class.getName () ) );
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:8,代码来源:Activator.java

示例2: registerListener

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
private static void registerListener(BundleContext context, ServiceListener listener, String filter) {
	Assert.notNull(context);
	Assert.notNull(listener);

	try {
		// add listener
		context.addServiceListener(listener, filter);
	}
	catch (InvalidSyntaxException isex) {
		throw (RuntimeException) new IllegalArgumentException("Invalid filter").initCause(isex);
	}
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:13,代码来源:OsgiListenerUtils.java

示例3: start

import org.osgi.framework.BundleContext; //导入方法依赖的package包/类
@Override
public void start ( final BundleContext context ) throws Exception
{
    this.executor = new ExportedExecutorService ( "org.eclipse.scada.da.server.osgi", 1, 1, 1, TimeUnit.MINUTES );

    this.service = new HiveImpl ( context, this.executor );
    this.service.start ();

    final Dictionary<String, Object> properties = new Hashtable<String, Object> ();

    properties.put ( Constants.SERVICE_VENDOR, "Eclipse SCADA Project" );
    properties.put ( Constants.SERVICE_DESCRIPTION, "A common generic OSGi DA Hive" );
    properties.put ( "hive.id", this.service.getHiveId () );

    this.handle = context.registerService ( Hive.class, this.service, properties );

    context.addServiceListener ( this.listener = new ServiceListener () {

        @Override
        public void serviceChanged ( final ServiceEvent event )
        {
            switch ( event.getType () )
            {
                case ServiceEvent.REGISTERED:
                    Activator.this.addItem ( event.getServiceReference () );
                    break;
                case ServiceEvent.UNREGISTERING:
                    Activator.this.removeItem ( event.getServiceReference () );
                    break;
            }
        }
    }, "(" + Constants.OBJECTCLASS + "=" + DataItem.class.getName () + ")" );

    final Collection<ServiceReference<DataItem>> refs = context.getServiceReferences ( DataItem.class, null );
    if ( refs != null )
    {
        for ( final ServiceReference<DataItem> ref : refs )
        {
            addItem ( ref );
        }
    }

    this.poolTracker = new ObjectPoolTracker<DataItem> ( context, DataItem.class );
    this.poolTracker.open ();

    this.itemTracker = new AllObjectPoolServiceTracker<DataItem> ( this.poolTracker, new ObjectPoolListener<DataItem> () {

        @Override
        public void serviceRemoved ( final DataItem service, final Dictionary<?, ?> properties )
        {
            Activator.this.service.removeItem ( service );
        }

        @Override
        public void serviceModified ( final DataItem service, final Dictionary<?, ?> properties )
        {
        }

        @Override
        public void serviceAdded ( final DataItem service, final Dictionary<?, ?> properties )
        {
            Activator.this.service.addItem ( service, properties );
        }
    } );
    this.itemTracker.open ();
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:67,代码来源:Activator.java


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