1 package org.jboss.cache.interceptors; 2 3 import org.jboss.cache.GlobalTransaction; 4 import org.jboss.cache.InvocationContext; 5 import org.jboss.cache.config.Configuration; 6 import org.jboss.cache.config.Option; 7 import org.jboss.cache.marshall.MethodCall; 8 import org.jboss.cache.marshall.MethodDeclarations; 9 10 18 public class ReplicationInterceptor extends BaseRpcInterceptor 19 { 20 21 public Object invoke(MethodCall m) throws Throwable 22 { 23 InvocationContext ctx = cache.getInvocationContext(); 24 GlobalTransaction gtx = ctx.getGlobalTransaction(); 25 26 if (MethodDeclarations.isBuddyGroupOrganisationMethod(m.getMethodId())) return super.invoke(m); 28 29 boolean isLocalCommitOrRollback = gtx != null && !gtx.isRemote() && (m.getMethodId() == MethodDeclarations.commitMethod_id || m.getMethodId() == MethodDeclarations.rollbackMethod_id); 30 31 if (log.isTraceEnabled()) log.trace("isLocalCommitOrRollback? " + isLocalCommitOrRollback + "; gtx = " + gtx); 32 33 Object o = isLocalCommitOrRollback ? null : super.invoke(m); 35 37 Option optionOverride = ctx.getOptionOverrides(); 38 39 if (optionOverride != null && optionOverride.isCacheModeLocal() && ctx.getTransaction() == null) 40 { 41 log.trace("skip replication"); 42 return isLocalCommitOrRollback ? super.invoke(m) : o; 43 } 44 45 if (ctx.getTransaction() != null) 48 { 49 if (gtx != null && !gtx.isRemote()) 50 { 51 switch (m.getMethodId()) 53 { 54 case MethodDeclarations.commitMethod_id: 55 if (containsModifications(m)) replicateCall(m, configuration.isSyncCommitPhase()); 57 o = super.invoke(m); 59 break; 60 case MethodDeclarations.prepareMethod_id: 61 if (containsModifications(m)) 62 { 63 runPreparePhase(m, gtx); 65 } 66 break; 67 case MethodDeclarations.rollbackMethod_id: 68 if (containsModifications(m) && !ctx.isLocalRollbackOnly()) 70 { 71 replicateCall(m, configuration.isSyncRollbackPhase()); 72 } 73 o = super.invoke(m); 75 break; 76 } 77 } 78 } 79 else if (MethodDeclarations.isCrudMethod(m.getMethodId())) 80 { 81 if (log.isTraceEnabled()) log.trace("Non-tx crud meth"); 83 if (ctx.isOriginLocal()) 84 { 85 handleReplicatedMethod(m, configuration.getCacheMode()); 87 } 88 } 89 else 90 { 91 if (log.isTraceEnabled()) log.trace("Non-tx and non crud meth"); 92 } 93 94 return o; 95 } 96 97 void handleReplicatedMethod(MethodCall m, Configuration.CacheMode mode) throws Throwable 98 { 99 if (log.isTraceEnabled()) 100 { 101 log.trace("invoking method " + m + ", members=" + cache.getMembers() + ", mode=" + 102 configuration.getCacheMode() + ", exclude_self=" + true + ", timeout=" + 103 configuration.getSyncReplTimeout()); 104 } 105 switch (mode) 106 { 107 case REPL_ASYNC: 108 replicateCall(m, false); 110 break; 111 case REPL_SYNC: 112 replicateCall(m, true); 115 break; 116 } 117 } 118 119 133 protected void runPreparePhase(MethodCall prepareMethod, GlobalTransaction gtx) throws Throwable 134 { 135 boolean async = configuration.getCacheMode() == Configuration.CacheMode.REPL_ASYNC; 136 if (log.isTraceEnabled()) 137 { 138 log.trace("(" + cache.getLocalAddress() + "): running remote prepare for global tx " + gtx + " with async mode=" + async); 139 } 140 141 replicateCall(prepareMethod, !async); 143 } 144 } 145 | Popular Tags |