Monthly Archives: September 2009

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 | Tagged , , | 2 Comments

Uniform Logging

Application logging always seems to become one of those code smells, typically regarding duplication of code, or conversely, non-uniform log messages.
There are many different ways to log a message in Java, but variations on the following pattern are common:

public class SomeClass {

private static final Log LOG = LogFactory.getLog(SomeClass.class);

public [...]

Posted in Java | Tagged , , | Leave a comment