1 22 package org.jboss.ejb.plugins.lock; 23 24 import javax.transaction.Transaction ; 25 26 import org.jboss.ejb.BeanLock; 27 import org.jboss.ejb.Container; 28 import org.jboss.ejb.BeanLockExt; 29 import org.jboss.invocation.Invocation; 30 import org.jboss.logging.Logger; 31 import org.jboss.util.deadlock.Resource; 32 33 34 41 public abstract class BeanLockSupport implements Resource, BeanLockExt 42 { 43 protected Container container = null; 44 45 49 protected int refs = 0; 50 51 52 protected Object id = null; 53 54 55 static Logger log = Logger.getLogger(BeanLock.class); 56 57 58 protected Transaction tx = null; 59 60 protected Thread synched = null; 61 protected int synchedDepth = 0; 62 63 protected int txTimeout; 64 65 66 public void setId(Object id) { this.id = id;} 67 public Object getId() { return id;} 68 public void setTimeout(int timeout) {txTimeout = timeout;} 69 public void setContainer(Container container) { this.container = container; } 70 public Object getResourceHolder() { return tx; } 71 72 79 public boolean attemptSync() 80 { 81 boolean didSync = false; 82 synchronized(this) 83 { 84 Thread thread = Thread.currentThread(); 85 if(synched == null || synched.equals(thread) == true) 86 { 87 synched = thread; 88 ++ synchedDepth; 89 didSync = true; 90 } 91 } 92 return didSync; 93 } 94 95 101 public void sync() 102 { 103 synchronized(this) 104 { 105 Thread thread = Thread.currentThread(); 106 while(synched != null && synched.equals(thread) == false) 107 { 108 try 109 { 110 this.wait(); 111 } 112 catch (InterruptedException ex) { } 113 } 114 synched = thread; 115 ++synchedDepth; 116 } 117 } 118 119 public void releaseSync() 120 { 121 synchronized(this) 122 { 123 if (--synchedDepth == 0) 124 synched = null; 125 this.notify(); 126 } 127 } 128 129 public abstract void schedule(Invocation mi) throws Exception ; 130 131 135 public void setTransaction(Transaction tx){this.tx = tx;} 136 public Transaction getTransaction(){return tx;} 137 138 public abstract void endTransaction(Transaction tx); 139 public abstract void wontSynchronize(Transaction tx); 140 141 public abstract void endInvocation(Invocation mi); 142 143 public void addRef() { refs++;} 144 public void removeRef() { refs--;} 145 public int getRefs() { return refs;} 146 147 149 } 150 | Popular Tags |