1 package org.jboss.cache.interceptors; 2 3 import org.jboss.cache.CacheSPI; 4 import org.jboss.cache.InvocationContext; 5 import org.jboss.cache.lock.IdentityLock; 6 import org.jboss.cache.marshall.MethodCall; 7 8 import javax.transaction.Transaction ; 9 import java.util.List ; 10 import java.util.ListIterator ; 11 import java.util.Map ; 12 13 20 public class UnlockInterceptor extends Interceptor { 21 22 Map lock_table = null; 23 boolean trace = log.isTraceEnabled(); 24 25 public void setCache(CacheSPI cache) 26 { 27 super.setCache(cache); 28 lock_table = cache.getLockTable(); 29 } 30 31 public Object invoke(MethodCall m) throws Throwable { 32 try { 33 return super.invoke(m); 34 } 35 finally 36 { 37 InvocationContext ctx = cache.getInvocationContext(); 38 if (ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isSuppressLocking()) 39 { 40 Transaction tx = ctx.getTransaction(); 41 if (tx != null && isValid(tx)) 42 { 43 } 45 else { Thread currentThread = Thread.currentThread(); 47 List locks = (List )lock_table.get(currentThread); 48 if (trace) log.trace("Attempting to release locks on current thread. Lock table is " + lock_table); 49 50 if (locks != null && locks.size() > 0) { 51 releaseLocks(locks, currentThread); 52 lock_table.remove(currentThread); 53 } 54 } 55 } 56 } 57 } 58 59 private void releaseLocks(List locks, Thread currentThread) { 60 IdentityLock lock; 61 for (ListIterator it=locks.listIterator(locks.size()); it.hasPrevious();) { 62 lock=(IdentityLock)it.previous(); 63 if (trace) 64 log.trace("releasing lock for " + lock.getFqn() + ": " + lock); 65 lock.release(currentThread); 66 } 67 } 68 69 70 } 71 | Popular Tags |