[hibernate-dev] [HSearch] ServiceManager and services

Hardy Ferentschik hardy at hibernate.org
Mon Oct 15 12:19:58 EDT 2012


On 12 Jan 2012, at 5:29 PM, Emmanuel Bernard wrote:

> On Fri 2012-10-12 15:13, Hardy Ferentschik wrote:
>> 
>> On 12 Jan 2012, at 3:00 PM, Steve Ebersole wrote:
>> 
>>> "Java services api" == ServiceLoader I assume?
>> 
>> correct 
>> 
>>> Going on that assumption:
>>> 
>>> No.  ServiceLoader is just a discovery mechanism.  There still needs to be something that, as you say, negotiates amongst the various discovered implementations of a particular service.  2 well known ServiceLoader uses are JDBC drivers and image processors, each illustrating a different approach that are really inherent to their respective problem domains.  In the case of JDBC drivers, the discovery is just used to register all the available drivers; users must still specify which driver they want via JDBC url protocol.  In the case of image processing (as I understand it anyway, not really my forte) the choice of processor is more intrinsic to the image you ask to have processed based on MIME type.
>>> 
>>> Here is sound like you more have the JDBC style, where discovery is just making the complete set of possibilities known.  The user would still need to make a distinction.  Or maybe you have some special rules like (a) using the standard service if it is the only one discovered; (b) using the "other" service if 2 are discovered; (c) requiring the user tell you if 3 or more are found. Many ways to skin that cat.
>> 
>> Right. I would expect the user to make this distinction via the configuration. 
>> 
>> I think really the problem is that what we have is actually not a ServiceManager (at least not what I understand under this term). It is a fancy way to instantiating a class and giving it a life cycle (aka #start(), #stop()).
>> We really have more of a BeanLifeCycleManager. 
> 
> Basically for you a Service must allow for multiple implementations
> and a ServiceManager must offer a way to switch between various
> implementations.

I orientate myself in this case at the ServiceLoader docs (especially since we are using this mechanism as well) which says:
"A service is a well-known set of interfaces and (usually abstract) classes. A service provider is a specific implementation of a service."

What I am saying is that by calling it a ServiceManager and by using the ServiceLoader API I have a certain expectation on how things 
will work. I would have expected that each of the services has its own service file and that we determine the service to use by using the 
Service Loader API + some config code.

> I don't see how renaming this class a BeanLifeCycleManager makes any of
> this better.

Just trying to avoid wrong expectations.

--Hardy




More information about the hibernate-dev mailing list