org.jboss.cache.pojo
Interface PojoCache

All Known Subinterfaces:
PojoCacheMBean
All Known Implementing Classes:
PojoCacheImpl

public interface PojoCache

Main PojoCache APIs. PojoCache is an in-memory, transactional, fine-grained, and object-oriented POJO (plain old Java object) distributed cache system. It differs from the traditional generic distributed cache library by operating on the POJO level directly without requiring that object to be serializable. It can preserve object graph relationship during replication or persistency. It also track the replication via fine-grained maner, i.e., only modified fields are replicated.

Since:
2.0
Author:
Ben Wang, Jason T. Greene

Method Summary
 void addListener(Object listener)
           Add a PojoCache listener.
 void addListener(Object listener, Pattern pattern)
           Add a PojoCache listener that will only monitor a specific ID(FQN) pattern.
 Object attach(Fqn<?> id, Object pojo)
          Attach a POJO into PojoCache.
 Object attach(String id, Object pojo)
          Attach a POJO into PojoCache.
 void create()
          Lifecycle method to start PojoCache.
 void destroy()
          Lifecycle method to destroy PojoCache.
 Object detach(Fqn<?> id)
          Remove POJO object from the cache.
 Object detach(String id)
          Remove POJO object from the cache.
 boolean exists(Fqn<?> id)
          Determines if an object is attached at a particular location.
 Object find(Fqn<?> id)
          Retrieve POJO from the cache system.
 Object find(String id)
          Retrieve POJO from the cache system.
 Map<Fqn<?>,Object> findAll(Fqn<?> id)
          Query all managed POJO objects under the id recursively.
 Map<Fqn<?>,Object> findAll(String id)
          Query all managed POJO objects under the id recursively.
 Cache<Object,Object> getCache()
          Obtain the underlying generic cache system.
 Collection<Object> getListeners()
          Retrieve a read-only list of listeners.
 String getPojoID(Object pojo)
          Return the POJO id that is associated with PojoCache.
 PojoCacheThreadContext getThreadContext()
          Get's the thread context for all POJO Cache operations.
 void removeListener(Object listener)
          Remove the specific listener.
 void start()
          Lifecycle method to start PojoCache.
 void stop()
          Lifecycle method to stop PojoCache.
 

Method Detail

attach

Object attach(String id,
              Object pojo)
              throws PojoCacheException

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 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.
  • 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

    Object attach(Fqn<?> id,
                  Object pojo)
                  throws PojoCacheException

    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 consequences when attached:

  • it is Replicable, that is, it has been annotated with 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 relationship 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.
  • Parameters:
    id - the Fqn that specifies the location in the cache to attach the object
    pojo - object to be inserted 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.
    Since:
    2.1

    detach

    Object detach(String id)
                  throws PojoCacheException
    Remove POJO object from the cache.

    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

    Object detach(Fqn<?> id)
                  throws PojoCacheException
    Remove POJO object from the cache.

    Parameters:
    id - location of the object to remove
    Returns:
    Original value object from this node.
    Throws:
    PojoCacheException - Throws if there is an error related to the cache operation.
    Since:
    2.1

    getPojoID

    String getPojoID(Object pojo)
    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.

    Parameters:
    pojo - The POJO that is attached to PojoCache.
    Returns:
    String ID. Null if not existed.

    exists

    boolean exists(Fqn<?> id)
    Determines if an object is attached at a particular location. This is somewhat less expensive than find() because an object is not created, and internal reference links are not traversed.

    Parameters:
    id - the location in the cache to examine
    Returns:
    true if an attached object exists, false if not
    Since:
    2.1

    find

    Object find(String id)
                throws PojoCacheException
    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.

    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

    Object find(Fqn<?> id)
                throws PojoCacheException
    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.

    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.
    Since:
    2.1

    findAll

    Map<Fqn<?>,Object> findAll(String id)
                               throws PojoCacheException
    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.

    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

    Map<Fqn<?>,Object> findAll(Fqn<?> id)
                               throws PojoCacheException
    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.

    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.
    Since:
    2.1

    create

    void create()
                throws PojoCacheException
    Lifecycle method to start PojoCache.

    Throws:
    PojoCacheException

    start

    void start()
               throws PojoCacheException
    Lifecycle method to start PojoCache.

    Throws:
    PojoCacheException

    stop

    void stop()
              throws PojoCacheException
    Lifecycle method to stop PojoCache. Note that PojoCache can be stopped and started repeatedly.

    Throws:
    PojoCacheException

    destroy

    void destroy()
                 throws PojoCacheException
    Lifecycle method to destroy PojoCache.

    Throws:
    PojoCacheException

    addListener

    void addListener(Object listener)

    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.

    Parameters:
    listener - the listener instance to register
    Throws:
    IllegalArgumentException - if listener does not conform to annotation requirements
    See Also:
    for examples

    addListener

    void addListener(Object listener,
                     Pattern pattern)

    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.

    Parameters:
    listener - the listener instance to register
    pattern - the ID pattern for notifications of interest
    Throws:
    IllegalArgumentException - if listener does not conform to annotation requirements
    See Also:
    for examples

    getListeners

    Collection<Object> getListeners()
    Retrieve a read-only list of listeners.


    removeListener

    void removeListener(Object listener)
    Remove the specific listener.

    Parameters:
    listener - the listener to remove

    getThreadContext

    PojoCacheThreadContext getThreadContext()
    Get's the thread context for all POJO Cache operations.

    Returns:
    the current thread's context
    Since:
    2.1

    getCache

    Cache<Object,Object> getCache()
    Obtain the underlying generic cache system. Use this for non-POJO cache operation, e.g.



    Copyright © 2008 JBoss, a division of Red Hat. All Rights Reserved.