1 22 package org.jboss.ejb.plugins; 23 24 import java.util.HashMap ; 25 26 import org.jboss.deployment.DeploymentException; 27 import org.jboss.ejb.EnterpriseContext; 28 import org.jboss.util.CachePolicy; 29 import org.jboss.metadata.MetaData; 30 import org.jboss.metadata.XmlLoadable; 31 import org.jboss.monitor.Monitorable; 32 import org.jboss.monitor.client.BeanCacheSnapshot; 33 import org.w3c.dom.Element ; 34 35 42 public class NoPassivationCachePolicy 43 implements CachePolicy, Monitorable, XmlLoadable 44 { 45 47 private HashMap m_map; 49 50 51 private boolean flushEnabled = false; 52 53 55 60 public NoPassivationCachePolicy(AbstractInstanceCache eic) 61 { 62 } 63 64 66 68 public void sample(Object s) 69 { 70 if(m_map == null) 71 return; 72 73 synchronized(m_map) 74 { 75 BeanCacheSnapshot snapshot = (BeanCacheSnapshot)s; 76 snapshot.m_passivatingBeans = 0; 77 snapshot.m_cacheMinCapacity = 0; 78 snapshot.m_cacheMaxCapacity = Integer.MAX_VALUE; 79 snapshot.m_cacheCapacity = Integer.MAX_VALUE; 80 snapshot.m_cacheSize = m_map.size(); 81 } 82 } 83 84 public void create() throws Exception 86 { 87 m_map = new HashMap (); 88 } 89 90 public void start() throws Exception 91 { 92 } 93 94 public void stop() 95 { 96 } 97 98 public void destroy() 99 { 100 synchronized (m_map) 101 { 102 m_map.clear(); 103 } 104 } 105 106 public Object get(Object key) 107 { 108 if (key == null) 109 { 110 throw new IllegalArgumentException ("Requesting an object using a null key"); 111 } 112 EnterpriseContext ctx = null; 113 synchronized (m_map) 114 { 115 ctx = (EnterpriseContext) m_map.get(key); 116 } 117 return ctx; 118 } 119 120 public Object peek(Object key) 121 { 122 return get(key); 123 } 124 125 public void insert(Object key, Object ctx) 126 { 127 if (ctx == null) 128 { 129 throw new IllegalArgumentException ("Cannot insert a null object in the cache"); 130 } 131 if (key == null) 132 { 133 throw new IllegalArgumentException ("Cannot insert an object in the cache with null key"); 134 } 135 136 synchronized (m_map) 137 { 138 Object obj = m_map.get(key); 139 if (obj == null) 140 { 141 m_map.put(key, ctx); 142 } 143 else 144 { 145 throw new IllegalStateException ("Attempt to put in the cache an object that is already there"); 146 } 147 } 148 } 149 150 public void remove(Object key) 151 { 152 if (key == null) 153 { 154 throw new IllegalArgumentException ("Removing an object using a null key"); 155 } 156 157 synchronized (m_map) 158 { 159 Object value = m_map.get(key); 160 if (value != null) 161 { 162 m_map.remove(key); 163 } 164 else 165 { 166 throw new IllegalArgumentException ("Cannot remove an object that isn't in the cache"); 167 } 168 } 169 } 170 171 public void flush() 172 { 173 if (flushEnabled) 174 { 175 synchronized (m_map) 176 { 177 m_map.clear(); 178 } 179 } 180 } 181 182 public int size() 183 { 184 synchronized (m_map) 185 { 186 return m_map.size(); 187 } 188 } 189 190 public void importXml(Element element) throws DeploymentException 191 { 192 String flushString = MetaData.getElementContent(MetaData.getOptionalChild(element, "flush-enabled")); 193 flushEnabled = Boolean.valueOf(flushString).booleanValue(); 194 } 195 196 198 200 202 204 } 206 | Popular Tags |