/** * 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, "" ); }
/** * 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 ); }
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() ); }
Map<String, String> props ) ServiceTracker tracker = createServiceTracker( bc, className, props ); try
String filter ) ServiceTracker tracker = createServiceTracker( bc, className, filter ); try
/** * 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 ); }
Object service = ServiceLookup.getServiceByFilter( bc, filter ); Class<? extends Object> klass = service.getClass(); Method method;
String filter ) ServiceTracker tracker = createServiceTracker( bc, className, filter ); try
private static ServiceTracker createServiceTracker( BundleContext bc, String className, Map<String, String> props ) { if( props == null || props.isEmpty() ) { return new ServiceTracker( bc, className, null ); } StringBuilder builder = new StringBuilder( "(&(objectClass=" ); builder.append( className ); builder.append( ')' ); for( Entry<String, String> entry : props.entrySet() ) { builder.append( '(' ); builder.append( entry.getKey() ); builder.append( '=' ); builder.append( entry.getValue() ); builder.append( ')' ); } 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 * @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 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 ); }
/** * 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 ); }
public ProbeInvoker createProbeInvoker(Object context, String expr) { BundleContext ctx = (BundleContext) context; Injector injector = ServiceLookup.getService(ctx, Injector.class); return new JUnitProbeInvoker(expr, 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 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 ProbeInvoker createInvoker(BundleContext ctx) { String invokerType = System.getProperty("pax.exam.invoker"); if (invokerType == null) { throw new TestContainerException("System property pax.exam.invoker must be defined"); } else { Map<String, String> props = new HashMap<String, String>(); props.put("driver", invokerType); ProbeInvokerFactory factory = ServiceLookup.getService(ctx, ProbeInvokerFactory.class, props); return factory.createProbeInvoker(ctx, null); } }
@Override public Object remoteCall(final Class<?> serviceType, final String methodName, final Class<?>[] methodParams, String filter, final RelativeTimeout timeout, final Object... actualParams) throws NoSuchServiceException, NoSuchMethodException, IllegalAccessException, InvocationTargetException { LOG.trace("Remote call of [" + serviceType.getName() + "." + methodName + "]"); Object service = ServiceLookup.getService(bundleContext, serviceType, timeout.getValue(), filter); Object obj = null; try { obj = serviceType.getMethod(methodName, methodParams).invoke(service, actualParams); } catch (InvocationTargetException t) { if (t.getTargetException().getCause() instanceof RerunTestException) { LOG.debug("rerun the test"); service = ServiceLookup.getService(bundleContext, serviceType, timeout.getValue(), filter); obj = serviceType.getMethod(methodName, methodParams).invoke(service, actualParams); } else { throw t; } } return obj; }
public void setBundleStartLevel( long bundleId, int startLevel ) throws RemoteException, BundleException { BundleContext bc = framework.getBundleContext(); StartLevel sl = ServiceLookup.getService( bc, StartLevel.class ); Bundle bundle = bc.getBundle( bundleId ); sl.setBundleStartLevel( bundle, startLevel ); }