[jbosscache-dev] Consistent factory method

Brian Stansberry brian.stansberry at jboss.com
Fri Oct 27 12:03:29 EDT 2006


I prefer both ;-)  Perhaps add a class to o.j.c.factories that creates a
singleton DefaultCacheFactory and exposes static methods?  If people
don't want to use it, that's fine, but it's there for the 99.9% use
case.  An issue is what to name it.

Static is a bit easier to understand when using the MC as it eliminates
an extra bean instantiation.

Static:

<bean name="MyCacheConfig" class="org.jboss.cache.config.Configuration">

      ....
</bean>

<bean name="MyCache">	    
    <constructor factoryClass="org.jboss.cache.pojo.PojoCacheFactory"
factoryMethod="createInstance">
	<parameter class="org.jboss.cache.config.Configuration"><inject
bean="MyCacheConfig"/></parameter>
	<parameter>false</parameter>
    </constructor>
</bean>

Instance:

<bean name="MyCacheConfig" class="org.jboss.cache.config.Configuration">

      ....
</bean>
    
<bean name="MyCacheFactory" 
   		class="org.jboss.cache.factories.DefaultCacheFactory"/> 

<bean name="MyCache">
	    
    <constructor factoryMethod="createCache">
      <factory bean="MyCacheFactory"/>
	<parameter class="org.jboss.cache.config.Configuration"><inject
bean="MyCacheConfig"/></parameter>
	<parameter>false</parameter>
    </constructor>
</bean>


jbosscache-dev-bounces at lists.jboss.org wrote:
> Ic. So what do other people prefer, if we can do it either way?
> 
> -----Original Message-----
> From: Manik Surtani [mailto:msurtani at redhat.com]
> Sent: Thursday, October 26, 2006 9:17 PM
> To: Ben Wang
> Cc: jbosscache-dev at lists.jboss.org
> Subject: Re: [jbosscache-dev] Consistent factory method
> 
> Nothing more than the factory is a simple class.  If user
> code wants to wrap it in a singleton and create factory
> methods in the wrapper, it is up to them.  Just keeping things simple.
> 
> 
>> Manik,
>> 
>> This is a minor issue raised by Brian when he is constructing the
>> bean file for AS5. Currently, we have slight way of creating a cache
>> instance from the factory method.
>> 
>> In Cache, we do:
>> 
>>       CacheFactory factory = new DefaultCacheFactory();
>>       CacheSPI tree = (CacheSPI) factory.createCache(c, false);
>> 
>> While in PojoCache, we do:
>>       cache_ = PojoCacheFactory.createInstance(configFile, false);
>> 
>> Nothing wrong with both approaches but maybe we should be consistent
>> in both cache instances. And I don't mind to switch if needed. For
>> me, the reason that I did it in the first place is I don't forsee a
>> pluggable cache instance for PojoCache. And if needed, another
>> Factory can be used as well. 
>> 
>> I thought originally with your approach, there is more control over
>> the lifecycle methods. But now it is probably not needed there. Any
>> other reason to stick with your approach?
>> 
>> Thanks,
>> 
>> -Ben




More information about the jbosscache-dev mailing list