public void reloadAll() throws IOException { logger.debug("Reloading " + entityType.getSimpleName() + " from " + store.getReadableResourcePath(resRootPath)); cache.clear(); List<String> paths = store.collectResourceRecursively(resRootPath, resPathSuffix); for (String path : paths) { reloadQuietlyAt(path); } logger.debug("Loaded " + cache.size() + " " + entityType.getSimpleName() + "(s) out of " + paths.size() + " resource"); }
public T save(T entity) throws IOException { Preconditions.checkArgument(entity != null); completeUuidIfNeeded(entity); Preconditions.checkArgument(entityType.isInstance(entity)); String resName = entity.resourceName(); Preconditions.checkArgument(resName != null && resName.length() > 0); if (checkCopyOnWrite) { if (entity.isCachedAndShared() || cache.get(resName) == entity) { throw new IllegalStateException("Copy-on-write violation! The updating entity " + entity + " is a shared object in " + entityType.getSimpleName() + " cache, which should not be."); } } String path = resourcePath(resName); logger.debug("Saving {} at {}", entityType.getSimpleName(), path); store.checkAndPutResource(path, entity, serializer); // just to trigger the event broadcast, the entity won't stay in cache cache.put(resName, entity); // keep the pass-in entity out of cache, the caller may use it for further update // return a reloaded new object return reload(resName); }
public void remove(K key) { boolean exists = innerCache.containsKey(key); innerCache.remove(key); if (exists) { getBroadcaster().announce(syncEntity, Broadcaster.Event.DROP.getType(), key.toString()); } }
public T reloadAt(String path) { try { T entity = store.getResource(path, serializer); if (entity == null) { logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null"); cache.removeLocal(resourceName(path)); return null; } // mark cached object entity.setCachedAndShared(true); entity = initEntityAfterReload(entity, resourceName(path)); if (path.equals(resourcePath(entity.resourceName())) == false) throw new IllegalStateException("The entity " + entity + " read from " + path + " will save to a different path " + resourcePath(entity.resourceName())); cache.putLocal(entity.resourceName(), entity); return entity; } catch (Exception e) { throw new IllegalStateException("Error loading " + entityType.getSimpleName() + " at " + path, e); } }
@Override public void putLocal(String key, V value) { super.putLocal(key, value); } }
public void delete(String resName) throws IOException { Preconditions.checkArgument(resName != null); String path = resourcePath(resName); logger.debug("Deleting {} at {}", entityType.getSimpleName(), path); store.deleteResource(path); cache.remove(resName); }
@Override public void put(String key, V value) { super.put(key, value); }
public T reloadAt(String path) { try { T entity = store.getResource(path, serializer); if (entity == null) { logger.warn("No " + entityType.getSimpleName() + " found at " + path + ", returning null"); cache.removeLocal(resourceName(path)); return null; } // mark cached object entity.setCachedAndShared(true); entity = initEntityAfterReload(entity, resourceName(path)); if (path.equals(resourcePath(entity.resourceName())) == false) throw new IllegalStateException("The entity " + entity + " read from " + path + " will save to a different path " + resourcePath(entity.resourceName())); cache.putLocal(entity.resourceName(), entity); return entity; } catch (Exception e) { throw new IllegalStateException("Error loading " + entityType.getSimpleName() + " at " + path, e); } }
@Override public void putLocal(String key, V value) { super.putLocal(key, value); } }
public void delete(String resName) throws IOException { Preconditions.checkArgument(resName != null); String path = resourcePath(resName); logger.debug("Deleting {} at {}", entityType.getSimpleName(), path); store.deleteResource(path); cache.remove(resName); }
@Override public void put(String key, V value) { super.put(key, value); }
public void reloadAll() throws IOException { logger.debug("Reloading " + entityType.getSimpleName() + " from " + store.getReadableResourcePath(resRootPath)); cache.clear(); List<String> paths = store.collectResourceRecursively(resRootPath, resPathSuffix); for (String path : paths) { reloadQuietlyAt(path); } logger.debug("Loaded " + cache.size() + " " + entityType.getSimpleName() + "(s) out of " + paths.size() + " resource"); }
public T save(T entity) throws IOException { Preconditions.checkArgument(entity != null); completeUuidIfNeeded(entity); Preconditions.checkArgument(entityType.isInstance(entity)); String resName = entity.resourceName(); Preconditions.checkArgument(resName != null && resName.length() > 0); if (checkCopyOnWrite) { if (entity.isCachedAndShared() || cache.get(resName) == entity) { throw new IllegalStateException("Copy-on-write violation! The updating entity " + entity + " is a shared object in " + entityType.getSimpleName() + " cache, which should not be."); } } String path = resourcePath(resName); logger.debug("Saving {} at {}", entityType.getSimpleName(), path); store.checkAndPutResource(path, entity, serializer); // just to trigger the event broadcast, the entity won't stay in cache cache.put(resName, entity); // keep the pass-in entity out of cache, the caller may use it for further update // return a reloaded new object return reload(resName); }
public void put(K key, V value) { boolean exists = innerCache.containsKey(key); innerCache.put(key, value); if (!exists) { getBroadcaster().announce(syncEntity, Broadcaster.Event.CREATE.getType(), key.toString()); } else { getBroadcaster().announce(syncEntity, Broadcaster.Event.UPDATE.getType(), key.toString()); } }
public void remove(K key) { boolean exists = innerCache.containsKey(key); innerCache.remove(key); if (exists) { getBroadcaster().announce(syncEntity, Broadcaster.Event.DROP.getType(), key.toString()); } }
public void put(K key, V value) { boolean exists = innerCache.containsKey(key); innerCache.put(key, value); if (!exists) { getBroadcaster().announce(syncEntity, Broadcaster.Event.CREATE.getType(), key.toString()); } else { getBroadcaster().announce(syncEntity, Broadcaster.Event.UPDATE.getType(), key.toString()); } }