org.jboss.cache.pojo.impl
Class PojoCacheImpl

java.lang.Object
  extended by org.jboss.cache.pojo.impl.PojoCacheImpl
All Implemented Interfaces:
PojoCache

public class PojoCacheImpl
extends java.lang.Object
implements PojoCache

Implementation class for PojoCache interface

Version:
$Id: PojoCacheImpl.java,v 1.12 2007/06/29 04:34:01 jgreene Exp $
Author:
Ben Wang

Field Summary
protected  org.apache.commons.logging.Log log_
           
 
Constructor Summary
PojoCacheImpl(Configuration config, boolean toStart)
           
PojoCacheImpl(java.lang.String configStr, boolean toStart)
           
 
Method Summary
 java.lang.Object _evictObject(Fqn fqn)
          Used by internal implementation.
 void addListener(java.lang.Object listener)
           Add a PojoCache listener.
 void addListener(java.lang.Object listener, java.util.regex.Pattern pattern)
           Add a PojoCache listener that will only monitor a specific ID(FQN) pattern.
 java.lang.Object attach(Fqn id, java.lang.Object pojo)
           
 java.lang.Object attach(Fqn id, java.lang.Object pojo, java.lang.String field)
           
 java.lang.Object attach(java.lang.String id, java.lang.Object pojo)
          Attach a POJO into PojoCache.
 void create()
          Lifecycle method to start PojoCache.
 void destroy()
          Lifecycle method to destroy PojoCache.
 java.lang.Object detach(Fqn id)
           
 java.lang.Object detach(Fqn id, java.lang.String field)
           
 java.lang.Object detach(java.lang.String id)
          Remove POJO object from the cache.
 java.lang.Object find(Fqn id)
           
 java.lang.Object find(java.lang.String id)
          Retrieve POJO from the cache system.
 java.util.Map findAll(Fqn id)
           
 java.util.Map findAll(java.lang.String id)
          Query all managed POJO objects under the id recursively.
 Cache<java.lang.Object,java.lang.Object> getCache()
          Obtain the underlying generic cache system.
 CachedType getCachedType(java.lang.Class clazz)
          Obtain a cache aop type for user to traverse the defined "primitive" types in aop.
 CacheSPI getCacheSPI()
           
 java.util.Collection<java.lang.Object> getListeners()
          Retrieve a read-only list of listeners.
 java.lang.Object getObject(Fqn id)
           
 java.lang.Object getObject(Fqn id, java.lang.String field)
           
 java.lang.String getPojoID(java.lang.Object pojo)
          Return the POJO id that is associated with PojoCache.
 java.lang.String getVersion()
           
 java.lang.Object putObject(Fqn id, java.lang.Object pojo, java.lang.String field)
          This public API is called from internal package only.
 void removeListener(java.lang.Object listener)
          Remove the specific listener.
 java.lang.Object removeObject(Fqn id, java.lang.String field)
           
 void start()
          Lifecycle method to start PojoCache.
 void stop()
          Lifecycle method to stop PojoCache.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

log_

protected final org.apache.commons.logging.Log log_
Constructor Detail

PojoCacheImpl

public PojoCacheImpl(java.lang.String configStr,
                     boolean toStart)

PojoCacheImpl

public PojoCacheImpl(Configuration config,
                     boolean toStart)
Method Detail

getCacheSPI

public CacheSPI getCacheSPI()

attach

public java.lang.Object attach(java.lang.String id,
                               java.lang.Object pojo)
                        throws PojoCacheException
Description copied from interface: PojoCache

Attach a POJO into PojoCache. It will also recursively put any sub-POJO into the cache system. A POJO can be the following and have the consqeuences when attached:

  • it is Replicable, that is, it has been annotated with @org.jboss.cache.pojo.annotation.Replicable annotation (or via XML), and has been "instrumented" either compile- or load-time. The POJO will be mapped recursively to the system and fine-grained replication will be performed.
  • It is Serializable. The POJO will still be stored in the cache system. However, it is treated as an "opaque" object per se. That is, the POJO will neither be intercepted (for fine-grained operation) or object relantionship will be maintained.
  • Neither of above. In this case, a user can specify whether it wants this POJO to be stored (e.g., replicated or persistent). If not, a PojoCacheException will be thrown.
  • Specified by:
    attach in interface PojoCache
    Parameters:
    id - An id String to identify the object in the cache. To promote concurrency, we recommend the use of hierarchical String separating by a designated separator. Default is "/" but it can be set differently via a System property, jbosscache.separator in the future release. E.g., "ben", or "student/joe", etc.
    pojo - object to be inerted into the cache. If null, it will nullify the fqn node.
    Returns:
    Existing POJO or null if there is none.
    Throws:
    PojoCacheException - Throws if there is an error related to the cache operation.

    attach

    public java.lang.Object attach(Fqn id,
                                   java.lang.Object pojo)
                            throws PojoCacheException
    Throws:
    PojoCacheException

    attach

    public java.lang.Object attach(Fqn id,
                                   java.lang.Object pojo,
                                   java.lang.String field)
                            throws PojoCacheException
    Throws:
    PojoCacheException

    putObject

    public java.lang.Object putObject(Fqn id,
                                      java.lang.Object pojo,
                                      java.lang.String field)
                               throws CacheException
    This public API is called from internal package only.

    Throws:
    CacheException

    detach

    public java.lang.Object detach(java.lang.String id)
                            throws PojoCacheException
    Description copied from interface: PojoCache
    Remove POJO object from the cache.

    Specified by:
    detach in interface PojoCache
    Parameters:
    id - Is string that associates with this node.
    Returns:
    Original value object from this node.
    Throws:
    PojoCacheException - Throws if there is an error related to the cache operation.

    detach

    public java.lang.Object detach(Fqn id,
                                   java.lang.String field)
                            throws PojoCacheException
    Throws:
    PojoCacheException

    detach

    public java.lang.Object detach(Fqn id)
                            throws PojoCacheException
    Throws:
    PojoCacheException

    removeObject

    public java.lang.Object removeObject(Fqn id,
                                         java.lang.String field)
                                  throws CacheException
    Throws:
    CacheException

    getPojoID

    public java.lang.String getPojoID(java.lang.Object pojo)
    Description copied from interface: PojoCache
    Return the POJO id that is associated with PojoCache. Note that if a POJO has not yet attached to the cache system, it will simply return null.

    Specified by:
    getPojoID in interface PojoCache
    Parameters:
    pojo - The POJO that is attached to PojoCache.
    Returns:
    String ID. Null if not existed.

    find

    public java.lang.Object find(java.lang.String id)
                          throws PojoCacheException
    Description copied from interface: PojoCache
    Retrieve POJO from the cache system. Return null if object does not exist in the cache. Note that this operation is fast if there is already a POJO instance attached to the cache.

    Specified by:
    find in interface PojoCache
    Parameters:
    id - that associates with this node.
    Returns:
    Current content value. Null if does not exist.
    Throws:
    PojoCacheException - Throws if there is an error related to the cache operation.

    find

    public java.lang.Object find(Fqn id)
                          throws PojoCacheException
    Throws:
    PojoCacheException

    getObject

    public java.lang.Object getObject(Fqn id)
                               throws CacheException
    Throws:
    CacheException

    getObject

    public java.lang.Object getObject(Fqn id,
                                      java.lang.String field)
                               throws CacheException
    Throws:
    CacheException

    findAll

    public java.util.Map findAll(java.lang.String id)
                          throws PojoCacheException
    Description copied from interface: PojoCache
    Query all managed POJO objects under the id recursively. Note that this will not return the sub-object POJOs, e.g., if Person has a sub-object of Address, it won't return Address pojo. Also note also that this operation is not thread-safe now. In addition, it assumes that once a POJO is found with a id, no more POJO is stored under the children of the id. That is, we don't mix the id with different POJOs.

    Specified by:
    findAll in interface PojoCache
    Parameters:
    id - The starting place to find all POJOs.
    Returns:
    Map of all POJOs found with (id, POJO) pair. Return size of 0, if not found.
    Throws:
    PojoCacheException - Throws if there is an error related to the cache operation.

    findAll

    public java.util.Map findAll(Fqn id)
                          throws PojoCacheException
    Throws:
    PojoCacheException

    getVersion

    public java.lang.String getVersion()

    create

    public void create()
                throws PojoCacheException
    Description copied from interface: PojoCache
    Lifecycle method to start PojoCache.

    Specified by:
    create in interface PojoCache
    Throws:
    PojoCacheException

    start

    public void start()
               throws PojoCacheException
    Description copied from interface: PojoCache
    Lifecycle method to start PojoCache.

    Specified by:
    start in interface PojoCache
    Throws:
    PojoCacheException

    stop

    public void stop()
              throws PojoCacheException
    Description copied from interface: PojoCache
    Lifecycle method to stop PojoCache. Note that PojoCache can be stopped and started repeatedly.

    Specified by:
    stop in interface PojoCache
    Throws:
    PojoCacheException

    destroy

    public void destroy()
                 throws PojoCacheException
    Description copied from interface: PojoCache
    Lifecycle method to destroy PojoCache.

    Specified by:
    destroy in interface PojoCache
    Throws:
    PojoCacheException

    getListeners

    public java.util.Collection<java.lang.Object> getListeners()
    Description copied from interface: PojoCache
    Retrieve a read-only list of listeners.

    Specified by:
    getListeners in interface PojoCache

    addListener

    public void addListener(java.lang.Object listener)
    Description copied from interface: PojoCache

    Add a PojoCache listener. A given listener instance can only be added once. To have a duplicate listener simply create a new instance.

    The listener must be annotated with the PojoCacheListener annotation, and all callback methods need to be annotated with the respective event annotations. Otherwise, an exception will be thrown.

    Specified by:
    addListener in interface PojoCache
    Parameters:
    listener - the listener instance to register
    See Also:
    for examples

    addListener

    public void addListener(java.lang.Object listener,
                            java.util.regex.Pattern pattern)
    Description copied from interface: PojoCache

    Add a PojoCache listener that will only monitor a specific ID(FQN) pattern. A given listener instance can only be added once, whether or not there is a pattern. To have a duplicate listener simply create a new instance.

    The listener must be annotated with the PojoCacheListener annotation, and all callback methods need to be annotated with the respective event annotations. Otherwise, an exception will be thrown.

    Specified by:
    addListener in interface PojoCache
    Parameters:
    listener - the listener instance to register
    pattern - the ID pattern for notifications of interest
    See Also:
    for examples

    removeListener

    public void removeListener(java.lang.Object listener)
    Description copied from interface: PojoCache
    Remove the specific listener.

    Specified by:
    removeListener in interface PojoCache
    Parameters:
    listener - the listener to remove

    getCache

    public Cache<java.lang.Object,java.lang.Object> getCache()
    Description copied from interface: PojoCache
    Obtain the underlying generic cache system. Use this for non-POJO cache operation, e.g.

    Specified by:
    getCache in interface PojoCache

    _evictObject

    public java.lang.Object _evictObject(Fqn fqn)
                                  throws CacheException
    Used by internal implementation. Not for general public.

    Throws:
    CacheException

    getCachedType

    public CachedType getCachedType(java.lang.Class clazz)
    Obtain a cache aop type for user to traverse the defined "primitive" types in aop. Note that this is not a synchronized call now for speed optimization.

    Parameters:
    clazz - The original pojo class
    Returns:
    CachedType

    toString

    public java.lang.String toString()
    Overrides:
    toString in class java.lang.Object