public Storage(VBucketInfo vbi[], MemcachedServer server) { vbInfo = vbi; persistStore = new HashMap<KeySpec, Item>(); VBucketStore.ItemAction deleteCallback = new DeleteActionCallback(this); VBucketStore.ItemAction mutateCallback = new MutateActionCallback(this); cacheStore = new VBucketStore(); cacheStore.onItemDelete = deleteCallback; cacheStore.onItemMutated = mutateCallback; this.server = server; }
public void replicateMutatedItem(Item itm) { VBucketInfo vbi = vbInfo[itm.getKeySpec().vbId]; if (vbi.getOwner() != server) { return; } for (MemcachedServer replica : vbi.getReplicas()) { Item newItem = new Item(itm); VBucketStore rStore = replica.getStorage().cacheStore; rStore.getMap().put(newItem.getKeySpec(), newItem); rStore.onItemMutated.onAction(rStore, newItem); } }
public void replicateDeletedItem(KeySpec ks) { VBucketInfo vbi = vbInfo[ks.vbId]; if (vbi.getOwner() != server) { return; } Item itm = new Item(ks); for (MemcachedServer replica : vbi.getReplicas()) { VBucketStore rStore = replica.getStorage().cacheStore; rStore.getMap().remove(ks); rStore.onItemDelete.onAction(rStore, itm); rStore.onItemMutated.onAction(rStore, itm); } }
public void flush() { cacheStore.getMap().clear(); persistStore.clear(); }
public void removeCached(KeySpec ks) { cacheStore.getMap().remove(ks); }
public void putCached(Item itm) { cacheStore.getMap().put(itm.getKeySpec(), itm); }
public Item getCached(KeySpec ks) { return cacheStore.get(ks); }