@Override public void componentOpened() { if(myServiceListener != null){ return; } BundleContext context = OSGiUtils.getBundleContext(ServoController.class); if(context == null){ return; } dynamixelControlLoopPanel1.initialize(context); }
public DescriptorBuilder with(String key, String value){ if(key == null || value == null){ throw new NullPointerException(); } myFilters.add(OSGiUtils.createFilter(key, value)); return this; }
public static String createIdFilter( String idPropertyName, String idString, String filter){ String idFilter = OSGiUtils.createServiceFilter(idPropertyName, idString); if(filter == null || filter.isEmpty()){ filter = idFilter; }else{ filter = "(&" + idFilter + filter + ")"; } return filter; }
public static Boolean serviceExists( BundleContext context, String clazz, Properties props){ String filter = createServiceFilter(props); return serviceExists(context, clazz, filter); }
/** * 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 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; }
@Override public void stopAll() { BundleContext context = OSGiUtils.getBundleContext(AnimationPlayer.class); if(context == null){ theLogger.log(Level.SEVERE, "Unable to find BundleContext for AnimationPlayer"); return; } ServiceReference ref = context.getServiceReference( RemoteAnimationPlayerClient.class.getName()); RemoteAnimationPlayerClient client = OSGiUtils.getService( RemoteAnimationPlayerClient.class, context, ref); if(client == null){ return; } client.stopAllAnimations(); } }
public DynamixelTracker(final OpenServoControlLoop osLoop){ BundleContext context = OSGiUtils.getBundleContext(ServoController.class); myTracker = new SingleServiceListener<ServoController>( ServoController.class, context, OSGiUtils.createFilter(ServoController.PROP_VERSION, DynamixelController.VERSION.toString())); myTracker.addPropertyChangeListener(SingleServiceListener.PROP_SERVICE_TRACKED, new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { DynamixelController controller = (DynamixelController)evt.getNewValue(); if(controller == null){ throw new IllegalArgumentException(); } DynamixelControlLoop loop = controller.getControlLoop(); if(loop == null){ throw new IllegalArgumentException(); } loop.setOpenServoLoop(osLoop); } }); myTracker.start(); }
confRefs = context.getAllServiceReferences( Configuration.class.getName(), OSGiUtils.createFilter( RKMessagingConfigUtils.JMS_CONNECTION_CONFIG, connectionConfigId)); OSGiUtils.getService(Configuration.class, context, conConfRef); String ip = conConf.getPropertyValue(String.class, ConnectionConfigUtils.CONF_BROKER_IP); Connection con = ConnectionManager.createConnection(
/** * 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 List<ServiceAddOnDriver> getAddOnDriverList( BundleContext context, ServiceReference[] refs){ if(context == null || refs == null){ throw new NullPointerException(); } List<ServiceAddOnDriver> drivers = new ArrayList<ServiceAddOnDriver>(); for(ServiceReference ref : refs){ ServiceAddOnDriver driver = OSGiUtils.getService( ServiceAddOnDriver.class, context, ref); if(driver == null){ continue; } drivers.add(driver); } return drivers; }
private void launchAnimationLibrary(BundleContext context, String libraryId){ theLogger.info("Launching AnimationLibrary Service."); AnimationLibrary library = new DefaultAnimationLibrary(libraryId); ServiceRegistration reg = OSGiUtils.registerService(context, AnimationLibrary.class.getName(), AnimationLibrary.PROP_ANIM_PLAYER_ID, libraryId, library, null); theLogger.info("AnimationLibrary Service Launched."); }
public static ServiceRegistration registerWavPlayer( BundleContext context, WavPlayer player, Properties props){ return OSGiUtils.registerUniqueService(context, WavPlayer.class.getName(), WavPlayer.PROP_WAV_PLAYER_ID, player.getWavPlayerId(), player, props); }
public static <T> SingleServiceListener<T> createIdServiceListener( Class<T> clazz, BundleContext context, String idPropertyName, String idString, String filter){ if(context == null || idPropertyName == null || idString == null){ throw new NullPointerException(); } filter = createIdFilter(idPropertyName, idString, filter); return new SingleServiceListener<T>(clazz, context, filter); }
@Override public void loop(){ BundleContext context = OSGiUtils.getBundleContext(AnimationPlayer.class); if(context == null){ theLogger.log(Level.SEVERE, "Unable to find BundleContext for AnimationPlayer"); return; } ServiceReference ref = context.getServiceReference(RemoteAnimationPlayerClient.class.getName()); RemoteAnimationPlayerClient client = OSGiUtils.getService(RemoteAnimationPlayerClient.class, context, ref); if(client == null){ return; } client.loopAnimation(getValue().getEnabledAnimation()); } }
regs[1] = registerAnimationEditListener(context, robot); regs[2] = registerJointSnapshotAdder(context, robotId); if(!OSGiUtils.serviceExists(context, RemoteAnimationPlayerClient.class, OSGiUtils.createFilter( AnimationPlayer.PROP_PLAYER_ID, robot.getRobotId().getRobtIdString()))){
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); }
private boolean track(ServiceReference ref){ if(ref == null){ throw new NullPointerException(); } if(ref.equals(myReference)){ return true; } T tracked = OSGiUtils.getService(myClass, myContext, ref); if(tracked == null){ return false; } T old = myTrackedClass; untrack(myReference); myReference = ref; myTrackedClass = tracked; firePropertyChange(PROP_SERVICE_TRACKED, old, myTrackedClass); return true; } }
private void launchAnimationLibrary(BundleContext context, String libraryId){ theLogger.info("Launching AnimationLibrary Service."); AnimationLibrary library = new DefaultAnimationLibrary(libraryId); ServiceRegistration reg = OSGiUtils.registerService(context, AnimationLibrary.class.getName(), AnimationLibrary.PROP_ANIM_PLAYER_ID, libraryId, library, null); theLogger.info("AnimationLibrary Service Launched."); }
private static ServiceRegistration registerAnimationPlayer( BundleContext context, Robot.Id robotId){ AnimationPlayer player = new RampedAnimationPlayer( context, robotId, DEFAULT_MAX_RAMP_TIME_MILLISEC); Properties props = new Properties(); String playerId = player.getAnimationPlayerId(); props.put(Robot.PROP_ID, robotId.toString()); ServiceRegistration reg = OSGiUtils.registerUniqueService(context, AnimationPlayer.class.getName(), AnimationPlayer.PROP_PLAYER_ID, playerId, player, props); theLogger.log(Level.INFO, "OSGiAnimationPlayer Service Registered Successfully."); return reg; }