1 7 package org.jboss.cache.aop; 8 9 import org.apache.commons.logging.Log; 10 import org.apache.commons.logging.LogFactory; 11 import org.jboss.aop.InstanceAdvisor; 12 import org.jboss.aop.Advised; 13 import org.jboss.aop.advice.Interceptor; 14 import org.jboss.aop.joinpoint.Invocation; 15 import org.jboss.aop.joinpoint.MethodInvocation; 16 import org.jboss.aop.proxy.ClassProxy; 17 import org.jboss.aop.proxy.ClassProxyFactory; 18 import org.jboss.aop.util.MethodHashing; 19 import org.jboss.util.NestedRuntimeException; 20 import org.jboss.cache.Fqn; 21 import org.jboss.cache.CacheException; 22 import org.jboss.cache.GlobalTransaction; 23 24 import java.lang.reflect.Method ; 25 import java.util.HashMap ; 26 import java.util.Map ; 27 import java.io.Serializable ; 28 29 34 public class InternalDelegate 35 { 36 static Log log=LogFactory.getLog(InternalDelegate.class.getName()); 37 public static final String CLASS_INTERNAL = "__jboss:internal:class__"; 38 public static final Fqn JBOSS_INTERNAL = new Fqn("__JBossInternal__"); 39 public static final String AOPINSTANCE_REF_COUNT = "__AOPINSTANCE_COUNT__"; 41 public static final String AOPINSTANCE_REF_FQN = "__AOPINSTANCE_FQN__"; 42 public static final String AOPINSTANCE_POJO = "__AOPINSTANCE_POJO__"; 44 45 protected TreeCacheAop cache_; 46 47 InternalDelegate(TreeCacheAop cache) 48 { 49 cache_ = cache; 50 } 51 52 56 void resetRefCount(Fqn fqn) throws CacheException 57 { 58 cache_.put(fqn, AOPINSTANCE_REF_COUNT, new Integer (1)); 59 } 60 61 64 int incrementRefCount(Fqn fqn) throws CacheException 65 { 66 70 Integer count = (Integer )cache_.peek(fqn, AOPINSTANCE_REF_COUNT); 72 if( count == null ) 73 throw new RuntimeException ("InternalDelegate.incrementRefCount(): REF_COUNT for reference counting is null at: " +fqn); 74 75 int counter = count.intValue() +1; 76 cache_.put(fqn, AOPINSTANCE_REF_COUNT, new Integer (counter)); 77 return counter; 78 } 79 80 83 int decrementRefCount(Fqn fqn) throws CacheException 84 { 85 Integer count = (Integer )cache_.peek(fqn, AOPINSTANCE_REF_COUNT); 87 if( count == null ) 88 throw new RuntimeException ("InternalDelegate.decrementRefCount(): REF_COUNT for reference counting is null at: " +fqn); 89 90 int counter = count.intValue(); 91 if(counter == 0) 92 throw new RuntimeException ("InternalDelegate.decrementRefCount(): REF_COUNT for reference counting is 0 at: " +fqn); 93 94 counter--; 95 cache_.put(fqn, AOPINSTANCE_REF_COUNT, new Integer (counter)); 96 return counter; 97 } 98 99 String getRefFqn(Fqn fqn) throws CacheException { 100 return (String )cache_.peek(fqn, AOPINSTANCE_REF_FQN); 101 } 102 103 void setRefFqn(Fqn fqn, String internalFqn) throws CacheException 104 { 105 cache_.put(fqn, AOPINSTANCE_REF_FQN, internalFqn); 106 } 107 108 void removeRefFqn(Fqn fqn) throws CacheException 109 { 110 cache_.remove(fqn, AOPINSTANCE_REF_FQN); 111 } 112 113 Object getObjectInstance(Fqn fqn) throws CacheException 114 { 115 return getPOJO(fqn); 116 } 117 118 Object getPOJO(Fqn fqn) throws CacheException 119 { 120 return cache_.peek(fqn, AOPINSTANCE_POJO); 121 } 122 123 void setPOJO(Fqn fqn, Object obj) throws CacheException 124 { 125 GlobalTransaction tx = cache_.getCurrentTransaction(); 127 cache_._put(tx, fqn, AOPINSTANCE_POJO, obj, true); 128 } 129 130 133 void putAopClazz(Fqn fqn, Class clazz) throws CacheException { 134 cache_.marshalledPut(fqn, CLASS_INTERNAL, clazz); 135 } 136 137 Class peekAopClazz(Fqn fqn) throws CacheException { 138 return (Class )cache_.marshalledGet(fqn, CLASS_INTERNAL); 139 } 140 141 public static boolean isInternalNode(Fqn fqn) 142 { 143 if(fqn.isChildOf(JBOSS_INTERNAL)) return true; 144 return false; 145 } 146 147 Fqn createInternalNode(Fqn storedFqn) 149 { 150 Fqn fqn = new Fqn(JBOSS_INTERNAL, storedFqn); 151 return fqn; 152 } 153 154 public boolean isAopNode(Fqn fqn) throws CacheException 155 { 156 if( cache_.peek(fqn, AOPINSTANCE_REF_COUNT) != null ) 158 return true; 159 else 160 return false; 161 } 162 163 } 164 | Popular Tags |