Java 类org.osgi.framework.FrameworkUtil 实例源码

项目:smarthome-cep-demonstrator    文件:RuleLoader.java   
@Override
public List<DrlConfiguration> getDrls() {

    List<DrlConfiguration> list = new LinkedList<DrlConfiguration>();

    Enumeration<URL> baseRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/base-rules", "*.drl", true);
    Enumeration<URL> genRules = FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/gen-rules", "*.drl", true);

    if(baseRules == null) {
        throw new RuntimeException("Error, base-rules folder shouldn't be empty.");
    }
    if(genRules == null) {
        throw new RuntimeException("Error, gen-rules folder shouldn't be empty. Have you forget to generate the rules?");
    }

    List<URL> loadedDrls = Collections.list(baseRules);
    loadedDrls.addAll(Collections.list(genRules));

    for (URL url : loadedDrls) {
        addInputStreamToList(url, list);
    }
    return list;
}
项目:smarthome-cep-demonstrator    文件:RuleLoader.java   
@Override
public List<DtableConfiguration> getDtables() {
    List<DtableConfiguration> dtableList = new LinkedList<DtableConfiguration>();

       List<URL> urls = Collections
               .list(FrameworkUtil.getBundle(getClass()).findEntries("/src/main/resources/dtables/", "*.xlsx", true));

       for (URL url : urls) {
           try {
            dtableList.add(new DtableConfiguration(url.openStream(), url.getFile()));
        } catch (IOException e) {
            e.printStackTrace();
        }
       }
    return dtableList;
}
项目:neoscada    文件:FilterUtil.java   
protected static Filter createFilter ( final String operand, final Filter... filters ) throws InvalidSyntaxException
{
    final StringBuilder sb = new StringBuilder ();

    sb.append ( "(" );
    sb.append ( operand );

    for ( final Filter filter : filters )
    {
        sb.append ( filter.toString () );
    }

    sb.append ( ")" );

    return FrameworkUtil.createFilter ( sb.toString () );
}
项目:neoscada    文件:MailEventHandler.java   
public MailEventHandler ( final String id, final MailSender sender, final PipeService pipeService, final int retries ) throws Exception
{
    this.bundle = FrameworkUtil.getBundle ( MailHandlerFactory.class );
    this.sender = sender;
    this.retries = retries;

    final String pipeName = "mail." + id;

    try
    {
        this.producer = pipeService.createProducer ( pipeName );
        this.workerHandle = pipeService.createWorker ( pipeName, this.mailWorker );
    }
    catch ( final Exception e )
    {
        if ( this.sender != null )
        {
            this.sender.dispose ();
            this.sender = null;
        }
    }
}
项目:scanning    文件:ViewUtil.java   
public static void openQueueMonitor(Class<? extends StatusBean> beanClass,
                                   final String queueName,
                                   final String topicName,
                                   final String submissionQueueName,
                                   String partName) throws PartInitException, UnsupportedEncodingException {

    String bundle = FrameworkUtil.getBundle(beanClass).getSymbolicName();
    String bean   = beanClass.getName();
    String sqn    = queueName;
    String stn    = topicName;
    String submit = submissionQueueName;

    String queueViewId = QueueViews.createSecondaryId(CommandConstants.getScanningBrokerUri(), bundle,bean, sqn, stn, submit);
    if (partName!=null) queueViewId = queueViewId+"partName="+partName;
    try {
        PageUtil.getPage().showView(QueueViews.getQueueViewID(), queueViewId, IWorkbenchPage.VIEW_ACTIVATE);
    } catch (PartInitException e) {
        ErrorDialog.openError(Display.getDefault().getActiveShell(), "Cannot open view", "Cannot open view "+queueViewId,
                new Status(Status.ERROR, "org.eclipse.scanning.event.ui", e.getMessage()));
        throw e;
    }
}
项目:osc-core    文件:InstallerIntegrationTest.java   
@Before
public void before() throws Exception {
    assertAllBundlesResolved();

    // Track ArtifactInstaller service ONLY from bundle org.osc.installer
    Bundle installerBundle = findBundle("osc-installer");
    Filter artifactInstallerTrackerFilter = FrameworkUtil.createFilter(String.format("(&(objectClass=%s)(service.bundleid=%d))", ArtifactInstaller.class.getName(), installerBundle.getBundleId()));
    this.artifactInstallerTracker = new ServiceTracker<>(this.bundleContext, artifactInstallerTrackerFilter, null);
    this.artifactInstallerTracker.open();

    // Wait up to 5 seconds for ArtifactInstaller to appear
    ArtifactInstaller artifactInstaller = this.artifactInstallerTracker.waitForService(5000);
    if (artifactInstaller == null) {
        fail("ArtifactInstaller service not available within 5 seconds");
    }

    this.fwkInstallerTracker = new ServiceTracker<>(this.bundleContext, FrameworkInstaller.class, null);
    this.fwkInstallerTracker.open();
}
项目:Hydrograph    文件:ApplicationWorkbenchWindowAdvisor.java   
@Override
  public void dispose() {
super.dispose();
BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
ServiceReference<IDebugService> serviceReference = (ServiceReference<IDebugService>) bundleContext.getServiceReference(IDebugService.class.getName());
if(serviceReference != null){
    IDebugService debugService = (IDebugService)bundleContext.getService(serviceReference);
    debugService.deleteDebugFiles();
}
Properties properties = ConfigFileReader.INSTANCE.getCommonConfigurations();
try {
    killPortProcess(properties);
} catch (IOException e) {
    logger.debug("Socket is not closed.");
}
  }
项目:fpc    文件:FpcCodecUtils.java   
/**
* 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;
  }
项目:com-liferay-apio-architect    文件:NestedCollectionRouterManagerImpl.java   
@Override
protected void emit(
    ServiceReference<NestedCollectionRouter> serviceReference,
    Emitter<String> emitter) {

    Bundle bundle = FrameworkUtil.getBundle(
        NestedCollectionRouterManagerImpl.class);

    BundleContext bundleContext = bundle.getBundleContext();

    CustomServiceReferenceMapper<NestedCollectionRouter>
        customServiceReferenceMapper = new CustomServiceReferenceMapper<>(
            bundleContext, NestedCollectionRouter.class);

    NestedCollectionRouter nestedCollectionRouter =
        bundleContext.getService(serviceReference);

    Class<?> genericClass = getGenericClassFromPropertyOrElse(
        serviceReference, PARENT_MODEL_CLASS,
        () -> getTypeParamOrFail(
            nestedCollectionRouter, NestedCollectionRouter.class, 1));

    customServiceReferenceMapper.map(
        serviceReference,
        key -> emitter.emit(key + "-" + genericClass.getName()));
}
项目:visuflow-plugin    文件:ServiceUtil.java   
/**
 * Looks up an OSGi service. If the service is not yet available, this method will wait for 60 seconds for the service to become available. If the service
 * does not appear in this period, a ServiceException is thrown.
 *
 * @param serviceClass
 *            The service interface of the service to look up
 * @param timeoutInMillis
 *            The amount of time in milliseconds to wait for the service to become available
 * @return an implementation of the given service interface
 * @throws a
 *             ServiceException, if the service couldn't be found in the OSGi service registry
 */
public static <T> T getService(Class<T> serviceClass, long timeoutInMillis) {
    BundleContext ctx = FrameworkUtil.getBundle(ServiceUtil.class).getBundleContext();
    ServiceTracker<T, T> tracker = new ServiceTracker<>(ctx, serviceClass, null);
    tracker.open();
    T service = null;
    try {
        service = tracker.waitForService(timeoutInMillis);
    } catch (InterruptedException e) {
        throw new ServiceException("Interrupted while waiting for the service " + serviceClass.getName(), e);
    }

    tracker.close();
    if (service != null) {
        return service;
    } else {
        throw new ServiceException("Service " + serviceClass.getName() + " not available");
    }
}
项目:cicomponents    文件:GithubEmittersCommand.java   
@Override public Object execute() throws Exception {
    BundleContext context = FrameworkUtil.getBundle(GithubEmittersCommand.class).getBundleContext();
    Collection<ServiceReference<GithubPullRequestEmitter>> references = context
            .getServiceReferences(GithubPullRequestEmitter.class, "(github-repository=*)");

    // Build the table
    ShellTable table = new ShellTable();

    table.column("Repository").alignLeft();
    table.column("Type").alignLeft();
    table.emptyTableText("No GitHub revision emitters available");

    for (ServiceReference<GithubPullRequestEmitter> reference : references) {
        GithubPullRequestEmitter service = context.getService(reference);
        String repository = (String) reference.getProperty("github-repository");
        String type = service instanceof PullRequestMonitor ? "pull requests" : "unknown";
        table.addRow().addContent(repository, type);
        context.ungetService(reference);
    }

    // Print it
    table.print(System.out);
    return null;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static List<Region> getRegions() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        List<Region> regions = regionLocalService.getRegions(
            0, getRegionsCount());

        return regions;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static int getRegionsCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        int regionsCount = regionLocalService.getRegionsCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static void useJNDI() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        regionLocalService.useJNDI();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static List<Country> getCountries() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        List<Country> countries = countryLocalService.getCountries(
            0, getCountriesCount());

        return countries;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static int getCountriesCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        int regionsCount = countryLocalService.getCountriesCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static void useJDBC() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        countryLocalService.useJDBC();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static List<Region> getRegions() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        List<Region> regions = regionLocalService.getRegions(
            0, getRegionsCount());

        return regions;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static int getRegionsCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        int regionsCount = regionLocalService.getRegionsCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static void useJNDI() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        regionLocalService.useJNDI();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static List<Country> getCountries() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        List<Country> countries = countryLocalService.getCountries(
            0, getCountriesCount());

        return countries;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static int getCountriesCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        int regionsCount = countryLocalService.getCountriesCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static void useJDBC() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        countryLocalService.useJDBC();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static List<Region> getRegions() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        List<Region> regions = regionLocalService.getRegions(
            0, getRegionsCount());

        return regions;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static int getRegionsCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        int regionsCount = regionLocalService.getRegionsCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJNDI.java   
public static void useJNDI() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJNDI.class).getBundleContext();

    ServiceTracker<RegionLocalService, RegionLocalService> tracker =
        new ServiceTracker<>(bundleContext, RegionLocalService.class, null);

    tracker.open();

    RegionLocalService regionLocalService = tracker.getService();

    try {
        regionLocalService.useJNDI();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static List<Country> getCountries() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        List<Country> countries = countryLocalService.getCountries(
            0, getCountriesCount());

        return countries;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return null;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static int getCountriesCount() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        int regionsCount = countryLocalService.getCountriesCount();

        return regionsCount;
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();

    return 0;
}
项目:liferay-blade-samples    文件:UseJDBC.java   
public static void useJDBC() {
    BundleContext bundleContext = FrameworkUtil.getBundle(
        UseJDBC.class).getBundleContext();

    ServiceTracker<CountryLocalService, CountryLocalService> tracker =
        new ServiceTracker<>(
            bundleContext, CountryLocalService.class, null);

    tracker.open();

    CountryLocalService countryLocalService = tracker.getService();

    try {
        countryLocalService.useJDBC();
    }
    catch (Exception e) {
        e.printStackTrace();
    }

    tracker.close();
}
项目:awplab-core    文件:IPOJOJobRunShellFactory.java   
protected Set<Factory> getFactories() {
    Set<Factory> factories = new HashSet<>();

    try {
        BundleContext bundleContext = FrameworkUtil.getBundle(IPOJOJobRunShellFactory.class).getBundleContext();
        ServiceReference[] refs = bundleContext.getServiceReferences(Factory.class.getName(), null);
        if (refs != null) {
            for (ServiceReference serviceReference : refs) {
                factories.add((Factory)bundleContext.getService(serviceReference));
            }
        }

        return factories;
    }
    catch (Exception ex) {
        LoggerFactory.getLogger(IPOJOJobRunShellFactory.class).error("Exception getting factories.", ex);
        return Collections.emptySet();
    }

}
项目:awplab-core    文件:ProvidersCommand.java   
@Override
public Object execute() throws Exception {

    ShellTable table = new ShellTable();
    table.column("Path");
    table.column("Bundle Id");
    table.column("Bundle");
    table.column("UI Class");
    table.column("Production Mode");
    //table.column("Bundle Id");
    //table.column("State");

    for (VaadinProvider vaadinProvider : vaadinManager.getProviders()) {
        Bundle bundle = FrameworkUtil.getBundle(vaadinProvider.getClass());
        table.addRow().addContent(vaadinProvider.getPath(), bundle.getBundleId(), bundle.getSymbolicName(), vaadinProvider.getUIClass().getSimpleName(), vaadinProvider.productionMode());
    }

    table.print(System.out);

    return null;
}
项目:google-cloud-eclipse    文件:StatusUtil.java   
private static String getBundleId(Object origin) {
  Class<?> clazz = null;
  if (origin == null) {
    clazz = StatusUtil.class;
  } else if (origin instanceof Class<?>) {
    clazz = (Class<?>) origin;
  } else {
    clazz = origin.getClass();
  }

  Bundle bundle = FrameworkUtil.getBundle(clazz);
  if (bundle == null) {
    return clazz.getName(); // what else can we do?
  }
  return bundle.getSymbolicName();
}
项目:google-cloud-eclipse    文件:BuildPath.java   
public static void runContainerResolverJob(IJavaProject javaProject) {
  IEclipseContext context = EclipseContextFactory.getServiceContext(
      FrameworkUtil.getBundle(BuildPath.class).getBundleContext());
  final IEclipseContext childContext =
      context.createChild(LibraryClasspathContainerResolverJob.class.getName());
  childContext.set(IJavaProject.class, javaProject);
  Job job =
      ContextInjectionFactory.make(LibraryClasspathContainerResolverJob.class, childContext);
  job.addJobChangeListener(new JobChangeAdapter() {
    @Override
    public void done(IJobChangeEvent event) {
      childContext.dispose();
    }
  });
  job.schedule();
}
项目:base    文件:ServiceLocator.java   
/**
 * Returns service by Interface, bypasses cache
 *
 * @param clazz Service Interface class to look up for
 *
 * @return service reference
 */
public static <T> T getServiceOrNull( Class<T> clazz )
{
    Preconditions.checkNotNull( clazz, "Class is null" );

    // get bundle instance via the OSGi Framework Util class
    BundleContext ctx = FrameworkUtil.getBundle( clazz ).getBundleContext();
    if ( ctx != null )
    {
        ServiceReference serviceReference = ctx.getServiceReference( clazz.getName() );
        if ( serviceReference != null )
        {
            Object service = ctx.getService( serviceReference );
            if ( clazz.isInstance( service ) )
            {
                return clazz.cast( service );
            }
        }
    }

    return null;
}
项目:liferay-devcon-2016-hystrix    文件:LiferayHystrixMetricsStreamServlet.java   
/**
 * OSGi component lifecycle listener for actication and modification of this
 * service.
 * 
 * @param componentContext
 *            OSGi component context.
 * @param properties
 *            OSGi configuration properties.
 * @throws Exception
 *             is thrown if the activation or modification of the service
 *             goes wrong.
 */
@Activate
@Modified
protected void activate(ComponentContext componentContext, Map<String, Object> properties) throws Exception {

    // Check if a service tracker for the context path exists and close it.
    if (_serviceTracker != null) {
        _serviceTracker.close();
    }

    // Create a filter for ServletContext components and start tracking.
    Filter filter = FrameworkUtil
            .createFilter("(&(objectClass=" + ServletContext.class.getName() + ")(osgi.web.contextpath=*))");

    _serviceTracker = new ServiceTracker<>(componentContext.getBundleContext(), filter, this);

    _serviceTracker.open();
}
项目:aries-rsa    文件:EndpointListenerNotifierTest.java   
@Test
public void testNotifyListener() throws InvalidSyntaxException {
    EndpointDescription endpoint1 = createEndpoint("myClass");
    EndpointDescription endpoint2 = createEndpoint("notMyClass");

    // Expect listener to be called for endpoint1 but not for endpoint2 
    EndpointListener epl = listenerExpects(endpoint1, "(objectClass=myClass)");

    EndpointRepository exportRepository = new EndpointRepository();
    EndpointListenerNotifier tm = new EndpointListenerNotifier(exportRepository);

    EasyMock.replay(epl);
    Set<Filter> filters = new HashSet<Filter>();
    filters.add(FrameworkUtil.createFilter("(objectClass=myClass)"));
    tm.add(epl, filters);
    tm.endpointAdded(endpoint1, null);
    tm.endpointAdded(endpoint2, null);
    tm.endpointRemoved(endpoint1, null);
    tm.endpointRemoved(endpoint2, null);
    EasyMock.verify(epl);
}
项目:aspecio    文件:ServiceWeavingManager.java   
private ProxyClassLoader getDynamicClassLoader(Class<?> clazz) {
    // Find all bundles required to instanciate the class
    // and bridge their classloaders in case the abstract class or interface
    // lives in non-imported packages...
    Class<?> currClazz = clazz;
    List<BundleRevision> bundleRevs = new ArrayList<>();
    Map<BundleRevision, BundleRevPath> revisions = revisionMap;
    BundleRevPath bundleRevPath = null;
    do {
        BundleRevision bundleRev = FrameworkUtil.getBundle(currClazz).adapt(BundleRevision.class);
        if (!bundleRevs.contains(bundleRev)) {
            bundleRevs.add(bundleRev);
            bundleRevPath = revisions.computeIfAbsent(bundleRev, k -> new BundleRevPath());
            revisions = bundleRevPath
                    .computeSubMapIfAbsent(() -> Collections.synchronizedMap(new WeakIdentityHashMap<>()));
        }
        currClazz = currClazz.getSuperclass();
    } while (currClazz != null && currClazz != Object.class);

    return bundleRevPath.computeClassLoaderIfAbsent(() -> {
        // the bundles set is now prioritised ...
        ClassLoader[] classLoaders = bundleRevs.stream().map(b -> b.getWiring().getClassLoader())
                .toArray(ClassLoader[]::new);
        return new ProxyClassLoader(new BridgingClassLoader(classLoaders));
    });
}
项目:aries-jax-rs-whiteboard    文件:TargetFilter.java   
@Override
public boolean test(CachingServiceReference<T> ref) {
    String target = (String)ref.getProperty(JAX_RS_WHITEBOARD_TARGET);

    if (target == null) {
        return true;
    }

    Filter filter;

    try {
        filter = FrameworkUtil.createFilter(target);
    }
    catch (InvalidSyntaxException ise) {
        if (_log.isErrorEnabled()) {
            _log.error("Invalid '{}' filter syntax in {}", JAX_RS_WHITEBOARD_TARGET, ref);
        }

        return false;
    }

    return filter.match(_serviceRuntimeReference);
}
项目:cicomponents    文件:OutputListCommand.java   
@Override public Object execute() throws Exception {

        BundleContext context = FrameworkUtil.getBundle(OutputListCommand.class).getBundleContext();
        ServiceReference<OutputProviderRegistry> reference = context
                .getServiceReference(OutputProviderRegistry.class);
        OutputProviderRegistry registry = context.getService(reference);

        // Build the table
        ShellTable table = new ShellTable();

        table.column("ID").alignLeft();
        table.column("Last updated").alignLeft();
        table.emptyTableText("No outputs available");

        for (Map.Entry<UUID, OutputProvider> entry : registry.getProviders().entrySet()) {
            table.addRow().addContent(entry.getKey().toString(), entry.getValue().getLatestDate().toString());
        }

        // Print it
        table.print(System.out);

        context.ungetService(reference);

        return null;
    }
项目:cicomponents    文件:OutputTailCommand.java   
@Override public Object execute() throws Exception {
    BundleContext context = FrameworkUtil.getBundle(OutputListCommand.class).getBundleContext();
    ServiceReference<OutputProviderRegistry> reference = context
            .getServiceReference(OutputProviderRegistry.class);
    OutputProviderRegistry registry = context.getService(reference);

    OutputProvider provider = registry.getProviders().get(UUID.fromString(uuid));

    try {
        provider.getOutput().forEachOrdered(timestampedOutput -> {
            if (timestampedOutput.getKind() == STDERR) {
                System.out.print(ANSI_RED);
            }
            System.out.print(new String(timestampedOutput.getOutput()));
            if (timestampedOutput.getKind() == STDERR) {
                System.out.print(ANSI_RESET);
            }

        });
    } finally {
        System.out.println(); // newline
        context.ungetService(reference);
    }
    return null;
}