/** * Creates a service collection and starts it. * * @see AbstractLifecycle#onStart */ @Override protected void onStart() { m_serviceCollection = new ServiceCollection<T>( m_context, m_serviceClass, new CollectionListener() ); m_serviceCollection.start(); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param className name of class implemented or extended by the service * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, String className ) { return ServiceLookup.<T> getService( bc, className, DEFAULT_TIMEOUT, "" ); }
/** * Resolves a new service by serching the services collection for first available service. */ private synchronized void resolveService() { T newService = null; final Iterator<T> it = m_serviceCollection.iterator(); while( newService == null && it.hasNext() ) { final T candidateService = it.next(); if( !candidateService.equals( getService() ) ) { newService = candidateService; } } setService( newService ); }
/** * Stops the service collection and releases resources. * * @see AbstractLifecycle#onStop */ @Override protected void onStop() { if( m_serviceCollection != null ) { m_serviceCollection.stop(); m_serviceCollection = null; } setService( null ); }
/** * Returns a service matching the given filter. * * @param bc bundle context for accessing the OSGi registry * @param ldapFilter LDAP filter to be matched by the service. The class name must be part of the * filter. * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the default * timeout */ public static Object getServiceByFilter( BundleContext bc, String ldapFilter ) { return getServiceByFilter( bc, ldapFilter, DEFAULT_TIMEOUT ); }
String filter ) ServiceTracker tracker = createServiceTracker( bc, className, filter ); try if( svc == null ) throw new ServiceLookupException( "gave up waiting for service " + className ); throw new ServiceLookupException( exc );
/** * Closes the service tracker and releases resources. * * @see AbstractLifecycle#onStop */ @Override protected void onStop() { if( m_serviceTracker != null ) { m_serviceTracker.close(); m_serviceTracker = null; } }
/** * Sets the new service and notifies the listener that the service was changed. * * @param newService the new service */ private synchronized void setService( final T newService ) { if( m_service != newService ) { LOG.debug( "Service changed [" + m_service + "] -> [" + newService + "]" ); final T oldService = m_service; m_service = newService; if( m_serviceListener != null ) { m_serviceListener.serviceChanged( oldService, m_service ); } } }
private static ServiceTracker createServiceTracker( BundleContext bc, String className, String filterString ) { StringBuilder builder = new StringBuilder( "(&(objectClass=" ); builder.append( className ); builder.append( ')' ); if( filterString != null ) { builder.append( filterString ); } builder.append( ')' ); return createServiceTrackerWithFilter( bc, builder.toString() ); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param type class implemented or extended by the service * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, Class<T> type ) { return getService( bc, type, DEFAULT_TIMEOUT ); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param type class implemented or extended by the service * @param props properties to be matched by the service * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, Class<T> type, Map<String, String> props ) { return getService( bc, type, DEFAULT_TIMEOUT, props ); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param type class implemented or extended by the service * @param timeout maximum wait period in milliseconds * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, Class<T> type, long timeout ) { return ServiceLookup.<T> getService( bc, type.getName(), timeout, "" ); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param type class implemented or extended by the service * @param timeout maximum wait period in milliseconds * @param props properties to be matched by the service * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, Class<T> type, long timeout, Map<String, String> props ) { return ServiceLookup.<T> getService( bc, type.getName(), timeout, props ); }
/** * Returns a service matching the given criteria. * * @param <T> class implemented or extended by the service * @param bc bundle context for accessing the OSGi registry * @param type class implemented or extended by the service * @param timeout maximum wait period in milliseconds * @param filter LDAP filter to be matched by the service. The class name will be added to the * filter. * @return matching service (not null) * @throws ServiceLookupException when no matching service has been found after the timeout */ public static <T> T getService( BundleContext bc, Class<T> type, long timeout, String filter ) { return ServiceLookup.<T> getService( bc, type.getName(), timeout, filter ); }
public ProbeInvoker createProbeInvoker(Object context, String expr) { BundleContext ctx = (BundleContext) context; Injector injector = ServiceLookup.getService(ctx, Injector.class); return new JUnitProbeInvoker(expr, ctx, injector); } }
@Override public ProbeInvoker createProbeInvoker(Object context, String expr) { BundleContext ctx = (BundleContext) context; Injector injector = ServiceLookup.getService(ctx, Injector.class); return new TestNGProbeInvoker(ctx, injector); } }
@Override public ProbeInvoker createProbeInvoker(Object context, String expr) { BundleContext ctx = (BundleContext) context; Injector injector = ServiceLookup.getService(ctx, Injector.class); return new JUnitProbeInvoker(ctx, injector); } }
private static void setupBundle( boolean start, int startLevel, BundleContext bundleContext, Bundle bundle ) throws BundleException { StartLevel sl = ServiceLookup.getService( bundleContext, StartLevel.class ); sl.setBundleStartLevel( bundle, startLevel ); if( start ) { bundle.start(); } }
@Override public void runTest(TestDescription description, TestListener listener) { BundleContext bundleContext = framework.getBundleContext(); ProbeInvoker probeInvokerService = ServiceLookup.getService(bundleContext, ProbeInvoker.class, determineExamServiceTimeout()); probeInvokerService.runTest(description, listener); }