[hibernate-dev] [HSearch] ServiceManager and services

Hardy Ferentschik hardy at hibernate.org
Fri Oct 12 08:23:33 EDT 2012


Hi,

as part of my investigations for HSEARCH-1025 and HSEARCH-1026 I had a look at how services are implemented in Search.
I thought I could make the statistics collector also a service. Looking at the code I am a little confused though.

Let's look at the different pieces.

First ServiceManager:

public interface ServiceManager {

	public abstract <T> T requestService(Class<? extends ServiceProvider<T>> serviceProviderClass, BuildContext context);

	public abstract void releaseService(Class<? extends ServiceProvider<?>> serviceProviderClass);

	public abstract void stopServices();

}

And now one service example:

public class JGroupsChannelProvider implements ServiceProvider<MessageSender> {
…
}

And one usage:

this.messageSender = serviceManager.requestService( JGroupsChannelProvider.class, context );

Now, I am wondering how this is a configurable service implementation. Whenever I request a "service" I specify a concrete implementation.
How is that different to hard coded things or using some properties to specify the impl class. Really the service in the above case is the interface
MessageSender and that's what I should request as a service. 

Which leads me to the second point, the service discovery. For that we use META-INF/services/org.hibernate.search.spi.ServiceProvider where we list
the ServiceProvider implementation we use. How, could I as user e.g. replace the serialization service to use something else than Avro? 
I guess in this case the user adds to its jar also META-INF/services/org.hibernate.search.spi.ServiceProvider specifying his implementation class, but
then there must be some code which negotiates which implementation to chose, right? That's how I would expect it to work using the Java services api.

Or maybe ServiceManager is not what I think a ServiceManager should be!?
What am I missing?

--Hardy




More information about the hibernate-dev mailing list