* @return
* @throws Throwable
*/
public Object invoke(MethodCall call) throws Throwable {
JBCMethodCall m = (JBCMethodCall) call;
// if this is a shared cache loader and the call is of remote origin, pass up the chain. - Manik
// see http://www.jboss.com/index.html?module=bb&op=viewtopic&t=76090
if (!getInvocationContext().isOriginLocal() && loaderConfig.isShared()) {
log.trace("Passing up method call and bypassing this interceptor since the cache loader is shared and this call originated remotely.");
return super.invoke(m);
}
Fqn fqn;
Map attributes;
Object key, value;
Method meth=m.getMethod();
Object[] args=m.getArgs();
Object retval, tmp_retval=null;
boolean use_tmp_retval=false;
if (log.isTraceEnabled()) {
log.trace("CacheStoreInterceptor called with meth " + m);
}
if (tx_mgr != null && tx_mgr.getTransaction() != null) {
// we have a tx running.
log.trace("transactional so don't put stuff in the cloader yet.");
GlobalTransaction gtx = getInvocationContext().getGlobalTransaction();
switch (m.getMethodId())
{
case MethodDeclarations.commitMethod_id:
if (getInvocationContext().isTxHasMods()) {
// this is a commit call.
if (log.isTraceEnabled()) log.trace("Calling loader.commit() for gtx " + gtx);
// sync call (a write) on the loader
List fqnsModified = getFqnsFromModificationList(tx_table.get(gtx).getCacheLoaderModifications());
try
{
loader.commit(gtx);
}
finally
{
preparingTxs.remove(gtx);
}
if (cache.getUseInterceptorMbeans()&& statsEnabled) {
Integer puts = (Integer)m_txStores.get(gtx);
if (puts != null)
m_cacheStores = m_cacheStores + puts.intValue();
m_txStores.remove(gtx);
}
}
else {
log.trace("Commit called with no modifications; ignoring.");
}
break;
case MethodDeclarations.rollbackMethod_id:
if (getInvocationContext().isTxHasMods()) {
// this is a rollback method
if (preparingTxs.containsKey(gtx))
{
preparingTxs.remove(gtx);
loader.rollback(gtx);
}
if (cache.getUseInterceptorMbeans()&& statsEnabled)
m_txStores.remove(gtx);
}
else {
log.trace("Rollback called with no modifications; ignoring.");
}
break;
case MethodDeclarations.optimisticPrepareMethod_id:
case MethodDeclarations.prepareMethod_id:
prepareCacheLoader(gtx, isOnePhaseCommitPrepareMehod(m));
break;
}
// pass up the chain
return super.invoke(m);
}
// if we're here we don't run in a transaction
// remove() methods need to be applied to the CacheLoader before passing up the call: a listener might
// access an element just removed, causing the CacheLoader to *load* the element before *removing* it.
// synchronized(this) {
switch (m.getMethodId())
{
case MethodDeclarations.removeNodeMethodLocal_id:
fqn=(Fqn)args[1];
loader.remove(fqn);
break;
case MethodDeclarations.removeKeyMethodLocal_id:
fqn=(Fqn)args[1];
key=args[2];
tmp_retval=loader.remove(fqn, key);
use_tmp_retval=true;
break;
case MethodDeclarations.removeDataMethodLocal_id:
fqn=(Fqn)args[1];
loader.removeData(fqn);
break;
}
// }
retval=super.invoke(m);
// put() methods need to be applied *after* the call
// synchronized(this) {
switch (m.getMethodId())
{
case MethodDeclarations.putDataMethodLocal_id:
case MethodDeclarations.putDataEraseMethodLocal_id:
Modification mod = convertMethodCallToModification(m);
log.debug(mod);