當前位置: 首頁>>代碼示例>>Java>>正文


Java BundleContext.getServiceReferences方法代碼示例

本文整理匯總了Java中org.osgi.framework.BundleContext.getServiceReferences方法的典型用法代碼示例。如果您正苦於以下問題:Java BundleContext.getServiceReferences方法的具體用法?Java BundleContext.getServiceReferences怎麽用?Java BundleContext.getServiceReferences使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.osgi.framework.BundleContext的用法示例。


在下文中一共展示了BundleContext.getServiceReferences方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getServices

import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
public static <E> List<E> getServices(BundleContext bundleContext, Class<E> serviceType, String filter)
        throws InvalidSyntaxException {
    List<E> services = null;
    final ServiceReference[] refs = bundleContext.getServiceReferences(serviceType.getName(), filter);
    if (refs != null) {
        services = new ArrayList<>(refs.length);
        if (refs != null && refs.length > 0) {
            for (ServiceReference ref : refs) {
                E service = (E) bundleContext.getService(ref);
                services.add(service);
            }
        }
    } else
        services = Collections.unmodifiableList(new ArrayList<E>());
    return services;
}
 
開發者ID:DantaFramework,項目名稱:Core,代碼行數:17,代碼來源:OSGiUtils.java

示例2: getGlobalInstances

import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
* Retrieves Global instances of Specific Service in the Bundle.  This is
* adapted from org.opendaylight.controller.sal.utils.ServiceHelper
*
* @param clazz - Class associated with the Class loader.
* @param bundle - Bundle
* @return an array of objects that implement the services specified by the clazz
*/
  public static Object[] getGlobalInstances(Class<?> clazz, Object bundle) {
      Object instances[] = null;
      try {
          BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
                  .getBundleContext();

          ServiceReference[] services = bCtx.getServiceReferences(clazz
                  .getName(), null);

          if (services != null) {
              instances = new Object[services.length];
              for (int i = 0; i < services.length; i++) {
                  instances[i] = bCtx.getService(services[i]);
              }
          }
      } catch (Exception e) {
          LOG.error("Instance reference is NULL");
      }
      return instances;
  }
 
開發者ID:opendaylight,項目名稱:fpc,代碼行數:29,代碼來源:FpcCodecUtils.java

示例3: getServiceReferences

import org.osgi.framework.BundleContext; //導入方法依賴的package包/類
/**
 * Returns references to <em>all</em> services matching the given class name and OSGi filter.
 * 
 * @param bundleContext OSGi bundle context
 * @param clazz fully qualified class name (can be <code>null</code>)
 * @param filter valid OSGi filter (can be <code>null</code>)
 * @return non-<code>null</code> array of references to matching services
 */
public static ServiceReference[] getServiceReferences(BundleContext bundleContext, String clazz, String filter) {
	Assert.notNull(bundleContext, "bundleContext should be not null");

	try {
		ServiceReference[] refs = bundleContext.getServiceReferences(clazz, filter);
		return (refs == null ? new ServiceReference[0] : refs);
	} catch (InvalidSyntaxException ise) {
		throw (RuntimeException) new IllegalArgumentException("invalid filter: " + ise.getFilter()).initCause(ise);
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:19,代碼來源:OsgiServiceReferenceUtils.java

示例4: 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.getServiceReferences方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。