public synchronized void onPartialResult(Collection<PackChunk.Members> res) { try { bytesLoading -= averageChunkSize * res.size(); for (PackChunk.Members builder : res) chunkIsReady(builder.build()); } catch (DhtException loadError) { onError(loadError); } }
private void maybeStartGet() { if (!queue.isEmpty() && bytesReady + bytesLoading <= lowWaterMark) forceStartGet(); }
private PackChunk useReadyChunk(ChunkKey key) { PackChunk chunk = ready.remove(key); status.put(chunk.getChunkKey(), Status.DONE); bytesReady -= chunk.getTotalSize(); if (automaticallyPushHints) { push(chunk.getMeta()); maybeStartGet(); } return chunk; }
ChunkKey startKey = chunk(trees.get(start)); if (startKey == null) throw DhtReader.missing(start, OBJ_TREE); ChunkKey endKey = chunk(trees.get(end)); if (endKey == null) throw DhtReader.missing(end, OBJ_TREE); push(startKey); maybeStartGet();
private void init() throws IOException { ObjectWithInfo<T> c; while ((c = nextObjectWithInfo()) != null) { ChunkKey chunkKey = c.chunkKey; Collection<ObjectWithInfo<T>> list = byChunk.get(chunkKey); if (list == null) { list = new ArrayList<ObjectWithInfo<T>>(); byChunk.put(chunkKey, list); if (prefetcher == null) { int limit = reader.getOptions().getChunkLimit(); int ratio = reader.getOptions().getOpenQueuePrefetchRatio(); int prefetchLimit = (int) (limit * (ratio / 100.0)); reader.getRecentChunks().setMaxBytes(limit - prefetchLimit); prefetcher = new Prefetcher(reader, 0, prefetchLimit); } prefetcher.push(chunkKey); } list.add(c); } chunkItr = byChunk.values().iterator(); } }
forceStartGet(); continue GET; queue.addFirst(key); forceStartGet(); continue GET; return useReadyChunk(key);
Map<String, Long> startsAt = new HashMap<String, Long>(); for (ChunkKey key : keyList) { PackChunk chunk = prefetcher.get(key);
void push(Iterable<ChunkKey> list) { synchronized (this) { for (ChunkKey key : list) { if (status.containsKey(key)) continue; status.put(key, Status.ON_QUEUE); queue.add(key); if (key.equals(stopAt)) { automaticallyPushHints = false; break; } } if (!first) maybeStartGet(); } }
private Prefetcher prefetch(final int type, final int ratio) { int limit = readerOptions.getChunkLimit(); int prefetchLimit = (int) (limit * (ratio / 100.0)); recentChunks.setMaxBytes(limit - prefetchLimit); return new Prefetcher(this, type, prefetchLimit); }
public synchronized void onSuccess(Collection<PackChunk.Members> result) { if (result != null && !result.isEmpty()) onPartialResult(result); }
public synchronized void onFailure(DhtException asyncError) { onError(asyncError); }
ChunkKey startKey = chunk(trees.get(start)); if (startKey == null) throw DhtReader.missing(start, OBJ_TREE); ChunkKey endKey = chunk(trees.get(end)); if (endKey == null) throw DhtReader.missing(end, OBJ_TREE); push(startKey); maybeStartGet();
private void init() throws IOException { ObjectWithInfo<T> c; while ((c = nextObjectWithInfo()) != null) { ChunkKey chunkKey = c.chunkKey; Collection<ObjectWithInfo<T>> list = byChunk.get(chunkKey); if (list == null) { list = new ArrayList<ObjectWithInfo<T>>(); byChunk.put(chunkKey, list); if (prefetcher == null) { int limit = reader.getOptions().getChunkLimit(); int ratio = reader.getOptions().getOpenQueuePrefetchRatio(); int prefetchLimit = (int) (limit * (ratio / 100.0)); reader.getRecentChunks().setMaxBytes(limit - prefetchLimit); prefetcher = new Prefetcher(reader, 0, prefetchLimit); } prefetcher.push(chunkKey); } list.add(c); } chunkItr = byChunk.values().iterator(); } }
forceStartGet(); continue GET; queue.addFirst(key); forceStartGet(); continue GET; return useReadyChunk(key);
Map<String, Long> startsAt = new HashMap<String, Long>(); for (ChunkKey key : keyList) { PackChunk chunk = prefetcher.get(key);
void push(Iterable<ChunkKey> list) { synchronized (this) { for (ChunkKey key : list) { if (status.containsKey(key)) continue; status.put(key, Status.ON_QUEUE); queue.add(key); if (key.equals(stopAt)) { automaticallyPushHints = false; break; } } if (!first) maybeStartGet(); } }
private Prefetcher prefetch(final int type, final int ratio) { int limit = readerOptions.getChunkLimit(); int prefetchLimit = (int) (limit * (ratio / 100.0)); recentChunks.setMaxBytes(limit - prefetchLimit); return new Prefetcher(this, type, prefetchLimit); }
public synchronized void onSuccess(Collection<PackChunk.Members> result) { if (result != null && !result.isEmpty()) onPartialResult(result); }