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


Java ServiceTrackerCustomizer類代碼示例

本文整理匯總了Java中org.osgi.util.tracker.ServiceTrackerCustomizer的典型用法代碼示例。如果您正苦於以下問題:Java ServiceTrackerCustomizer類的具體用法?Java ServiceTrackerCustomizer怎麽用?Java ServiceTrackerCustomizer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: FilterTracker

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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
        }
    } );
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:26,代碼來源:FilterTracker.java

示例2: start

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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();
}
 
開發者ID:luoweb,項目名稱:osgi_in_action-,代碼行數:24,代碼來源:Activator.java

示例3: start

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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();
}
 
開發者ID:luoweb,項目名稱:osgi_in_action-,代碼行數:22,代碼來源:Activator.java

示例4: start

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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));
    }

}
 
開發者ID:L7R7,項目名稱:magic-bundle,代碼行數:33,代碼來源:Activator.java

示例5: start

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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);
}
 
開發者ID:L7R7,項目名稱:magic-bundle,代碼行數:33,代碼來源:Activator.java

示例6: ObjectPoolTracker

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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;
        }
    } );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:31,代碼來源:ObjectPoolTracker.java

示例7: ConnectionAnalyzerFactory

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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 ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:39,代碼來源:ConnectionAnalyzerFactory.java

示例8: AbstractConfigurationAdministrator

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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 );
        }
    } );
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:28,代碼來源:AbstractConfigurationAdministrator.java

示例9: install

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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();
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:28,代碼來源:ConsoleLogManager.java

示例10: install

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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));
    }
}
 
開發者ID:vespa-engine,項目名稱:vespa,代碼行數:37,代碼來源:OsgiLogManager.java

示例11: ChannelProviderTracker

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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 );
            }
        }
    } );
}
 
開發者ID:eclipse,項目名稱:packagedrone,代碼行數:37,代碼來源:ChannelProviderTracker.java

示例12: activate

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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();
}
 
開發者ID:Talend,項目名稱:components,代碼行數:34,代碼來源:DefinitionRegistryOsgi.java

示例13: startTracking

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
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);
    }
}
 
開發者ID:arievanwi,項目名稱:osgi.ee,代碼行數:12,代碼來源:OurServletContext.java

示例14: activate

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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();
}
 
開發者ID:arievanwi,項目名稱:osgi.ee,代碼行數:28,代碼來源:WebContextListener.java

示例15: activate

import org.osgi.util.tracker.ServiceTrackerCustomizer; //導入依賴的package包/類
@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();
 }
 
開發者ID:mhus,項目名稱:mhus-osgi-tools,代碼行數:28,代碼來源:VaadinResourcesServlet.java


注:本文中的org.osgi.util.tracker.ServiceTrackerCustomizer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。