Question

I am familiar with Google Guice, at least with basics. I now use strategy pattern with annotations (answered here) to format messages based on target device.

I have an interface called MessageFormatter.

public interface MessageFormatter{
    public String format(String input);
}

I have many implementations of this interface. Basically those implementations format short messages based on target display - big screen, cell phone etc. A message is obtained from another server.

What I'd like to do is to SEND FORMATTERS FROM ONE SERVER TO ANOTHER. By sending formatters I mean sending implementations of MessageFormatter interface. I already know how to use reflection to load a class at runtime and use it.

What I need to do is to plug those implementations in at runtime, making the container aware of those new classes, injecting them instead of older ones. Is this possible with Google Guice ?

Was it helpful?

Solution

Guice has third party support for OSGi, which would allow using Guice to plug in services that are dynamically changing during runtime. There are OSGi containers that can monitor your file system for new bundles containing additional class files to load (e.g Apache Felix File Install).

Here is some additional resources

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top