/** * Creates a new OSGiFrameSourceTracker which tracks services registered * under the given class name. * @param className fully qualified name of the FrameSource class to track */ public OSGiFrameSourceTracker(String className){ myTracker = new ClassTracker(className); }
/** * Initializes the tracking to begin tracking FrameSources. * @param context BundleContext to use for tracking. * @param filter FrameSource service property filter string * @return true if successful */ public boolean init(BundleContext context, String filter){ myTracker.setContext(context); myTracker.setFilter(filter); return myTracker.init(); }
/** * Creates a new tracker for the given class, and begins tracking. * There is no need to call init() * @param className name of the class to track */ public ClassTracker(BundleContext context, String className, String filter) throws IllegalArgumentException{ construct(context, className, filter, null); } /**
private void construct(BundleContext context, String className, String filter, ServiceTrackerCustomizer customizer) throws IllegalArgumentException{ myContext = context; setTrackedClassName(className); myFilter = filter; myCustomizer = customizer; if(init()){ return; } String filterMsg = (filter == null || filter.isEmpty()) ? "" : ", Filter: " + filter; String custMsg = customizer == null ? "" : ", Customizer: " + customizer; throw new IllegalArgumentException( "Unable to initialize ServiceTracker from given arguments." + " BundleContext: " + context + ", ClassName: " + className + filterMsg + custMsg + "."); }
/** * Creates a new tracker for the given class. init() must be called before * the ClassTracker begins tracking. * @param className name of the class to track */ public ClassTracker(String className){ setTrackedClassName(className); }
@Override public List<FrameSource> getSources() { if(myTracker == null){ return null; } return myTracker.getServices(); }
public Robot getRobot(){ ClassTracker<Robot> tracker = getRobotTracker(); return tracker == null ? null : tracker.getTopService(); }
public static <C> ClassTracker<C> build(Class<C> clazz, Properties props){ String filter = OSGiUtils.createServiceFilter(props); return build(clazz, filter); }
private ClassTracker<Robot> getRobotTracker(){ if(myRobotTracker != null){ return myRobotTracker; } myRobotTracker = new ClassTracker<Robot>(myContext, Robot.class.getName(),null,null); return myRobotTracker; }
/** * Creates a new tracker for the given class, and begins tracking. * There is no need to call init() * @param className name of the class to track */ public ClassTracker(BundleContext context, String className, String filter, ServiceTrackerCustomizer customizer) throws IllegalArgumentException{ construct(context, className, filter, customizer); }
/** * Creates a new OSGiFrameSourceTracker. */ public OSGiFrameSourceTracker(){ myTracker = new ClassTracker(FrameSource.class.getName()); }
public static <C> ClassTracker<C> build(Class<C> clazz, String filter){ if(clazz == null){ throw new NullPointerException(); } BundleContext context = OSGiUtils.getBundleContext(clazz); if(context == null){ theLogger.log(Level.WARNING, "Could not find BundleContext for {0}", clazz); return null; } ClassTracker<C> tracker = new ClassTracker<C>( context, clazz.getName(), filter); return tracker; }