Java Code Examples for org.osgi.util.tracker.ServiceTrackerCustomizer

The following are top voted examples for showing how to use org.osgi.util.tracker.ServiceTrackerCustomizer. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: packagedrone   File: FilterTracker.java   View source code 6 votes vote down vote up
public FilterTracker ( final BundleContext context )
{
    this.context = context;

    this.tracker = new ServiceTracker<> ( context, Filter.class, new ServiceTrackerCustomizer<Filter, TrackedFilter> () {

        @Override
        public TrackedFilter addingService ( final ServiceReference<Filter> reference )
        {
            return addFilter ( reference );
        }

        @Override
        public void modifiedService ( final ServiceReference<Filter> reference, final TrackedFilter service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<Filter> reference, final TrackedFilter service )
        {
            service.dispose ();
            FilterTracker.this.filters = null; // reset cache
        }
    } );
}
 
Example 2
Project: package-drone   File: FilterTracker.java   View source code 6 votes vote down vote up
public FilterTracker ( final BundleContext context )
{
    this.context = context;

    this.tracker = new ServiceTracker<> ( context, Filter.class, new ServiceTrackerCustomizer<Filter, TrackedFilter> () {

        @Override
        public TrackedFilter addingService ( final ServiceReference<Filter> reference )
        {
            return addFilter ( reference );
        }

        @Override
        public void modifiedService ( final ServiceReference<Filter> reference, final TrackedFilter service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<Filter> reference, final TrackedFilter service )
        {
            service.dispose ();
            FilterTracker.this.filters = null; // reset cache
        }
    } );
}
 
Example 3
Project: osgi_in_action-   File: Activator.java   View source code 6 votes vote down vote up
public void start(final BundleContext context) throws Exception {
  tracker = new ServiceTracker(context, Command.class.getName(), new ServiceTrackerCustomizer() {
    
    public Object addingService(ServiceReference ref) {
      Command command = (Command) context.getService(ref);
      startTelnet(context, command);
      return command;
    }
    
    public void modifiedService(ServiceReference ref, Object service) {
      // TODO Auto-generated method stub
      
    }
    
    public void removedService(ServiceReference ref, Object service) {
      stopTelnet();
      context.ungetService(ref);
    }
    
  });

  tracker.open();
}
 
Example 4
Project: osgi_in_action-   File: Activator.java   View source code 6 votes vote down vote up
public void start(final BundleContext context) throws Exception {
  tracker = new ServiceTracker(context, Command.class.getName(), new ServiceTrackerCustomizer() {
    
    public Object addingService(ServiceReference ref) {
      Command command = (Command) context.getService(ref);
      startTty(context, command);
      return command;
    }
    
    public void modifiedService(ServiceReference ref, Object service) {
    }
    
    public void removedService(ServiceReference ref, Object service) {
      stopTty();
      context.ungetService(ref);
    }
    
  });

  tracker.open();
}
 
Example 5
Project: magic-bundle   File: Activator.java   View source code 5 votes vote down vote up
@Override
public void start(BundleContext context) throws Exception {
    randomNumberServiceTracker = new ServiceTracker<>(context, RandomNumberGenerator.class.getName(), new ServiceTrackerCustomizer<RandomNumberGenerator, RandomNumberGenerator>() {
        @Override
        public RandomNumberGenerator addingService(ServiceReference<RandomNumberGenerator> reference) {
            log.info(">>>>>>>>>>>> customizer#addingService");
            setServiceReference(reference);
            RandomNumberGenerator service = context.getService(reference);
            consumeService(service);
            return service;
        }

        @Override
        public void modifiedService(ServiceReference<RandomNumberGenerator> reference, RandomNumberGenerator service) {
            log.info(">>>>>>>>>>>> customizer#modifiedService");
            unsetServiceReference(context);
        }

        @Override
        public void removedService(ServiceReference<RandomNumberGenerator> reference, RandomNumberGenerator service) {
            log.info(">>>>>>>>>>>> customizer#removedService");
            unsetServiceReference(context);
        }
    });
    randomNumberServiceTracker.open();

    final ServiceReference<RandomNumberGenerator> reference = randomNumberServiceTracker.getServiceReference();
    if (reference != null) {
        consumeService(context.getService(reference));
    }

}
 
Example 6
Project: magic-bundle   File: Activator.java   View source code 5 votes vote down vote up
@Override
public void start(BundleContext context) throws Exception {
    String filterString = String.format("(|(objectClass=%s)(objectClass=%s))", RandomNumberGenerator.class.getName(), RandomStringGenerator.class.getName());
    serviceTracker = new ServiceTracker<>(context, context.createFilter(filterString), new ServiceTrackerCustomizer<Object, Object>() {
        @Override
        public Object addingService(ServiceReference<Object> reference) {
            setServiceReference(reference);
            consumeServicesIfPresent(context, randomNumberGeneratorServiceReference, randomStringGeneratorServiceReference);
            return context.getService(reference);
        }

        @Override
        public void modifiedService(ServiceReference<Object> reference, Object service) {

        }

        @Override
        public void removedService(ServiceReference<Object> reference, Object service) {
            unsetServiceReference(reference);
        }
    });
    serviceTracker.open();

    ServiceReference<Object>[] serviceReferences = serviceTracker.getServiceReferences();
    if (serviceReferences != null) {
        Arrays.stream(serviceReferences).forEach(this::setServiceReference);
    } else {
        log.info("serviceReferences is null");
    }

    consumeServicesIfPresent(context, randomNumberGeneratorServiceReference, randomStringGeneratorServiceReference);
}
 
Example 7
Project: neoscada   File: ObjectPoolTracker.java   View source code 5 votes vote down vote up
public ObjectPoolTracker ( final BundleContext context, final String poolClass ) throws InvalidSyntaxException
{
    final Map<String, String> parameters = new HashMap<String, String> ();
    parameters.put ( ObjectPool.OBJECT_POOL_CLASS, poolClass );
    final Filter filter = FilterUtil.createAndFilter ( ObjectPool.class.getName (), parameters );

    this.poolTracker = new ServiceTracker<ObjectPool<S>, ObjectPool<S>> ( context, filter, new ServiceTrackerCustomizer<ObjectPool<S>, ObjectPool<S>> () {

        @Override
        public void removedService ( final ServiceReference<ObjectPool<S>> reference, final ObjectPool<S> service )
        {
            context.ungetService ( reference );
            ObjectPoolTracker.this.removePool ( service );
        }

        @Override
        public void modifiedService ( final ServiceReference<ObjectPool<S>> reference, final ObjectPool<S> service )
        {
            ObjectPoolTracker.this.modifyPool ( service, reference );
        }

        @Override
        public ObjectPool<S> addingService ( final ServiceReference<ObjectPool<S>> reference )
        {
            final ObjectPool<S> o = context.getService ( reference );
            ObjectPoolTracker.this.addPool ( o, reference );
            return o;
        }
    } );
}
 
Example 8
Project: neoscada   File: ConnectionAnalyzerFactory.java   View source code 5 votes vote down vote up
public ConnectionAnalyzerFactory ( final ScheduledExecutorService executor, final BundleContext context )
{
    this.executor = executor;
    this.context = context;
    this.connectionTracker = new ServiceTracker<ConnectionService, ConnectionService> ( context, ConnectionService.class, new ServiceTrackerCustomizer<ConnectionService, ConnectionService> () {

        @Override
        public void removedService ( final ServiceReference<ConnectionService> reference, final ConnectionService service )
        {
            ConnectionAnalyzerFactory.this.removeService ( service );
        }

        @Override
        public void modifiedService ( final ServiceReference<ConnectionService> reference, final ConnectionService service )
        {

        }

        @Override
        public ConnectionService addingService ( final ServiceReference<ConnectionService> reference )
        {
            try
            {
                logger.debug ( "Found new service: {}", reference );
                final ConnectionService service = context.getService ( reference );
                ConnectionAnalyzerFactory.this.addService ( reference, service );
                return service;
            }
            catch ( final Throwable e )
            {
                logger.warn ( "Failed to add service", e );
            }
            context.ungetService ( reference );
            return null;
        }
    } );
    this.connectionTracker.open ();
}
 
Example 9
Project: neoscada   File: AbstractConfigurationAdministrator.java   View source code 5 votes vote down vote up
public AbstractConfigurationAdministrator ( final BundleContext context )
{
    this.context = context;

    this.executor = new ExportedExecutorService ( "Configuration Administrator", 1, 1, 1, TimeUnit.MINUTES );

    this.listenerTracker = new ListenerTracker ( context );
    this.serviceListener = new ServiceTracker<ConfigurationFactory, ConfigurationFactory> ( context, ConfigurationFactory.class, new ServiceTrackerCustomizer<ConfigurationFactory, ConfigurationFactory> () {

        @Override
        public void removedService ( final ServiceReference<ConfigurationFactory> reference, final ConfigurationFactory service )
        {
            AbstractConfigurationAdministrator.this.removedService ( reference, service );
        }

        @Override
        public void modifiedService ( final ServiceReference<ConfigurationFactory> reference, final ConfigurationFactory service )
        {
        }

        @Override
        public ConfigurationFactory addingService ( final ServiceReference<ConfigurationFactory> reference )
        {
            return AbstractConfigurationAdministrator.this.addingService ( reference );
        }
    } );
}
 
Example 10
Project: vespa   File: ConsoleLogManager.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void install(final BundleContext osgiContext) {
    if (tracker != null) {
        throw new IllegalStateException("ConsoleLogManager already installed.");
    }
    tracker = new ServiceTracker<LogReaderService,LogReaderService>(osgiContext, LogReaderService.class.getName(),
        new ServiceTrackerCustomizer<LogReaderService,LogReaderService>() {

        @Override
        public LogReaderService addingService(ServiceReference<LogReaderService> reference) {
            LogReaderService service = osgiContext.getService(reference);
            service.addLogListener(listener);
            return service;
        }

        @Override
        public void modifiedService(ServiceReference<LogReaderService> reference, LogReaderService service) {

        }

        @Override
        public void removedService(ServiceReference<LogReaderService> reference, LogReaderService service) {
            service.removeLogListener(listener);
        }
    });
    tracker.open();
}
 
Example 11
Project: vespa   File: OsgiLogManager.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void install(final BundleContext osgiContext) {
    if (tracker != null) {
        throw new IllegalStateException("OsgiLogManager already installed.");
    }
    tracker = new ServiceTracker<>(osgiContext, LogService.class, new ServiceTrackerCustomizer<LogService,LogService>() {

        @Override
        public LogService addingService(ServiceReference<LogService> reference) {
            LogService service = osgiContext.getService(reference);
            services.add(service);
            return service;
        }

        @Override
        public void modifiedService(ServiceReference<LogService> reference, LogService service) {

        }

        @Override
        public void removedService(ServiceReference<LogService> reference, LogService service) {
            services.remove(service);
        }
    });
    tracker.open();
    synchronized (globalLock) {
        Logger root = Logger.getLogger("");
        if (configureLogLevel) {
            root.setLevel(Level.ALL);
        }
        for (Handler handler : root.getHandlers()) {
            root.removeHandler(handler);
        }
        root.addHandler(new OsgiLogHandler(this));
    }
}
 
Example 12
Project: packagedrone   File: ChannelProviderTracker.java   View source code 5 votes vote down vote up
public ChannelProviderTracker ( final BundleContext context )
{
    final ReadWriteLock lock = new ReentrantReadWriteLock ( false );

    this.readLock = lock.readLock ();
    this.writeLock = lock.writeLock ();

    this.tracker = new ServiceTracker<> ( context, ChannelProvider.class, new ServiceTrackerCustomizer<ChannelProvider, ChannelProvider> () {

        @Override
        public ChannelProvider addingService ( final ServiceReference<ChannelProvider> reference )
        {
            final ChannelProvider service = context.getService ( reference );
            addService ( service );
            return service;
        }

        @Override
        public void modifiedService ( final ServiceReference<ChannelProvider> reference, final ChannelProvider service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<ChannelProvider> reference, final ChannelProvider service )
        {
            try
            {
                removeService ( service );
            }
            finally
            {
                context.ungetService ( reference );
            }
        }
    } );
}
 
Example 13
Project: components   File: DefinitionRegistryOsgi.java   View source code 5 votes vote down vote up
@Activate
void activate(final BundleContext bundleContext) throws InvalidSyntaxException {
    serviceTracker = new ServiceTracker<>(bundleContext, ComponentInstaller.class.getName(),
            new ServiceTrackerCustomizer<ComponentInstaller, ComponentInstaller>() {

                @Override
                public ComponentInstaller addingService(ServiceReference<ComponentInstaller> serviceRef) {
                    ComponentInstaller componentInstaller = bundleContext.getService(serviceRef);
                    Object nameProp = serviceRef.getProperty("component.name"); //$NON-NLS-1$
                    if (nameProp instanceof String) {
                        LOGGER.info("Registered the component: " + nameProp + "(" //$NON-NLS-1$//$NON-NLS-2$
                                + componentInstaller.getClass().getCanonicalName() + ")"); //$NON-NLS-1$
                        componentInstaller.install(DefinitionRegistryOsgi.this);
                    } else {// no name set so issue a warning
                        LOGGER.warn("Failed to register the following component because it is unnamed: " //$NON-NLS-1$
                                + serviceRef.getClass().getCanonicalName());
                    }
                    return componentInstaller;
                }

                @Override
                public void modifiedService(ServiceReference<ComponentInstaller> arg0,
                        ComponentInstaller componentInstaller) {
                    // not handled for now
                }

                @Override
                public void removedService(ServiceReference<ComponentInstaller> arg0, ComponentInstaller componentInstaller) {
                    // No any un-install yet from the service
                }
            });
    serviceTracker.open();
}
 
Example 14
Project: osgi.ee   File: OurServletContext.java   View source code 5 votes vote down vote up
private <T, C> ServiceTracker<T, C> startTracking(String filter, ServiceTrackerCustomizer<T, C> cust) {
    try {
        BundleContext bc = getOwner().getBundleContext();
        String filterString = "(&(" + filter + ")(" + WebContextDefinition.WEBCONTEXTPATH + "=*))";
        ServiceTracker<T, C> tracker = new ServiceTracker<>(bc, bc.createFilter(filterString), cust);
        tracker.open();
        return tracker;
    } catch (Exception exc) {
        throw new RuntimeException(exc);
    }
}
 
Example 15
Project: osgi.ee   File: WebContextListener.java   View source code 5 votes vote down vote up
@Activate
void activate(BundleContext context) {
    // Track the web context definitions.
    tracker = new ServiceTracker<>(context, WebContextDefinition.class,
            new ServiceTrackerCustomizer<WebContextDefinition, Context>() {
        @Override
        public Context addingService(ServiceReference<WebContextDefinition> ref) {
            // Get the service.
            WebContextDefinition definition = context.getService(ref);
            if (definition == null) {
                return null;
            }
            // Construct the servlet from this service.
            Context ctx = create(ref.getBundle(), definition);
            return ctx;
        }
        @Override
        public void modifiedService(ServiceReference<WebContextDefinition> ref, Context ctxt) {
            // Not necessary
        }
        @Override
        public void removedService(ServiceReference<WebContextDefinition> ref, Context ctxt) {
            destroy(ctxt);
        }
    });
    new Thread(() -> tracker.open()).start();
}
 
Example 16
Project: mhus-osgi-tools   File: VaadinResourcesServlet.java   View source code 5 votes vote down vote up
@Activate
 public void activate(ComponentContext ctx) {
 	this.context = ctx.getUsingBundle().getBundleContext();
 	customizer = new ServiceTrackerCustomizer<VaadinResourceProvider,VaadinResourceProvider>() {

@Override
public VaadinResourceProvider addingService(
		ServiceReference<VaadinResourceProvider> reference) {
	return context.getService(reference);
}

@Override
public void modifiedService(
		ServiceReference<VaadinResourceProvider> reference,
		VaadinResourceProvider service) {
}

@Override
public void removedService(
		ServiceReference<VaadinResourceProvider> reference,
		VaadinResourceProvider service) {
}
 		
 	};
 	tracker = new ServiceTracker<VaadinResourceProvider, VaadinResourceProvider>(context, VaadinResourceProvider.class, customizer);
 	tracker.open();
 }
 
Example 17
Project: neoscada   File: Advertiser.java   View source code 4 votes vote down vote up
public void start ( final BundleContext context )
{
    this.executor = Executors.newSingleThreadExecutor ( new NamedThreadFactory ( "ECF/Advertiser", true ) );

    try
    {
        connect ();
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to start advertiser", e );
        return;
    }

    this.tracker = new ServiceTracker<ExporterInformation, ExporterInformation> ( context, ExporterInformation.class, new ServiceTrackerCustomizer<ExporterInformation, ExporterInformation> () {

        @Override
        public void removedService ( final ServiceReference<ExporterInformation> reference, final ExporterInformation service )
        {
            Advertiser.this.executor.execute ( new Runnable () {

                @Override
                public void run ()
                {
                    Advertiser.this.removedService ( service );
                }

            } );
        }

        @Override
        public void modifiedService ( final ServiceReference<ExporterInformation> reference, final ExporterInformation service )
        {
        }

        @Override
        public ExporterInformation addingService ( final ServiceReference<ExporterInformation> reference )
        {
            return performAdd ( context, reference );
        }
    } );
    this.tracker.open ();
}
 
Example 18
Project: neoscada   File: AbstractConnectionProvider.java   View source code 4 votes vote down vote up
public AbstractConnectionProvider ( final BundleContext context, final String interfaceName )
{
    super ();
    this.context = context;

    Filter filter = null;
    try
    {
        final Map<String, String> parameters = new HashMap<String, String> ();
        parameters.put ( DriverFactory.INTERFACE_NAME, interfaceName );
        filter = FilterUtil.createAndFilter ( ConnectionRequest.class.getName (), parameters );
    }
    catch ( final InvalidSyntaxException e )
    {
        logger.warn ( "Failed to create filter", e );
    }

    if ( filter != null )
    {
        this.tracker = new ServiceTracker<ConnectionRequest, ConnectionRequest> ( context, filter, new ServiceTrackerCustomizer<ConnectionRequest, ConnectionRequest> () {

            @Override
            public void removedService ( final ServiceReference<ConnectionRequest> reference, final ConnectionRequest service )
            {
                AbstractConnectionProvider.this.removedService ( reference, service );
            }

            @Override
            public void modifiedService ( final ServiceReference<ConnectionRequest> reference, final ConnectionRequest service )
            {
                AbstractConnectionProvider.this.modifiedService ( reference, service );
            }

            @Override
            public ConnectionRequest addingService ( final ServiceReference<ConnectionRequest> reference )
            {
                return AbstractConnectionProvider.this.addingService ( reference );
            }
        } );
    }
    else
    {
        this.tracker = null;
    }

}
 
Example 19
Project: neoscada   File: DaveBlockConfigurator.java   View source code 4 votes vote down vote up
public DaveBlockConfigurator ( final DaveDevice device, final BundleContext context )
{
    this.device = device;
    this.context = context;

    final Map<String, String> parameters = new HashMap<String, String> ();
    parameters.put ( "daveDevice", device.getId () );
    try
    {
        final Filter filter = FilterUtil.createAndFilter ( BlockConfiguration.class.getName (), parameters );
        this.tracker = new ServiceTracker<Object, Object> ( context, filter, new ServiceTrackerCustomizer<Object, Object> () {

            @Override
            public void removedService ( final ServiceReference<Object> reference, final Object service )
            {
                if ( service instanceof BlockConfiguration )
                {
                    if ( DaveBlockConfigurator.this.removeBlock ( reference, (BlockConfiguration)service ) )
                    {
                        context.ungetService ( reference );
                    }
                }
            }

            @Override
            public void modifiedService ( final ServiceReference<Object> reference, final Object service )
            {
                DaveBlockConfigurator.this.modifyBlock ( reference, (BlockConfiguration)service );
            }

            @Override
            public Object addingService ( final ServiceReference<Object> reference )
            {
                final Object o = DaveBlockConfigurator.this.context.getService ( reference );
                try
                {
                    DaveBlockConfigurator.this.addOrReplaceBlock ( reference, (BlockConfiguration)o );
                    return o;
                }
                catch ( final Throwable e )
                {
                    logger.warn ( "Failed to add block", e );
                    return o;
                }
            }
        } );
    }
    catch ( final Exception e )
    {
        logger.warn ( "Failed to configure", e );
    }
    if ( this.tracker != null )
    {
        this.tracker.open ();
    }
}
 
Example 20
Project: hashsdn-controller   File: BlueprintBundleTracker.java   View source code 4 votes vote down vote up
/**
 * Implemented from BundleActivator.
 */
@Override
public void start(final BundleContext context) {
    LOG.info("Starting {}", getClass().getSimpleName());

    restartService = new BlueprintContainerRestartServiceImpl();

    bundleContext = context;

    registerBlueprintEventHandler(context);

    registerNamespaceHandler(context);

    bundleTracker = new BundleTracker<>(context, Bundle.ACTIVE, this);

    blueprintExtenderServiceTracker = new ServiceTracker<>(context, BlueprintExtenderService.class.getName(),
            new ServiceTrackerCustomizer<BlueprintExtenderService, BlueprintExtenderService>() {
                @Override
                public BlueprintExtenderService addingService(
                        final ServiceReference<BlueprintExtenderService> reference) {
                    return onBlueprintExtenderServiceAdded(reference);
                }

                @Override
                public void modifiedService(final ServiceReference<BlueprintExtenderService> reference,
                        final BlueprintExtenderService service) {
                }

                @Override
                public void removedService(final ServiceReference<BlueprintExtenderService> reference,
                        final BlueprintExtenderService service) {
                }
            });
    blueprintExtenderServiceTracker.open();

    quiesceParticipantTracker = new ServiceTracker<>(context, QuiesceParticipant.class.getName(),
            new ServiceTrackerCustomizer<QuiesceParticipant, QuiesceParticipant>() {
                @Override
                public QuiesceParticipant addingService(
                        final ServiceReference<QuiesceParticipant> reference) {
                    return onQuiesceParticipantAdded(reference);
                }

                @Override
                public void modifiedService(final ServiceReference<QuiesceParticipant> reference,
                                            final QuiesceParticipant service) {
                }

                @Override
                public void removedService(final ServiceReference<QuiesceParticipant> reference,
                                           final QuiesceParticipant service) {
                }
            });
    quiesceParticipantTracker.open();
}
 
Example 21
Project: aries-rsa   File: Activator.java   View source code 4 votes vote down vote up
private RSATracker(BundleContext context, Class<RemoteServiceAdmin> clazz,
                   ServiceTrackerCustomizer<RemoteServiceAdmin, RemoteServiceAdmin> customizer) {
    super(context, clazz, customizer);
}
 
Example 22
Project: recalot.com   File: ServiceTracker.java   View source code 4 votes vote down vote up
public ServiceTracker(BundleContext context, String reference, ServiceTrackerCustomizer customizer, String filePath, String path) {
    super(context, reference, customizer);

    this.filePath = filePath;
    this.path = path;
}
 
Example 23
Project: packagedrone   File: ChannelAspectProcessor.java   View source code 4 votes vote down vote up
public ChannelAspectProcessor ( final BundleContext context )
{

    this.tracker = new ServiceTracker<ChannelAspectFactory, FactoryEntry> ( context, ChannelAspectFactory.class, new ServiceTrackerCustomizer<ChannelAspectFactory, FactoryEntry> () {

        @Override
        public FactoryEntry addingService ( final ServiceReference<ChannelAspectFactory> reference )
        {
            return makeEntry ( context, reference );
        }

        @Override
        public void modifiedService ( final ServiceReference<ChannelAspectFactory> reference, final FactoryEntry service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<ChannelAspectFactory> reference, final FactoryEntry service )
        {
            context.ungetService ( reference ); // makeEntry got the service
        }
    } );
    this.tracker.open ();

    this.groupTracker = new ServiceTracker<Group, GroupInformation> ( context, Group.class, new ServiceTrackerCustomizer<Group, GroupInformation> () {

        @Override
        public GroupInformation addingService ( final ServiceReference<Group> reference )
        {
            final Group group = context.getService ( reference );
            return group.getInformation ();
        }

        @Override
        public void modifiedService ( final ServiceReference<Group> reference, final GroupInformation service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<Group> reference, final GroupInformation service )
        {
            context.ungetService ( reference );
        }
    } );
    this.groupTracker.open ();
}
 
Example 24
Project: package-drone   File: ChannelAspectProcessor.java   View source code 4 votes vote down vote up
public ChannelAspectProcessor ( final BundleContext context )
{

    this.tracker = new ServiceTracker<ChannelAspectFactory, FactoryEntry> ( context, ChannelAspectFactory.class, new ServiceTrackerCustomizer<ChannelAspectFactory, FactoryEntry> () {

        @Override
        public FactoryEntry addingService ( final ServiceReference<ChannelAspectFactory> reference )
        {
            return makeEntry ( context, reference );
        }

        @Override
        public void modifiedService ( final ServiceReference<ChannelAspectFactory> reference, final FactoryEntry service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<ChannelAspectFactory> reference, final FactoryEntry service )
        {
            context.ungetService ( reference ); // makeEntry got the service
        }
    } );
    this.tracker.open ();

    this.groupTracker = new ServiceTracker<Group, GroupInformation> ( context, Group.class, new ServiceTrackerCustomizer<Group, GroupInformation> () {

        @Override
        public GroupInformation addingService ( final ServiceReference<Group> reference )
        {
            final Group group = context.getService ( reference );
            return group.getInformation ();
        }

        @Override
        public void modifiedService ( final ServiceReference<Group> reference, final GroupInformation service )
        {
        }

        @Override
        public void removedService ( final ServiceReference<Group> reference, final GroupInformation service )
        {
            context.ungetService ( reference );
        }
    } );
    this.groupTracker.open ();
}