Tag Archives: osgi

Whiteboard Registry

In OSGi using a publisher/subscriber design can be somewhat more complicated that traditional Java environments:

public class SomeBundleActivator implements BundleActivator {

private SomeService service = …

private ServiceRegistration registration;

public void start(BundleContext context) {
registration = context.registerService(SomeService.class.getName(), service, null);
}

}

public class AnotherBundleActivator implements BundleActivator {

private [...]

Posted in Java | Also tagged , , | Leave a comment

OSGi Service Locator

The Service Locator pattern is a well-established mechanism for accessing local and remote services in a consistent manner:

public interface ServiceLocator {

<T> T findService(String serviceName) throws ServiceNotAvailableException;
}

Using a structured service name interface we can improve uniformity and reduce the potential for typos:

public enum ServiceName {

SomeService("SomeService");

private final String filter;
[...]

Posted in Java | Also tagged , | 2 Comments