in commons-jcs3-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCacheConfigurator.java [125:220]
protected <K, V> AuxiliaryCache<K, V> parseAuxiliary( final Properties props, final CompositeCacheManager ccm,
final String auxName, final String regName )
{
log.debug( "parseAuxiliary {0}", auxName );
// GET CACHE
AuxiliaryCache<K, V> auxCache = ccm.getAuxiliaryCache(auxName, regName);
if (auxCache == null)
{
// GET FACTORY
AuxiliaryCacheFactory auxFac = ccm.registryFacGet( auxName );
if ( auxFac == null )
{
// auxFactory was not previously initialized.
final String prefix = AUXILIARY_PREFIX + auxName;
auxFac = OptionConverter.instantiateByKey( props, prefix, null );
if ( auxFac == null )
{
log.error( "Could not instantiate auxFactory named \"{0}\"", auxName );
return null;
}
auxFac.setName( auxName );
if ( auxFac instanceof IRequireScheduler)
{
((IRequireScheduler)auxFac).setScheduledExecutorService(ccm.getScheduledExecutorService());
}
auxFac.initialize();
ccm.registryFacPut( auxFac );
}
// GET ATTRIBUTES
AuxiliaryCacheAttributes auxAttr = ccm.registryAttrGet( auxName );
final String attrName = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX;
if ( auxAttr == null )
{
// auxFactory was not previously initialized.
final String prefix = AUXILIARY_PREFIX + auxName + ATTRIBUTE_PREFIX;
auxAttr = OptionConverter.instantiateByKey( props, prefix, null );
if ( auxAttr == null )
{
log.error( "Could not instantiate auxAttr named \"{0}\"", attrName );
return null;
}
auxAttr.setName( auxName );
ccm.registryAttrPut( auxAttr );
}
auxAttr = auxAttr.clone();
log.debug( "Parsing options for \"{0}\"", attrName );
PropertySetter.setProperties( auxAttr, props, attrName + "." );
auxAttr.setCacheName( regName );
log.debug( "End of parsing for \"{0}\"", attrName );
// GET CACHE FROM FACTORY WITH ATTRIBUTES
auxAttr.setCacheName( regName );
final String auxPrefix = AUXILIARY_PREFIX + auxName;
// CONFIGURE THE EVENT LOGGER
final ICacheEventLogger cacheEventLogger =
AuxiliaryCacheConfigurator.parseCacheEventLogger( props, auxPrefix );
// CONFIGURE THE ELEMENT SERIALIZER
final IElementSerializer elementSerializer =
AuxiliaryCacheConfigurator.parseElementSerializer( props, auxPrefix );
// CONFIGURE THE KEYMATCHER
//IKeyMatcher keyMatcher = parseKeyMatcher( props, auxPrefix );
// TODO add to factory interface
// Consider putting the compositeCache back in the factory interface
// since the manager may not know about it at this point.
// need to make sure the manager already has the cache
// before the auxiliary is created.
try
{
auxCache = auxFac.createCache( auxAttr, ccm, cacheEventLogger, elementSerializer );
}
catch (final Exception e)
{
log.error( "Could not instantiate auxiliary cache named \"{0}\"", regName, e );
return null;
}
ccm.addAuxiliaryCache(auxName, regName, auxCache);
}
return auxCache;
}