package org.jboss.cache.interceptors;
import org.jgroups.blocks.MethodCall;
import org.jboss.cache.TreeCache;
import org.jboss.logging.Logger;
import javax.transaction.Transaction;
import javax.transaction.SystemException;
import javax.transaction.Status;
public abstract class Interceptor {
Interceptor next=null;
TreeCache cache=null;
Logger log=null;
public Interceptor() {
log=Logger.getLogger(getClass());
}
public void setNext(Interceptor i) {
next=i;
}
public Interceptor getNext() {
return next;
}
public void setCache(TreeCache cache) {
this.cache=cache;
}
public Object invoke(MethodCall m) throws Throwable {
return next.invoke(m);
}
boolean isActive(Transaction tx) {
if(tx == null) return false;
int status=-1;
try {
status=tx.getStatus();
return status == Status.STATUS_ACTIVE;
}
catch(SystemException e) {
log.error("failed getting transaction status", e);
return false;
}
}
boolean isPreparing(Transaction tx) {
if(tx == null) return false;
int status=-1;
try {
status=tx.getStatus();
return status == Status.STATUS_PREPARING;
}
catch(SystemException e) {
log.error("failed getting transaction status", e);
return false;
}
}
boolean isValid(Transaction tx) {
return isActive(tx) || isPreparing(tx);
}
}