[infinispan-dev] Marshaller implementation discovery

David M. Lloyd david.lloyd at redhat.com
Mon Dec 27 18:08:08 EST 2010


Sanne Grinovero asked me to drop a quick note about the API used to 
discover JBoss Marshalling implementations.  Since 1.2.0.GA, you can use 
the org.jboss.marshalling.Marshalling class methods to locate protocol 
implementations without involving a hard dependency in your sources.

I've heard that Infinispan uses this pattern to load the implementation 
class:

(MarshallerFactory) 
Thread.currentThread().getContextClassLoader().loadClass("org.jboss.marshalling.river.RiverMarshallerFactory").newInstance();

This is a bit kludgey though and is considerably more complex than just 
doing:

Marshaller.getMarshallerFactory("river");

which uses the java.util.ServiceLoader API to locate and instantiate the 
appropriate implementation class, also using the TCCL, and should be 
functionally equivalent (yet quite a bit cleaner) to the former.
-- 
- DML


More information about the infinispan-dev mailing list