org.objectledge.cache
Class DefaultCacheFactory

java.lang.Object
  extended by org.objectledge.cache.DefaultCacheFactory
All Implemented Interfaces:
CacheFactory, CacheFactorySPI

public class DefaultCacheFactory
extends Object
implements CacheFactorySPI, CacheFactory

DefaultCacheFactory component.

An instance declaration is a list of map layer declarations. A map layer declaration is composed of a map type name (both standard and custom types may be used) and a pair of parentheses. Optional configuration string may be placed betweene the parens. The meaning of the string is depenant upon the implementation class. If there is a non-empty configuration string, the map implementation is required to support ConfigurableMap interface. Layers declared first are the deeper than those declared later. The implemenation of map types used on layers deeper than layer one are required to support LayeredMap interface. The layer number n becomes the delegate of the layer n+1.

Version:
$Id: DefaultCacheFactory.java,v 1.4 2006/02/08 18:19:56 zwierzem Exp $
Author:
Rafal Krzewski

Nested Class Summary
private  class DefaultCacheFactory.DelayedUpdateTask
          The task that performs delayed updates.
 
Field Summary
private  org.jcontainer.dna.Configuration config
          The configuration
static String DISTRIBUTED_MAP_CLASS_DEFALUT
          The default implementation DistributedMap implementation.
static String DISTRIBUTED_MAP_TYPE
          Type constant for DistributedMap.
static String FACTORY_MAP_CLASS_DEFALUT
          The default implementation FactoryMap implementation.
static String FACTORY_MAP_TYPE
          Type constant for FactoryMap.
private  Map<String,org.jcontainer.dna.Configuration> factoryConfigurations
          Factory configurations
static String FORGETFULL_MAP_CLASS_DEFALUT
          The default implementation StatisticsMap implementation.
static String FORGETFULL_MAP_TYPE
          Type constant for ForgetFullMap.
static String HASH_MAP_CLASS_DEFALUT
          The default implementation HashMap implementation.
static String HASH_MAP_TYPE
          Type constant for HashMap.
private  Map<String,Class> implClasses
          Mapping of *_TYPE constants into configured implementation classes.
private  Map<String,org.jcontainer.dna.Configuration> instanceConfigurations
          instance prepared configurations map.
private  Map<String,Map> instances
          Configured map instances.
private  org.jcontainer.dna.Logger logger
          The logging facility.
static String LRU_MAP_CLASS_DEFALUT
          The default implementation LRUMap implementation.
static String LRU_MAP_TYPE
          Type constant for LRUMap.
private  Notification notification
          The notification
private  Persistence persistence
          The persistence
private  SortedMap<Long,Set<DelayedUpdate>> queue
          DelayedUpdate queue (target update time -> object)
private  Map<DelayedUpdate,Long> queueHelper
          DelayedUpdate queue helper map (object -> target update time)
static String SOFT_MAP_CLASS_DEFALUT
          The default implementation SoftMap implementation.
static String SOFT_MAP_TYPE
          Type constant for SoftMap.
private  List<StatisticsMap> statistics
          The registered StatisticsMaps
static String STATISTICS_MAP_CLASS_DEFALUT
          The default implementation StatisticsMap implementation.
static String STATISTICS_MAP_TYPE
          Type constant for StatisticsMap.
private  ThreadPool threadPool
          The thread pool
static String TIMEOUT_MAP_CLASS_DEFALUT
          The default implementation TimeoutMap implementation.
static String TIMEOUT_MAP_TYPE
          Type constant for TimeoutMap.
 
Constructor Summary
DefaultCacheFactory(org.jcontainer.dna.Configuration config, org.jcontainer.dna.Logger logger, ThreadPool threadPool, Notification notification, Persistence persistence)
          Component constructor.
 
Method Summary
 void addStatisticsMap(StatisticsMap map)
          Adds an statistics map the the service's registry.
private  Map buildInstance(String name, org.jcontainer.dna.Configuration conf)
          Creates a new configurable map instance.
 DistributedMap getDistributedMap(String name, Map delegate)
          
 Map getFactoryMap(ValueFactory factory, Map delegate)
          
 Map getHashMap()
          
 Map getInstance(String name)
          
 Map getInstance(String name, String configAlias)
          
 Map getLRUMap(int capacity)
          
 Map getMap(String type)
          Get the map.
 Notification getNotification()
          Get the notification system.
 Persistence getPersistence()
          Get the persistence system.
 ValueFactory getPersitenceValueFactory(Class valueClass)
          
 Map getSoftMap(int protect)
          
 Map getStatisticsMap(String name, Map delegate)
          
 void getStatus(PrintWriter out)
          Prints the report on the specified PrintWriter.
 Map getTimeoutMap(long timeoutMillis)
          
 ValueFactory getValueFactory(String factory, String map)
          
private  void initImpl(String type, String className, Class iface)
          Initializes an entry in the implClasses map.
 void register(DelayedUpdate object)
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HASH_MAP_TYPE

public static final String HASH_MAP_TYPE
Type constant for HashMap.

See Also:
Constant Field Values

TIMEOUT_MAP_TYPE

public static final String TIMEOUT_MAP_TYPE
Type constant for TimeoutMap.

See Also:
Constant Field Values

LRU_MAP_TYPE

public static final String LRU_MAP_TYPE
Type constant for LRUMap.

See Also:
Constant Field Values

SOFT_MAP_TYPE

public static final String SOFT_MAP_TYPE
Type constant for SoftMap.

See Also:
Constant Field Values

FACTORY_MAP_TYPE

public static final String FACTORY_MAP_TYPE
Type constant for FactoryMap.

See Also:
Constant Field Values

DISTRIBUTED_MAP_TYPE

public static final String DISTRIBUTED_MAP_TYPE
Type constant for DistributedMap.

See Also:
Constant Field Values

STATISTICS_MAP_TYPE

public static final String STATISTICS_MAP_TYPE
Type constant for StatisticsMap.

See Also:
Constant Field Values

FORGETFULL_MAP_TYPE

public static final String FORGETFULL_MAP_TYPE
Type constant for ForgetFullMap.

See Also:
Constant Field Values

HASH_MAP_CLASS_DEFALUT

public static final String HASH_MAP_CLASS_DEFALUT
The default implementation HashMap implementation.

See Also:
Constant Field Values

TIMEOUT_MAP_CLASS_DEFALUT

public static final String TIMEOUT_MAP_CLASS_DEFALUT
The default implementation TimeoutMap implementation.

See Also:
Constant Field Values

LRU_MAP_CLASS_DEFALUT

public static final String LRU_MAP_CLASS_DEFALUT
The default implementation LRUMap implementation.

See Also:
Constant Field Values

SOFT_MAP_CLASS_DEFALUT

public static final String SOFT_MAP_CLASS_DEFALUT
The default implementation SoftMap implementation.

See Also:
Constant Field Values

DISTRIBUTED_MAP_CLASS_DEFALUT

public static final String DISTRIBUTED_MAP_CLASS_DEFALUT
The default implementation DistributedMap implementation.

See Also:
Constant Field Values

FACTORY_MAP_CLASS_DEFALUT

public static final String FACTORY_MAP_CLASS_DEFALUT
The default implementation FactoryMap implementation.

See Also:
Constant Field Values

STATISTICS_MAP_CLASS_DEFALUT

public static final String STATISTICS_MAP_CLASS_DEFALUT
The default implementation StatisticsMap implementation.

See Also:
Constant Field Values

FORGETFULL_MAP_CLASS_DEFALUT

public static final String FORGETFULL_MAP_CLASS_DEFALUT
The default implementation StatisticsMap implementation.

See Also:
Constant Field Values

statistics

private List<StatisticsMap> statistics
The registered StatisticsMaps


implClasses

private Map<String,Class> implClasses
Mapping of *_TYPE constants into configured implementation classes.


instanceConfigurations

private Map<String,org.jcontainer.dna.Configuration> instanceConfigurations
instance prepared configurations map.


factoryConfigurations

private Map<String,org.jcontainer.dna.Configuration> factoryConfigurations
Factory configurations


instances

private Map<String,Map> instances
Configured map instances.


queue

private SortedMap<Long,Set<DelayedUpdate>> queue
DelayedUpdate queue (target update time -> object)


queueHelper

private Map<DelayedUpdate,Long> queueHelper
DelayedUpdate queue helper map (object -> target update time)


config

private org.jcontainer.dna.Configuration config
The configuration


logger

private org.jcontainer.dna.Logger logger
The logging facility.


threadPool

private ThreadPool threadPool
The thread pool


notification

private Notification notification
The notification


persistence

private Persistence persistence
The persistence

Constructor Detail

DefaultCacheFactory

public DefaultCacheFactory(org.jcontainer.dna.Configuration config,
                           org.jcontainer.dna.Logger logger,
                           ThreadPool threadPool,
                           Notification notification,
                           Persistence persistence)
                    throws org.jcontainer.dna.ConfigurationException,
                           ClassNotFoundException
Component constructor.

Parameters:
config - the configuration.
logger - the logger.
threadPool - the thread pool.
notification - the notification.
persistence - the persistence.
Throws:
org.jcontainer.dna.ConfigurationException - thrown if configuration is invalid.
ClassNotFoundException - thrown if one of the class not found.
Method Detail

getMap

public Map getMap(String type)
Get the map.

Specified by:
getMap in interface CacheFactory
Parameters:
type - the type.
Returns:
the map.

getInstance

public Map getInstance(String name)

Specified by:
getInstance in interface CacheFactory

getInstance

public Map getInstance(String name,
                       String configAlias)
                throws org.jcontainer.dna.ConfigurationException

Specified by:
getInstance in interface CacheFactory
Throws:
org.jcontainer.dna.ConfigurationException

getValueFactory

public ValueFactory getValueFactory(String factory,
                                    String map)

Specified by:
getValueFactory in interface CacheFactory

getHashMap

public Map getHashMap()

Specified by:
getHashMap in interface CacheFactory

getTimeoutMap

public Map getTimeoutMap(long timeoutMillis)

Specified by:
getTimeoutMap in interface CacheFactory

getLRUMap

public Map getLRUMap(int capacity)

Specified by:
getLRUMap in interface CacheFactory

getSoftMap

public Map getSoftMap(int protect)

Specified by:
getSoftMap in interface CacheFactory

getDistributedMap

public DistributedMap getDistributedMap(String name,
                                        Map delegate)

Specified by:
getDistributedMap in interface CacheFactory

getFactoryMap

public Map getFactoryMap(ValueFactory factory,
                         Map delegate)

Specified by:
getFactoryMap in interface CacheFactory

getStatisticsMap

public Map getStatisticsMap(String name,
                            Map delegate)

Specified by:
getStatisticsMap in interface CacheFactory

getPersitenceValueFactory

public ValueFactory getPersitenceValueFactory(Class valueClass)

Specified by:
getPersitenceValueFactory in interface CacheFactory

register

public void register(DelayedUpdate object)

Specified by:
register in interface CacheFactory

getStatus

public void getStatus(PrintWriter out)
Prints the report on the specified PrintWriter.

Specified by:
getStatus in interface CacheFactory
Parameters:
out - the PrintWriter to print report into.

addStatisticsMap

public void addStatisticsMap(StatisticsMap map)
Adds an statistics map the the service's registry.

Specified by:
addStatisticsMap in interface CacheFactorySPI
Parameters:
map - the map

getNotification

public Notification getNotification()
Get the notification system.

Specified by:
getNotification in interface CacheFactorySPI
Returns:
the notification system.

getPersistence

public Persistence getPersistence()
Get the persistence system.

Specified by:
getPersistence in interface CacheFactorySPI
Returns:
the persistence.

initImpl

private void initImpl(String type,
                      String className,
                      Class iface)
               throws ClassNotFoundException
Initializes an entry in the implClasses map.

Parameters:
type - the map type.
className - the implementation class name.
iface - the interface the implementation class must support.
Throws:
ClassNotFoundException - if class couldn't be found.

buildInstance

private Map buildInstance(String name,
                          org.jcontainer.dna.Configuration conf)
                   throws org.jcontainer.dna.ConfigurationException
Creates a new configurable map instance.

Parameters:
name - instance's name.
conf - inststance's configuration elements.
Throws:
org.jcontainer.dna.ConfigurationException


Copyright © 2003-2006 objectledge.org. All Rights Reserved.