private void seekChunk(ChunkKey key, boolean cache) throws DhtException, DhtTimeoutException { if (dbChunk == null || !dbChunk.getChunkKey().equals(key)) { dbChunk = chunkReadBackCache.get(key); if (dbChunk == null) { dbWriteBuffer.flush(); Collection<PackChunk.Members> found; Context opt = Context.READ_REPAIR; Sync<Collection<PackChunk.Members>> sync = Sync.create(); db.chunk().get(opt, Collections.singleton(key), sync); try { found = sync.get(objdb.getReaderOptions().getTimeout()); } catch (InterruptedException e) { throw new DhtTimeoutException(e); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } if (found.isEmpty()) { throw new DhtException(MessageFormat.format( DhtText.get().missingChunk, key)); } dbChunk = found.iterator().next().build(); if (cache) chunkReadBackCache.put(key, dbChunk); } } }
private void seekChunk(ChunkKey key, boolean cache) throws DhtException, DhtTimeoutException { if (dbChunk == null || !dbChunk.getChunkKey().equals(key)) { dbChunk = chunkReadBackCache.get(key); if (dbChunk == null) { dbWriteBuffer.flush(); Collection<PackChunk.Members> found; Context opt = Context.READ_REPAIR; Sync<Collection<PackChunk.Members>> sync = Sync.create(); db.chunk().get(opt, Collections.singleton(key), sync); try { found = sync.get(objdb.getReaderOptions().getTimeout()); } catch (InterruptedException e) { throw new DhtTimeoutException(e); } catch (TimeoutException e) { throw new DhtTimeoutException(e); } if (found.isEmpty()) { throw new DhtException(MessageFormat.format( DhtText.get().missingChunk, key)); } dbChunk = found.iterator().next().build(); if (cache) chunkReadBackCache.put(key, dbChunk); } } }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }
DhtReader(DhtObjDatabase objdb) { this.repository = objdb.getRepository(); this.repo = objdb.getRepository().getRepositoryKey(); this.db = objdb.getDatabase(); this.readerOptions = objdb.getReaderOptions(); this.inserterOptions = objdb.getInserterOptions(); this.stats = new Statistics(); this.recentInfo = new RecentInfoCache(getOptions()); this.recentChunks = new RecentChunks(this); this.deltaBaseCache = new DeltaBaseCache(this); }