Package org.osgi.util.tracker

Examples of org.osgi.util.tracker.ServiceTrackerCustomizer


            if (sRef != null) {
                IDiagramPreferenceService service = (IDiagramPreferenceService) context.getService(sRef);
                EditorHandler.PREFERENCE_FACTORY = service;
            }
            //use a service tracker to be called back when the IUUIDBasedRepositoryFactory is ready:
            ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {

                public void removedService(ServiceReference reference, Object service) {
                    //special servlet shutdown
                }

                public void modifiedService(ServiceReference reference, Object service) {
                    //reload?
                }

                public Object addingService(ServiceReference reference) {
                    IDiagramPreferenceService service = (IDiagramPreferenceService) context.getService(reference);
                    EditorHandler.PREFERENCE_FACTORY = service;
                    return service;
                }
            };
            ServiceTracker tracker = new ServiceTracker(context,
                    IDiagramPreferenceService.class.getName(), cust);
            tracker.open();
        }

        {
            ServiceReference[] sRefs = context.getServiceReferences(IFilterFactory.class.getName(), null);
            if (sRefs != null) {
                for (ServiceReference sRef : sRefs) {
                    IFilterFactory service = (IFilterFactory) context.getService(sRef);
                    PluggableFilter.registerFilter(service);
                }
            }
            //use a service tracker to be called back when the IFilterFactory is ready:
            ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {

                public void removedService(ServiceReference reference, Object service) {
                    //special servlet shutdown
                }

                public void modifiedService(ServiceReference reference, Object service) {
                    //reload?
                }

                public Object addingService(ServiceReference reference) {
                    IFilterFactory service = (IFilterFactory) context.getService(reference);
                    PluggableFilter.registerFilter(service);
                    return service;
                }
            };
            ServiceTracker tracker = new ServiceTracker(context,
                    IFilterFactory.class.getName(), cust);
            tracker.open();
        }
       
        {
          ServiceReference[] sRefs = context.getServiceReferences(IDiagramProfileFactory.class.getName(), null);
          if (sRefs != null) {
              for (ServiceReference sRef : sRefs) {
                  IDiagramProfileFactory service = (IDiagramProfileFactory) context.getService(sRef);
                  ProfileServiceImpl.INSTANCE.getFactories().add(service);
              }
          }
          ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {
 
              public void removedService(ServiceReference reference, Object service) {
              }
 
              public void modifiedService(ServiceReference reference, Object service) {
View Full Code Here


    }

    private void init() {
        Filter virtualConnectorFilter = FilterUtils.makeFilterForClass(VirtualConnectorProvider.class);
        virtualConnectorProviderTracker =
            new ServiceTracker(bundleContext, virtualConnectorFilter, new ServiceTrackerCustomizer() {
                @Override
                public void removedService(ServiceReference reference, Object service) {
                    VirtualConnectorProvider provider = (VirtualConnectorProvider) service;
                    Iterator<Registration> factoryServices = getFactoriesForVirtualConnectorForRemoval(provider);
                    unregisterAllRegistrations(factoryServices);
                }

                @Override
                public void modifiedService(ServiceReference reference, Object service) {
                    // do nothing
                }

                @Override
                public Object addingService(ServiceReference reference) {
                    createNewFactoryForVirtualConnectorProvider(reference);
                    return bundleContext.getService(reference);
                }

            });
        Filter domainProviderFilter = FilterUtils.makeFilterForClass(DomainProvider.class);
        domainProviderTracker =
            new ServiceTracker(bundleContext, domainProviderFilter, new ServiceTrackerCustomizer() {
                @Override
                public void removedService(ServiceReference reference, Object service) {
                    Iterator<Registration> factoryServices =
                        getFactoriesForDomainProviderForRemoval((DomainProvider) service);
                    unregisterAllRegistrations(factoryServices);
View Full Code Here

                for (ServiceReference sRef : sRefs) {
                    IDiagramPluginFactory service = (IDiagramPluginFactory) bundleContext.getService(sRef);
                    _factories.add(service);
                }
            }
            ServiceTrackerCustomizer cust = new ServiceTrackerCustomizer() {

                public void removedService(ServiceReference reference, Object service) {
                }

                public void modifiedService(ServiceReference reference, Object service) {
View Full Code Here

    public void init() throws Exception {
        if (bundleContext == null) {
            throw new IllegalArgumentException("No bundleContext injected!");
        }
        ServiceTrackerCustomizer customizer = null;
        serviceTracker = new ServiceTracker(bundleContext, "org.ops4j.pax.logging.spi.PaxAppender", customizer);
        serviceTracker.open();

        bundleContext.addBundleListener(this);
    }
View Full Code Here

        super.start(arg0);
        // bundle context for later ServiceReference lookups
        ctx = arg0;

        // track providers as they register themselves
        ServiceTrackerCustomizer customizer = new PersistenceTracker(this);
        tracker = new ServiceTracker(ctx, PERSISTENCE_PROVIDER, customizer);
        tracker.open();

        // configure JPA provider resolver for OSGi
        PersistenceProviderResolverHolder.setPersistenceProviderResolver(this);
View Full Code Here

    protected void activate(ComponentContext ctx){
        final BundleContext bundleContext = ctx.getBundleContext();
        final String managerServicePid = (String)ctx.getProperties().get(Constants.SERVICE_PID);
        labelTokenizerTracker = new ServiceTracker(bundleContext,
            LabelTokenizer.class.getName(),
            new ServiceTrackerCustomizer() {
               
                @Override
                public Object addingService(ServiceReference reference) {
                    if(managerServicePid.equals(reference.getProperty(Constants.SERVICE_PID))){
                        return null; //do not track this manager!
View Full Code Here

    // Register the endpoint listener tracker, so that endpoint listeners
    // that are subsequently added
    // will then be notified of discovered endpoints
    endpointListenerTracker = new ServiceTracker(context,
        EndpointListener.class.getName(),
        new ServiceTrackerCustomizer() {
          public Object addingService(ServiceReference reference) {
            if (context == null)
              return null;
            EndpointListener listener = (EndpointListener) context
                .getService(reference);
            if (listener == null)
              return null;
            Collection<org.osgi.service.remoteserviceadmin.EndpointDescription> allDiscoveredEndpointDescriptions = getAllDiscoveredEndpointDescriptions();
            for (org.osgi.service.remoteserviceadmin.EndpointDescription ed : allDiscoveredEndpointDescriptions) {
              EndpointDescriptionLocator.EndpointListenerHolder[] endpointListenerHolders = getMatchingEndpointListenerHolders(
                  new ServiceReference[] { reference }, ed);
              if (endpointListenerHolders != null) {
                for (int i = 0; i < endpointListenerHolders.length; i++) {
                  queueEndpointDescription(
                      endpointListenerHolders[i]
                          .getListener(),
                      endpointListenerHolders[i]
                          .getDescription(),
                      endpointListenerHolders[i]
                          .getMatchingFilter(), true);
                }
              }
            }
            return listener;
          }

          public void modifiedService(ServiceReference reference,
              Object service) {
          }

          public void removedService(ServiceReference reference,
              Object service) {
          }
        });

    endpointListenerTracker.open();

    // Register the endpoint event listener tracker, so that endpoint event listeners
    // that are subsequently added
    // will then be notified of discovered endpoints
    endpointEventListenerTracker = new ServiceTracker(context,
        EndpointEventListener.class.getName(),
        new ServiceTrackerCustomizer() {
          public Object addingService(ServiceReference reference) {
            if (context == null)
              return null;
            EndpointEventListener listener = (EndpointEventListener) context
                .getService(reference);
View Full Code Here

    // Register IIDFactory service
    idFactoryServiceRegistration = context.registerService(
        IIDFactory.class.getName(), IDFactory.getDefault(), null);

    namespacesTracker = new ServiceTracker(context,
        Namespace.class.getName(), new ServiceTrackerCustomizer() {

          public Object addingService(ServiceReference reference) {
            Namespace ns = (Namespace) context
                .getService(reference);
            if (ns != null && ns.getName() != null)
View Full Code Here

  public IServiceInfoServiceListener(final IDiscoveryAdvertiser advertiser) {
    final BundleContext bundleContext = DiscoveryPlugin.getDefault()
        .getBundleContext();
    serviceTracker = new ServiceTracker(bundleContext, IServiceInfo.class,
        new ServiceTrackerCustomizer() {

          public Object addingService(ServiceReference reference) {
            final IServiceInfo serviceInfo = (IServiceInfo) bundleContext
                .getService(reference);
            final IServiceInfo specific = convertToProviderSpecific(
View Full Code Here

   
    // Other services can contribute Event topic filters which will be ignored
    // by the distribution part of DistributedEventAdmin. This is primarily useful
    // in cases where the Event data cannot be serialized or serialization is too
    // expensive.
    etfServiceTracker = new ServiceTracker(this.context, EventTopicFilter.class, new ServiceTrackerCustomizer() {
      public Object addingService(ServiceReference reference) {
        final EventTopicFilter etf = (EventTopicFilter) context.getService(reference);
        addEventTopicFilters(etf.getFilters());
        return etf;
      }

      public void modifiedService(ServiceReference reference,
          Object service) {
        // nop
      }

      public void removedService(ServiceReference reference,
          Object service) {
        final EventTopicFilter etf = (EventTopicFilter) service;
        removeEventTopicFilters(etf.getFilters());
      }
    });
    etfServiceTracker.open();

    // SerializationHandler are responsible to handle serialization of Event properties
    shServiceTracker = new ServiceTracker(this.context, SerializationHandler.class, new ServiceTrackerCustomizer() {
      public Object addingService(ServiceReference reference) {
        final SerializationHandler sh = (SerializationHandler) context.getService(reference);
        topic2serializationHandler.put(sh.getTopic(), sh);
        return sh;
      }
View Full Code Here

TOP

Related Classes of org.osgi.util.tracker.ServiceTrackerCustomizer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.