Tag Archives: proxy

Service Selector

Sometimes we may have more than one implementation and/or instance of a service to which we need to route requests. Routing may be controlled by a number of different factors, such as the request type, request arguments, runtime configuration, etc.

An implementation of such routing might look something like this:

[java]
public interface SomeService {
void someMethod();
}

public class RoutingSomeService implements SomeService {

private Map delegates = …

private String activeDelegateId = …

public void someMethod() {
SomeService delegate = delegates.get(activeDelegateId);
if (delegate != null) {
delegate.someMethod();
}
else {
// XXX: throw runtime exception???
}
}
}
[/java]

Posted in Java | Also tagged | Leave a comment