@Override public Object getValue() { return casValue.getValue(); } }
@Override protected boolean updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException { final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject); return casResult == CASResponse.OK; }
public void gotData(String k, int flags, long cas, byte[] data) { if (!key.equals(k)) log.warn("Wrong key returned. Key - {}; Returned Key {}", key, k); if (data != null) { if(getAndTouchDataSize == null) getAndTouchDataSize = EVCacheMetricsFactory.getDistributionSummary(appName + "-GATOperation-DataSize", appName, serverGroup.getName()); if (getAndTouchDataSize != null) getAndTouchDataSize.record(data.length); } val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize()))); } });
public void testGets() throws Exception { MemcachedClient client = bootstrapClient(); client.add("getskey", 10, "casValue").get(); CASValue<Object> val = client.gets("getskey"); long oldCas = val.getCas(); assertEquals("casValue", val.getValue()); client.replace("getskey", 10, "myNewVal").get(); val = client.gets("getskey"); assertEquals(oldCas + 1, val.getCas()); assertEquals("myNewVal", val.getValue()); }
public void testCas() throws Exception { MemcachedClient client = bootstrapClient(); client.add("caskey", 10, "casValue").get(); CASValue<Object> val = client.gets("caskey"); assertEquals("casValue", val.getValue()); CASResponse r = client.cas("caskey", val.getCas(), "newValue"); assertEquals(CASResponse.OK, r); r = client.cas("caskey", val.getCas(), "newValue2"); assertEquals(CASResponse.EXISTS, r); }
@Override protected byte[] getStorageObject(final CASValue<Object> casValue) throws ResourceIOException { return castAsByteArray(casValue.getValue()); }
@Override protected Cancellable updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject, final FutureCallback<Boolean> callback) { return operation(client.asyncCAS(storageKey, casValue.getCas(), storageObject), new FutureCallback<CASResponse>() { @Override public void completed(final CASResponse result) { callback.completed(result == CASResponse.OK); } @Override public void failed(final Exception ex) { callback.failed(ex); } @Override public void cancelled() { callback.cancelled(); } }); }
public void receivedStatus(OperationStatus status) { if (!status.isSuccess()) { val = new CASValue<T>(-1, null); } rv.set(val, status); }
@Override protected byte[] getStorageObject(final CASValue<Object> casValue) throws ResourceIOException { return castAsByteArray(casValue.getValue()); }
public Set<String> putIfUntouched(final Map<String, CasPut> values) { final Set<String> successes = new HashSet<>(); values.forEach((key, vals) -> { final long cas = ((SpyIdentifiableValue)vals.getIv()).getCasValue().getCas(); final CASResponse response = client.cas(key, cas, vals.getExpirationSeconds(), toCacheValue(vals.getNextToStore())); if (response == CASResponse.OK) { successes.add(key); } }); return successes; }
public void gotData(String k, int flags, long cas, byte[] data) { assert key.equals(k) : "Wrong key returned"; assert cas > 0 : "CAS was less than zero: " + cas; val = new CASValue<T>(cas, tc.decode(new CachedData(flags, data, tc.getMaxSize()))); }
return value.flatMap(r -> { final CASValue<Object> rObj = (CASValue<Object>)r; final EVCacheValue val = (EVCacheValue)rObj.getValue(); if(val == null || !(val.getKey().equals(key))) { EVCacheMetricsFactory.increment(appName, null, serverGroup.getName(), appName + "-KEY_HASH_COLLISION"); return value.flatMap(r -> { final CASValue<Object> rObj = (CASValue<Object>)r; final EVCacheValue val = (EVCacheValue)rObj.getValue(); if(val == null || !(val.getKey().equals(key))) { EVCacheMetricsFactory.increment(appName, null, serverGroup.getName(), appName + "-KEY_HASH_COLLISION"); return _client.asyncGetAndTouch(key, timeToLive, tc) .get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF, scheduler) .map(value -> (value == null) ? null : value.getValue());
@Override protected boolean updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject) throws ResourceIOException { final CASResponse casResult = client.cas(storageKey, casValue.getCas(), storageObject); return casResult == CASResponse.OK; }
public void gotData(String k, int flags, long cas, byte[] data) { assert key.equals(k) : "Wrong key returned"; assert cas > 0 : "CAS was less than zero: " + cas; val=new CASValue<T>(cas, tc.decode( new CachedData(flags, data, tc.getMaxSize()))); } public void complete() {
/** {@inheritDoc} */ @Override public StorageRecord read(@Nonnull @NotEmpty final String context, @Nonnull @NotEmpty final String key) throws IOException { Constraint.isNotNull(StringSupport.trimOrNull(context), "Context cannot be null or empty"); Constraint.isNotNull(StringSupport.trimOrNull(key), "Key cannot be null or empty"); final String namespace = lookupNamespace(context); if (namespace == null) { logger.debug("Namespace for context {} does not exist", context); return null; } final String cacheKey = memcachedKey(namespace, key); logger.debug("Reading entry at {} for context={}, key={}", cacheKey, context, key); final CASValue<MemcachedStorageRecord> record; try { record = handleAsyncResult(memcacheClient.asyncGets(cacheKey, storageRecordTranscoder)); } catch (RuntimeException e) { throw new IOException("Memcached operation failed", e); } if (record == null) { return null; } record.getValue().setVersion(record.getCas()); return record.getValue(); }
} else { final CASValue<Object> value = _client.asyncGetAndTouch(key, timeToLive, evcacheValueTranscoder).get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF); obj = (value == null) ? null : value.getValue(); } else { final CASValue<T> value = _client.asyncGetAndTouch(key, timeToLive, tc).get(readTimeout.get(), TimeUnit.MILLISECONDS, _throwException, hasZF); returnVal = (value == null) ? null : value.getValue();
@Override protected Cancellable updateCAS( final String storageKey, final CASValue<Object> casValue, final byte[] storageObject, final FutureCallback<Boolean> callback) { return operation(client.asyncCAS(storageKey, casValue.getCas(), storageObject), new FutureCallback<CASResponse>() { @Override public void completed(final CASResponse result) { callback.completed(result == CASResponse.OK); } @Override public void failed(final Exception ex) { callback.failed(ex); } @Override public void cancelled() { callback.cancelled(); } }); }