1 package org.jahia.services.webdav.stores; 18 19 import org.apache.slide.common.ServiceAccessException; 20 import org.apache.slide.common.Uri; 21 import org.apache.slide.content.NodeRevisionDescriptor; 22 import org.apache.slide.content.RevisionDescriptorNotFoundException; 23 import org.apache.slide.store.BindingStore; 24 import org.apache.slide.store.ExtendedStore; 25 import org.apache.slide.structure.ObjectNode; 26 import org.apache.slide.structure.ObjectNotFoundException; 27 import org.apache.slide.util.ByteSizeLimitedObjectCache; 28 import org.apache.slide.util.TxLRUObjectCache; 29 import org.apache.slide.util.logger.Logger; 30 import org.jahia.exceptions.JahiaInitializationException; 31 import org.jahia.services.cache.Cache; 32 import org.jahia.services.cache.CacheFactory; 33 34 import java.util.Collection ; 35 import java.util.HashSet ; 36 import java.util.Map ; 37 import java.util.Set ; 38 39 46 public class JahiaBindingStore extends BindingStore { 47 public void storeRevisionDescriptor(Uri uri, NodeRevisionDescriptor revisionDescriptor) throws ServiceAccessException, RevisionDescriptorNotFoundException { 49 super.storeRevisionDescriptor(uri, revisionDescriptor); 50 if (uri.toString().startsWith("/users")) { 51 ((TxCacheWrapper)objectsCache).remove("/users"); 52 } 53 if (uri.toString().startsWith("/groups")) { 54 ((TxCacheWrapper)objectsCache).remove("/groups"); 55 } 56 } 57 58 public void storeObject(Uri uri, ObjectNode object) throws ServiceAccessException, ObjectNotFoundException { 60 super.storeObject(uri, object); 61 objectsCache.remove(uri.toString()); 62 } 63 64 protected void init( 66 int globalObjectCacheSize, 67 int globalPermissionCacheSize, 68 int globalLockCacheSize, 69 int globalDescrtiptorsCacheSize, 70 int globalDescrtiptorCacheSize, 71 boolean contentCachingEnabled, 72 int globalContentCacheSize, 73 long contentCacheBytes, 74 int txContentCacheSize, 75 long txContentCacheBytes, 76 long maxByteSizePerEntry, 77 boolean noGlobalCacheInTx) { 78 try { 79 objectsCache = new TxCacheWrapper(globalObjectCacheSize, "object", noGlobalCacheInTx); 80 permissionsCache = new TxCacheWrapper(globalPermissionCacheSize, "permission", noGlobalCacheInTx); 81 locksCache = new TxCacheWrapper(globalLockCacheSize, "lock", noGlobalCacheInTx); 82 descriptorsCache = new TxCacheWrapper(globalDescrtiptorsCacheSize, "descriptors", noGlobalCacheInTx); 83 descriptorCache = new TxCacheWrapper(globalDescrtiptorCacheSize, "descriptor", noGlobalCacheInTx); 84 85 if (contentCachingEnabled) { 86 contentCache = 87 new TxContentCacheWrapper( 88 new ByteSizeLimitedObjectCache( 89 globalContentCacheSize, 90 txContentCacheSize, 91 contentCacheBytes, 92 txContentCacheBytes, 93 maxByteSizePerEntry, 94 getName() + ".content", 95 getLogger(), 96 noGlobalCacheInTx)); 97 } else { 98 contentCache = null; 99 } 100 } catch (Error e) { 101 fatalError(e); 102 } catch (RuntimeException re) { 103 fatalError(re); 104 } 105 } 106 107 protected void invalidateCacheUponError(Uri uri) { 108 return; 109 } 110 111 protected class TxCacheWrapper extends ExtendedStore.TxCacheWrapper { 112 public TxCacheWrapper(int globalCacheSize, String name, boolean noGlobalCacheInTx) { 113 super(new JahiaTxLRUObjectCache(globalCacheSize, getName() + "." + name, getLogger(), noGlobalCacheInTx)); 114 } 115 } 116 117 private class JahiaTxLRUObjectCache extends TxLRUObjectCache { 118 private Cache jahiaCache; 119 120 protected void prune(Map map, Object key, String delimiter) { 121 map.clear(); 122 } 123 124 protected void deprune(Set set, Object key, String delimiter) { 125 return; 126 } 127 128 public JahiaTxLRUObjectCache(int globalCacheSize, String name, Logger logger, boolean noGlobalCachingInsideTx) { 129 super(globalCacheSize, name, logger, noGlobalCachingInsideTx); 130 131 try { 132 jahiaCache = CacheFactory.getInstance().createCacheInstance(name); 133 globalCache = new Map () { 134 public Collection values() { 135 return null; 136 } 137 138 public int size() { 139 return jahiaCache.size(); 140 } 141 142 public Object remove(Object key) { 143 if (namespace == null) { 144 return null; 145 } 146 key = namespace.getName() + "." + key; 147 Object r = jahiaCache.get(key); 148 jahiaCache.remove(key); 149 return r; 150 } 151 152 public void putAll(Map t) { 153 } 154 155 public Object put(Object key, Object value) { 156 if (namespace == null) { 157 return null; 158 } 159 key = namespace.getName() + "." + key; 160 Object r = jahiaCache.get(key); 161 jahiaCache.put(key, value); 162 return r; 163 } 164 165 public Set keySet() { 166 return new HashSet (); 167 } 168 169 public boolean isEmpty() { 170 return false; 171 } 172 173 public Object get(Object key) { 174 if (namespace == null) { 175 return null; 176 } 177 key = namespace.getName() + "." + key; 178 return jahiaCache.get(key); 179 } 180 181 public Set entrySet() { 182 return null; 183 } 184 185 public boolean containsValue(Object value) { 186 return false; 187 } 188 189 public boolean containsKey(Object key) { 190 return false; 191 } 192 193 public void clear() { 194 jahiaCache.flush(); 195 } 196 }; 197 } catch (JahiaInitializationException e) { 198 e.printStackTrace(); 199 } 200 } 201 202 public synchronized Object get(Object txId, Object key) { 203 return super.get(null, key); 204 } 205 206 public synchronized void put(Object txId, Object key, Object value, long timeout) { 207 super.put(null, key, value, timeout); 208 } 209 210 public synchronized void put(Object txId, Object key, Object value) { 211 super.put(null, key, value); 212 } 213 214 public synchronized void remove(Object txId, Object key) { 215 super.remove(null, key); 216 } 217 218 public synchronized void remove(Object txId, Object key, String delimiter) { 219 super.remove(null, key, delimiter); 220 } 221 222 public synchronized void start(Object txId) { 223 return; 224 } 225 226 public synchronized void rollback(Object txId) { 227 return; 228 } 229 230 public synchronized void forget(Object txId) { 231 return; 232 } 233 234 protected void hit(Object txId, Object key) { 235 super.hit(null, key); 236 } 237 238 protected void miss(Object txId, Object key) { 239 super.miss(null, key); 240 } 241 242 protected void log(Object txId, Object key, boolean hit) { 243 super.log(null, key, hit); 244 } 245 246 public synchronized void commit(Object txId) { 247 return; 248 } 249 } 250 251 } 252 | Popular Tags |