/** * Checks the OSGi Service Registry for a Service with the given class and * matching the given filter. Returns true if a matching ServiceReference is * found, return null if there is an InvalidSyntaxException. * @param context BundleContext to use * @param clazz Class to match * @param filter OSGi Service filter String * @return true if a matching ServiceReference is found, returns null if * there is an InvalidSyntaxException */ public static Boolean serviceExists( BundleContext context, Class clazz, String filter){ return serviceExists(context, clazz.getName(), filter); }
public static Boolean serviceExists(BundleContext context, String clazz, String idPropertyName, String idString, Properties props){ if(props == null){ props = new Properties(); } props.put(idPropertyName, idString); return serviceExists(context, clazz, props); }
public static Boolean serviceExists( BundleContext context, String clazz, Properties props){ String filter = createServiceFilter(props); return serviceExists(context, clazz, filter); }
/** * Checks the OSGi Service Registry for an existing Service matching the * given filter String and one or more of the given Class names. * @param context BundleContext to use * @param classes one or more of the class names must be matched * @param filter OSGi Service filter String to match * @return true if a ServiceReference is found matching one or more of the * given classes and the filter String, return null if there is an * InvalidSyntaxException */ public static Boolean serviceExists( BundleContext context, String[] classes, String filter) { for(String c : classes){ Boolean b = serviceExists(context, c, filter); if(b == null){//InvalidSyntaxException return null; }else if(!b){ continue; }else if(b){ theLogger.log(Level.INFO, "Found existing Service: {0}, matching {1}.", new Object[]{c, filter}); return true; } }theLogger.log(Level.INFO, "No existing Service matching {0} with class {1}.", new Object[]{filter, Arrays.toString(classes)}); return false; }
private boolean uniquePropertiesAvailable(){ if(myUniqueProperties == null){ return true; } for(Entry e : myUniqueProperties.entrySet()){ String key = e.getKey().toString(); String val = e.getValue().toString(); String filter = OSGiUtils.createFilter(key, val); if(OSGiUtils.serviceExists( myContext, myRegistrationClassNames, filter)){ getLogger().warn("Unique service property already in use: ({}={}).", key, val); return false; } } return true; }
public static ServiceRegistration registerRobotAnimationPlayer( BundleContext context, Robot.Id robotId){ Boolean exists = OSGiUtils.serviceExists( context, AnimationPlayer.class.getName(), RobotUtils.getRobotFilter(robotId)); if(exists == null || exists){ return null; } return registerAnimationPlayer(context, robotId); }
/** * Registers the given service only if a service does not exist with the * given id. Returns the ServiceRegistration, or null if a service exists. * @param context * @param className * @param idPropertyName * @param idString * @param service * @param serviceProperties * @return the ServiceRegistration, or null if a service exists */ public static ServiceRegistration registerUniqueService( BundleContext context, String className, String idPropertyName, String idString, Object service, Properties serviceProperties){ if(context == null || service == null){ throw new NullPointerException(); } if(serviceExists(context, className, idPropertyName, idString, null)){ theLogger.log(Level.WARNING, "Service already exists with Id: {0}={1}", new Object[]{idPropertyName,idString}); return null; } return registerService(context, className, idPropertyName, idString, service, serviceProperties); }
private void registerSignalFactory(BundleContext context){ if(OSGiUtils.serviceExists( context, AnimationSignal.AnimationSignalFactory.class, null)){ return; } new OSGiComponent(context, new SimpleLifecycle( new PortableAnimationSignal.Factory(), AnimationSignal.AnimationSignalFactory.class) ).start(); } }
private static void registerEventFactory(BundleContext context){ if(OSGiUtils.serviceExists(context, AnimationEvent.AnimationEventFactory.class, null)){ return; } new OSGiComponent(context, new SimpleLifecycle( new PortableAnimationEvent.Factory(), AnimationEventFactory.class) ).start(); }
regs[1] = registerAnimationEditListener(context, robot); regs[2] = registerJointSnapshotAdder(context, robotId); if(!OSGiUtils.serviceExists(context, RemoteAnimationPlayerClient.class, OSGiUtils.createFilter( AnimationPlayer.PROP_PLAYER_ID,