asmuts 02/01/14 22:49:53
Added: src/java/org/apache/stratum/jcs/access CacheAccess.java
Log:
no message
Revision Changes Path
1.1
jakarta-turbine-stratum/src/java/org/apache/stratum/jcs/access/CacheAccess.java
Index: CacheAccess.java
===================================================================
package org.apache.stratum.jcs.access;
import java.io.*;
import java.util.*;
// CACHE
import org.apache.stratum.jcs.access.*;
import org.apache.stratum.jcs.access.behavior.*;
import org.apache.stratum.jcs.access.exception.*;
import org.apache.stratum.jcs.engine.*;
import org.apache.stratum.jcs.engine.behavior.*;
import org.apache.stratum.jcs.engine.control.*;
import org.apache.stratum.jcs.utils.log.*;
//////////////////////////////////////////////////////////////
public class CacheAccess implements ICacheAccess {
private static CompositeCacheManager cacheMgr;
protected Cache cache_control;
////////////////////////////////////////////////
protected CacheAccess( Cache cache_control ) {
this.cache_control = cache_control;
}
/////////////////////////////////////////
/**
* In the oracle specification, these attributes are global
* and not region specific, regional overirdes is a value add
* each region should be able to house both
* cache and element attribute sets.
*
* It is more efficient to define a cache in the props file and then
* strictly use the get access method. Use of the define region outside of
* an initialization block should be avoided.
*/
public static CacheAccess defineRegion( String name ) throws CacheException {
if ( cacheMgr == null ) {
synchronized( CacheAccess.class ) {
if ( cacheMgr == null ) {
cacheMgr = CacheManagerFactory.getInstance();
}
}
}
Cache cache_control = (Cache)cacheMgr.getCache( name );
return new CacheAccess( cache_control );
}
/////////////////////////////////////////
public static CacheAccess defineRegion( String name, CompositeCacheAttributes
cattr ) throws CacheException {
if ( cacheMgr == null ) {
synchronized( CacheAccess.class ) {
if ( cacheMgr == null ) {
cacheMgr = CacheManagerFactory.getInstance();
}
}
}
Cache cache_control= (Cache)cacheMgr.getCache( name, cattr );
return new CacheAccess( cache_control );
}
/////////////////////////////////////////
public static CacheAccess defineRegion( String name, CompositeCacheAttributes
cattr, Attributes attr ) throws CacheException {
if ( cacheMgr == null ) {
synchronized( CacheAccess.class ) {
if ( cacheMgr == null ) {
cacheMgr = CacheManagerFactory.getInstance();
}
}
}
Cache cache_control= (Cache)cacheMgr.getCache( name, cattr, attr );
return new CacheAccess( cache_control );
}
/////////////////////////////////////////
public static CacheAccess getAccess( String region ) throws CacheException {
if ( cacheMgr == null ) {
synchronized( CacheAccess.class ) {
if ( cacheMgr == null ) {
cacheMgr = CacheManagerFactory.getInstance();
}
}
}
Cache cache_control= (Cache)cacheMgr.getCache( region );
return new CacheAccess( cache_control);
}
/////////////////////////////////////////
public static CacheAccess getAccess( String region, ICompositeCacheAttributes icca
) throws CacheException {
if ( cacheMgr == null ) {
synchronized( CacheAccess.class ) {
if ( cacheMgr == null ) {
cacheMgr = CacheManagerFactory.getInstance();
}
}
}
Cache cache_control= (Cache)cacheMgr.getCache( region, icca );
return new CacheAccess( cache_control);
}
/////////////////////////////////////////
public Object get( String name ) {
return (Object)cache_control.get( (Serializable)name );
}
/////////////////////////////////////////
/**
* Put allows a new object to be placed into the cache identified by name. If
there is currently an object
* associated with name in the region it is replaced. Names are scoped to a region
so
* they must be unique within the region they are placed. Attributes to associate
with the object may be specified with attr. If attr is not supplied, default
* attributes are assumed.
*/
public void put(Object name, Object obj) throws CacheException {
try {
cache_control.put( (Serializable)name, (Serializable)obj );
} catch( Exception e ) {
throw new CacheException( e );
}
}
public void put(Object name, Object obj, Attributes attr) throws CacheException {
try {
cache_control.put( (Serializable)name, (Serializable)obj, attr );
} catch( Exception e ) {
throw new CacheException( e );
}
}
/**
Destroy will invalidate all objects associated with name removing all references
to the objects from the
cache. If name is not specified, the region and all objects
within the region will be destroyed. If destroy is called without a name
attribute, the Cache object
can no longer be used as it will be closed.
*/
public void destroy () throws CacheException {
cache_control.removeAll();
}
public void destroy (Object name) throws CacheException {
cache_control.remove( (Serializable)name );
}
/**
* Remove either the entire region of elements or the
* the specified element from other caches specified in
* in the cache.properties file as lateral caches.
*/
public void removeLateralDirect() {
cache_control.removeLateralDirect("ALL");
return;
}
public void removeLateralDirect(Serializable key) {
cache_control.removeLateralDirect(key);
return;
}
///////////////////////////////////////
public void save() {
cache_control.save();
}
/**
* ResetAttributes allows for some of the attributes of a region to be reset in
particular expiration time
* attriubtes, time to live, default time to live and idle time, and event
handlers. Changing default settings on groups and regions will not affect existing
objects.
* Only object loaded after the reset will use the new defaults. If no name
argument is provided, the reset is
* applied to the region.
*/
public void resetElementAttributes(Attributes attr) throws CacheException,
InvalidHandleException {}
public void resetElementAttributes(Object name, Attributes attr) throws
CacheException, InvalidHandleException {}
/**
* GetAttributes will return an attribute object describing the current attributes
associated with the object
* name. If no name parameter is available, the attributes for the region will be
returned. The name object must
* override the Object.equals and Object.hashCode methods.
*/
public Attributes getElementAttributes() throws CacheException {
return cache_control.attr;
}
public Attributes getElementAttributes(Object name) throws CacheException {
Attributes attr = null;
try {
attr = cache_control.getElementAttributes( (Serializable)name );
} catch( IOException ioe ) {
p( ioe.toString() );
}
return attr;
}
// ///////////////////////////////////////////////////
// // METHODS FOR TESTING AND ERROR REPORTING
// protected void dumpMap() {
// cache_control.dumpMap();
// }
//
// ///////////////////////////////////////////////////
// protected void dumpCacheEntries() {
// cache_control.dumpCacheEntries();
// }
////////////////////////////////////////////////////
protected void dispose() {
cache_control.dispose();
}
////////////////////////////////////////////////////
protected String getStats() {
return cache_control.getStats();
}
////////////////////////////////////////////////////
public static void p( String s ) {
System.out.println( s );
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>