1 package org.jboss.cache.interceptors; 2 3 import org.jboss.cache.CacheImpl; 4 import org.jboss.cache.CacheSPI; 5 import org.jboss.cache.GlobalTransaction; 6 import org.jboss.cache.InvocationContext; 7 import org.jboss.cache.config.Option; 8 import org.jboss.cache.marshall.MethodCall; 9 import org.jboss.cache.marshall.MethodDeclarations; 10 11 import javax.transaction.Transaction ; 12 13 24 public class CallInterceptor extends Interceptor 25 { 26 private CacheImpl cache; 27 28 public void setCache(CacheSPI cache) 29 { 30 super.setCache(cache); 31 } 32 33 public void setTreeCacheInstance(CacheImpl c) 34 { 35 cache = c; 36 } 37 38 public Object invoke(MethodCall m) throws Throwable 39 { 40 41 Object retval = null; 42 43 if (!MethodDeclarations.isTransactionLifecycleMethod(m.getMethodId())) 44 { 45 if (log.isTraceEnabled()) log.trace("Passing up method " + m + " so it gets invoked on cache."); 46 try 47 { 48 retval = m.invoke(cache); 50 } 51 catch (Throwable t) 52 { 53 retval = t; 54 } 55 } 56 else 57 { 58 if (log.isTraceEnabled()) log.trace("Suppressing invocation of method " + m + " on cache."); 59 } 60 61 InvocationContext ctx = cache.getInvocationContext(); 62 Transaction tx = ctx.getTransaction(); 63 if (tx != null && isValid(tx)) 64 { 65 if (retval instanceof Throwable ) 67 { 68 tx.setRollbackOnly(); } 70 else 71 { 72 77 if (!configuration.isNodeLockingOptimistic() && MethodDeclarations.isCrudMethod(m.getMethodId())) 78 { 79 GlobalTransaction gtx = ctx.getGlobalTransaction(); 84 if (gtx == null) 85 { 86 if (log.isDebugEnabled()) 87 { 88 log.debug("didn't find GlobalTransaction for " + tx + "; won't add modification to transaction list"); 89 } 90 } 91 else 92 { 93 Option o = cache.getInvocationContext().getOptionOverrides(); 94 if (o != null && o.isCacheModeLocal()) 95 { 96 log.debug("Not adding method to modification list since cache mode local is set."); 97 } 98 else 99 { 100 cache.getTransactionTable().addModification(gtx, m); 101 } 102 if (cache.getCacheLoaderManager() != null) 103 cache.getTransactionTable().addCacheLoaderModification(gtx, m); 104 } 105 } 106 } 107 } 108 109 if (retval instanceof Throwable ) 110 { 111 throw (Throwable ) retval; 112 } 113 114 return retval; 115 } 116 } 117 | Popular Tags |