/** * Update properties by setting fields from the configuration. * <p> * If a property is not defined in the configuration, then it is left * unmodified. * * @param rc * configuration to read properties from. * @return {@code this} */ public CacheOptions fromConfig(final Config rc) { setTimeout(Timeout.getTimeout(rc, "cache", "dht", "timeout", getTimeout())); setWriteBufferSize(rc.getInt("cache", "dht", "writeBufferSize", getWriteBufferSize())); return this; } }
/** Initialize default options. */ public CacheOptions() { setTimeout(Timeout.milliseconds(500)); setWriteBufferSize(512 * 1024); }
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(); } } }
/** * Initialize a new buffer. * * @param dbBuffer * the underlying database's own buffer. * @param client * connection to the cache service. * @param options * options controlling cache operations. */ public CacheBuffer(WriteBuffer dbBuffer, CacheService client, CacheOptions options) { super(null, options.getWriteBufferSize()); this.dbBuffer = dbBuffer; this.client = client; this.none = Sync.none(); }
/** Initialize default options. */ public CacheOptions() { setTimeout(Timeout.milliseconds(500)); setWriteBufferSize(512 * 1024); }
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(); } } }
/** * Initialize a new buffer. * * @param dbBuffer * the underlying database's own buffer. * @param client * connection to the cache service. * @param options * options controlling cache operations. */ public CacheBuffer(WriteBuffer dbBuffer, CacheService client, CacheOptions options) { super(null, options.getWriteBufferSize()); this.dbBuffer = dbBuffer; this.client = client; this.none = Sync.none(); }
/** * Update properties by setting fields from the configuration. * <p> * If a property is not defined in the configuration, then it is left * unmodified. * * @param rc * configuration to read properties from. * @return {@code this} */ public CacheOptions fromConfig(final Config rc) { setTimeout(Timeout.getTimeout(rc, "cache", "dht", "timeout", getTimeout())); setWriteBufferSize(rc.getInt("cache", "dht", "writeBufferSize", getWriteBufferSize())); return this; } }
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; }
result = sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException();
result = sync.get(options.getTimeout()); } catch (InterruptedException e) { throw new TimeoutException();