@Override protected void startQueuedOperations(int bytes) throws DhtException { client.modify(pending, wrap(none, bytes)); pending = null; }
@Override protected void startQueuedOperations(int bytes) throws DhtException { client.modify(pending, wrap(none, bytes)); pending = null; }
public void run() { for (Map.Entry<ChunkKey, ChunkMeta> ent : toPutIntoCache.entrySet()) { ChunkKey key = ent.getKey(); Change op = Change.put(nsMeta.key(key), ent.getValue().toByteArray()); client.modify(singleton(op), none); } } });
public void run() { for (Map.Entry<ChunkKey, ChunkMeta> ent : toPutIntoCache.entrySet()) { ChunkKey key = ent.getKey(); Change op = Change.put(nsMeta.key(key), ent.getValue().toByteArray()); client.modify(singleton(op), none); } } });
public void run() { List<Change> ops = new ArrayList<Change>(toPut.size()); for (Map.Entry<ObjectIndexKey, Collection<ObjectInfo>> e : all(toPut)) { List<ObjectInfo> items = copy(e.getValue()); ObjectInfo.sort(items); ops.add(Change.put(ns.key(e.getKey()), encode(items))); } client.modify(ops, Sync.<Void> none()); }
public void run() { List<Change> ops = new ArrayList<Change>(toPut.size()); for (Map.Entry<ObjectIndexKey, Collection<ObjectInfo>> e : all(toPut)) { List<ObjectInfo> items = copy(e.getValue()); ObjectInfo.sort(items); ops.add(Change.put(ns.key(e.getKey()), encode(items))); } client.modify(ops, Sync.<Void> none()); }
public void run() { for (PackChunk.Members members : toPutIntoCache) { ChunkKey key = members.getChunkKey(); Change op = Change.put(nsChunk.key(key), encode(members)); client.modify(singleton(op), none); } } });
public void run() { for (PackChunk.Members members : toPutIntoCache) { ChunkKey key = members.getChunkKey(); Change op = Change.put(nsChunk.key(key), encode(members)); client.modify(singleton(op), none); } } });
public void onPartialResult(Map<CacheKey, byte[]> result) { for (Map.Entry<CacheKey, byte[]> ent : result.entrySet()) { ChunkKey key = ChunkKey.fromBytes(ent.getKey().getBytes()); ChunkMeta meta; try { meta = ChunkMeta.parseFrom(ent.getValue()); } catch (InvalidProtocolBufferException e) { // Invalid meta message, remove the cell from cache. client.modify(singleton(Change.remove(ent.getKey())), Sync.<Void> none()); continue; } if (streamingCallback != null) { streamingCallback.onPartialResult(singletonMap(key, meta)); synchronized (lock) { remaining.remove(key); } } else { synchronized (lock) { all.put(key, meta); remaining.remove(key); } } } }
public void onPartialResult(Map<CacheKey, byte[]> result) { for (Map.Entry<CacheKey, byte[]> ent : result.entrySet()) { ChunkKey key = ChunkKey.fromBytes(ent.getKey().getBytes()); ChunkMeta meta; try { meta = ChunkMeta.parseFrom(ent.getValue()); } catch (InvalidProtocolBufferException e) { // Invalid meta message, remove the cell from cache. client.modify(singleton(Change.remove(ent.getKey())), Sync.<Void> none()); continue; } if (streamingCallback != null) { streamingCallback.onPartialResult(singletonMap(key, meta)); synchronized (lock) { remaining.remove(key); } } else { synchronized (lock) { all.put(key, meta); remaining.remove(key); } } } }
public void remove(RepositoryName name, RepositoryKey key) throws DhtException, TimeoutException { db.remove(name, key); Sync<Void> sync = Sync.create(); CacheKey memKey = ns.key(name); client.modify(singleton(Change.remove(memKey)), sync); try { sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } } }
public void remove(RepositoryName name, RepositoryKey key) throws DhtException, TimeoutException { db.remove(name, key); Sync<Void> sync = Sync.create(); CacheKey memKey = ns.key(name); client.modify(singleton(Change.remove(memKey)), sync); try { sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } } }
public void putUnique(RepositoryName name, RepositoryKey key) throws DhtException, TimeoutException { db.putUnique(name, key); Sync<Void> sync = Sync.create(); CacheKey memKey = ns.key(name); byte[] data = key.asBytes(); client.modify(singleton(Change.put(memKey, data)), sync); try { sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } }
public void putUnique(RepositoryName name, RepositoryKey key) throws DhtException, TimeoutException { db.putUnique(name, key); Sync<Void> sync = Sync.create(); CacheKey memKey = ns.key(name); byte[] data = key.asBytes(); client.modify(singleton(Change.put(memKey, data)), sync); try { sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } }
public RepositoryKey get(RepositoryName name) throws DhtException, TimeoutException { CacheKey memKey = ns.key(name); Sync<Map<CacheKey, byte[]>> sync = Sync.create(); client.get(singleton(memKey), sync); Map<CacheKey, byte[]> result; try { result = sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } catch (TimeoutException timeout) { // Fall through and read the database directly. result = emptyMap(); } byte[] data = result.get(memKey); if (data != null) { if (data.length == 0) return null; return RepositoryKey.fromBytes(data); } RepositoryKey key = db.get(name); data = key != null ? key.asBytes() : new byte[0]; client.modify(singleton(Change.put(memKey, data)), none); return key; }
public RepositoryKey get(RepositoryName name) throws DhtException, TimeoutException { CacheKey memKey = ns.key(name); Sync<Map<CacheKey, byte[]>> sync = Sync.create(); client.get(singleton(memKey), sync); Map<CacheKey, byte[]> result; try { result = sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException(); } catch (TimeoutException timeout) { // Fall through and read the database directly. result = emptyMap(); } byte[] data = result.get(memKey); if (data != null) { if (data.length == 0) return null; return RepositoryKey.fromBytes(data); } RepositoryKey key = db.get(name); data = key != null ? key.asBytes() : new byte[0]; client.modify(singleton(Change.put(memKey, data)), none); return key; }
/** * Schedule any cache change. * * @param op * the cache operation. * @throws DhtException * a prior flush failed. */ public void modify(CacheService.Change op) throws DhtException { int sz = op.getKey().getBytes().length; if (op.getData() != null) sz += op.getData().length; if (add(sz)) { if (pending == null) pending = newList(); pending.add(op); queued(sz); } else { client.modify(singleton(op), wrap(none, sz)); } }
/** * Schedule any cache change. * * @param op * the cache operation. * @throws DhtException * a prior flush failed. */ public void modify(CacheService.Change op) throws DhtException { int sz = op.getKey().getBytes().length; if (op.getData() != null) sz += op.getData().length; if (add(sz)) { if (pending == null) pending = newList(); pending.add(op); queued(sz); } else { client.modify(singleton(op), wrap(none, sz)); } }