1 22 package org.jboss.ejb.plugins; 23 24 import org.jboss.cache.invalidation.InvalidationManagerMBean; 25 import org.jboss.cache.invalidation.InvalidationGroup; 26 import org.jboss.metadata.ConfigurationMetaData; 27 import org.jboss.metadata.EntityMetaData; 28 import org.jboss.system.Registry; 29 import org.jboss.ejb.EnterpriseContext; 30 31 42 public class InvalidableEntityInstanceCache 43 extends org.jboss.ejb.plugins.EntityInstanceCache 44 implements org.jboss.cache.invalidation.Invalidatable 45 { 46 47 49 51 protected InvalidationManagerMBean invalMgr = null; 52 protected InvalidationGroup ig = null; 53 54 protected boolean isTraceEnabled = false; 55 56 58 60 public InvalidableEntityInstanceCache() 61 { 62 super(); 63 } 64 65 67 69 public void areInvalid(java.io.Serializable [] keys) 70 { 71 if (this.isTraceEnabled) 72 log.trace("Invalidating entry in cache. Quantity: " + keys.length); 73 74 for (int i = 0; i < keys.length; i++) 75 { 76 try 77 { 78 doInvalidate(keys[i]); 79 } 80 catch (Exception ignored) 81 { 82 log.debug(ignored); 83 } 84 } 85 } 86 87 public void isInvalid(java.io.Serializable key) 88 { 89 try 90 { 91 doInvalidate(key); 92 } 93 catch (Exception ignored) 94 { 95 log.debug(ignored); 96 } 97 } 98 99 public void invalidateAll() 100 { 101 flush(); 102 } 103 104 106 public void start() throws Exception 107 { 108 super.start(); 109 110 log.debug("Starting InvalidableEntityInstanceCache..."); 111 112 EntityMetaData emd = ((EntityMetaData) this.getContainer().getBeanMetaData()); 113 114 boolean participateInDistInvalidations = emd.doDistributedCacheInvalidations(); 115 byte co = emd.getContainerConfiguration().getCommitOption(); 116 117 if (participateInDistInvalidations && 118 (co == ConfigurationMetaData.A_COMMIT_OPTION || co == ConfigurationMetaData.D_COMMIT_OPTION) 119 ) 120 { 121 String groupName = emd.getDistributedCacheInvalidationConfig().getInvalidationGroupName(); 124 String imName = emd.getDistributedCacheInvalidationConfig().getInvalidationManagerName(); 125 126 this.invalMgr = (InvalidationManagerMBean) Registry.lookup(imName); 127 this.ig = this.invalMgr.getInvalidationGroup(groupName); 128 this.ig.register(this); 129 this.isTraceEnabled = log.isTraceEnabled(); 130 } 131 132 } 133 134 public void stop() 135 { 136 try 137 { 138 this.ig.unregister(this); 139 this.ig = null; 140 this.invalMgr = null; 141 } 142 catch (Exception e) 143 { 144 log.debug(e); 145 } 146 147 super.stop(); 148 } 149 150 152 154 protected void doInvalidate(java.io.Serializable key) 155 { 156 if (key != null) 157 { 158 synchronized (getCacheLock()) 159 { 160 EnterpriseContext ctx = (EnterpriseContext)getCache().peek(key); 161 if(ctx != null) 162 { 163 release(ctx); 164 } 165 } 166 } 167 } 168 169 171 173 } 174 | Popular Tags |