A small wrapper around org.osgi.util.tracker.ServiceTracker that opens it once on first access and closes it when the OSGi bundle stops.
Example:
public class Activator implements BundleActivator {
private volatile static TrackerRegister register;
@Override
public void start(BundleContext context) throws Exception {
register = new TrackerRegister(context);
}
@Override
public void stop(BundleContext context) throws Exception {
register.close();
}
public static TrackerRegister getRegister()
{
return register;
}
}
[...]
public class SomeWhere
{
public void foo(String[] args)
{
SomeType service = Activator.getRegister().getService(SomeType.class);
service.bar();
}
}