Represents a particular region within the given JBossCache TreeCache
utilizing TreeCache's optimistic locking capabilities.
| Method from org.hibernate.cache.OptimisticTreeCache Detail: |
public void clear() throws CacheException {
try {
Option option = new Option();
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.remove( regionFqn, option );
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public void destroy() throws CacheException {
try {
Option option = new Option();
option.setCacheModeLocal( true );
option.setFailSilently( true );
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.remove( regionFqn, option );
}
catch( Exception e ) {
throw new CacheException( e );
}
}
|
public Object get(Object key) throws CacheException {
try {
Option option = new Option();
option.setFailSilently( true );
// option.setDataVersion( NonLockingDataVersion.INSTANCE );
return cache.get( new Fqn( regionFqn, key ), ITEM, option );
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public long getElementCountInMemory() {
try {
Set children = cache.getChildrenNames( regionFqn );
return children == null ? 0 : children.size();
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public long getElementCountOnDisk() {
return 0;
}
|
public String getRegionName() {
return regionName;
}
|
public long getSizeInMemory() {
return -1;
}
|
public int getTimeout() {
return 600; //60 seconds
}
|
public void lock(Object key) throws CacheException {
throw new UnsupportedOperationException( "TreeCache is a fully transactional cache" + regionName );
}
|
public long nextTimestamp() {
return System.currentTimeMillis() / 100;
}
|
public void put(Object key,
Object value) throws CacheException {
try {
log.trace( "performing put() into region [" + regionName + "]" );
// do the put outside the scope of the JTA txn
Option option = new Option();
option.setFailSilently( true );
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (TimeoutException te) {
//ignore!
log.debug("ignoring write lock acquisition failure");
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public Object read(Object key) throws CacheException {
try {
return cache.get( new Fqn( regionFqn, key ), ITEM );
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public void remove(Object key) throws CacheException {
try {
// tree cache in optimistic mode seems to have as very difficult
// time with remove calls on non-existent nodes (NPEs)...
if ( cache.get( new Fqn( regionFqn, key ), ITEM ) != null ) {
Option option = new Option();
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.remove( new Fqn( regionFqn, key ), option );
}
else {
log.trace( "skipping remove() call as the underlying node did not seem to exist" );
}
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public void setSource(OptimisticCacheSource source) {
this.source = source;
}
|
public Map toMap() {
try {
Map result = new HashMap();
Set childrenNames = cache.getChildrenNames( regionFqn );
if (childrenNames != null) {
Iterator iter = childrenNames.iterator();
while ( iter.hasNext() ) {
Object key = iter.next();
result.put(
key,
cache.get( new Fqn( regionFqn, key ), ITEM )
);
}
}
return result;
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public String toString() {
return "OptimisticTreeCache(" + regionName + ')";
}
|
public void unlock(Object key) throws CacheException {
throw new UnsupportedOperationException( "TreeCache is a fully transactional cache: " + regionName );
}
|
public void update(Object key,
Object value) throws CacheException {
try {
Option option = new Option();
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public void writeInsert(Object key,
Object value,
Object currentVersion) {
writeUpdate( key, value, currentVersion, null );
}
|
public void writeLoad(Object key,
Object value,
Object currentVersion) {
try {
Option option = new Option();
option.setFailSilently( true );
option.setDataVersion( NonLockingDataVersion.INSTANCE );
cache.remove( new Fqn( regionFqn, key ), "ITEM", option );
option = new Option();
option.setFailSilently( true );
DataVersion dv = ( source != null && source.isVersioned() )
? new DataVersionAdapter( currentVersion, currentVersion, source.getVersionComparator(), source.toString() )
: NonLockingDataVersion.INSTANCE;
option.setDataVersion( dv );
cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch (Exception e) {
throw new CacheException(e);
}
}
|
public void writeUpdate(Object key,
Object value,
Object currentVersion,
Object previousVersion) {
try {
Option option = new Option();
DataVersion dv = ( source != null && source.isVersioned() )
? new DataVersionAdapter( currentVersion, previousVersion, source.getVersionComparator(), source.toString() )
: NonLockingDataVersion.INSTANCE;
option.setDataVersion( dv );
cache.put( new Fqn( regionFqn, key ), ITEM, value, option );
}
catch ( Exception e ) {
throw new CacheException( e );
}
}
|