本文整理汇总了Java中net.spy.memcached.internal.OperationFuture类的典型用法代码示例。如果您正苦于以下问题:Java OperationFuture类的具体用法?Java OperationFuture怎么用?Java OperationFuture使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OperationFuture类属于net.spy.memcached.internal包,在下文中一共展示了OperationFuture类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTouch
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testTouch() throws Exception {
if (serverSupportsTouch()) {
return;
}
String value = UUID.randomUUID().toString();
Boolean didSet = memcacheClient.set("key", 0, value).get();
assertTrue(didSet);
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("touch");
OperationFuture<Boolean> operationFuture = memcacheClient.touch("key", 0);
Boolean touched = operationFuture.get();
assertTrue(touched);
tracker.validate(expectedValues);
/*
//Touch operation does not return cas value
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", operationFuture.getCas(), value1);
assertEquals(CASResponse.OK, response);
*/
}
示例2: testAppendCas
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testAppendCas() throws Exception {
String value = UUID.randomUUID().toString();
OperationFuture<Boolean> setFuture = memcacheClient.set("key", 0, value);
Boolean didSet = setFuture.get();
assertTrue(didSet);
Long cas = setFuture.getCas();
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("append");
String value1 = UUID.randomUUID().toString();
Boolean appended = memcacheClient.append(cas, "key", value1).get();
assertTrue(appended);
tracker.validate(expectedValues);
Object val = memcacheClient.get("key");
assertEquals(value + value1, val);
}
示例3: testPrependCas
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testPrependCas() throws Exception {
String value = UUID.randomUUID().toString();
OperationFuture<Boolean> setFuture = memcacheClient.set("key", 0, value);
Boolean didSet = setFuture.get();
assertTrue(didSet);
Long cas = setFuture.getCas();
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("prepend");
String value1 = UUID.randomUUID().toString();
Boolean appended = memcacheClient.prepend(cas, "key", value1).get();
assertTrue(appended);
tracker.validate(expectedValues);
Object val = memcacheClient.get("key");
assertEquals(value1 + value, val);
}
示例4: testAsyncCas
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testAsyncCas() throws Exception {
String value = UUID.randomUUID().toString();
OperationFuture<Boolean> setFuture = memcacheClient.set("key", 0, value);
Boolean didSet = setFuture.get();
assertTrue(didSet);
Long cas = setFuture.getCas();
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("set");
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.asyncCAS("key", cas, value1).get();
assertEquals(CASResponse.OK, response);
tracker.validate(expectedValues);
Object val = memcacheClient.get("key");
assertEquals(value1, val);
}
示例5: testCas
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testCas() throws Exception {
String value = UUID.randomUUID().toString();
OperationFuture<Boolean> setFuture = memcacheClient.set("key", 0, value);
Boolean didSet = setFuture.get();
assertTrue(didSet);
Long cas = setFuture.getCas();
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("set");
String value1 = UUID.randomUUID().toString();
CASResponse response = memcacheClient.cas("key", cas, value1);
assertEquals(CASResponse.OK, response);
tracker.validate(expectedValues);
Object val = memcacheClient.get("key");
assertEquals(value1, val);
}
示例6: testDeleteCas
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Test
public void testDeleteCas() throws Exception {
String value = UUID.randomUUID().toString();
OperationFuture<Boolean> future = memcacheClient.set("key", 0, value);
assertTrue(future.get());
long cas = future.getCas();
Snapshot expectedValues = tracker.snapshot();
expectedValues.increment("delete");
Boolean deleted = memcacheClient.delete("key", cas).get();
assertTrue(deleted);
tracker.validate(expectedValues);
Object val = memcacheClient.get("key");
assertNull(val);
}
示例7: setKeyValueInCouchBase
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
public void setKeyValueInCouchBase(T tuple)
{
id++;
String key = getKey(tuple);
Object value = getValue(tuple);
if (!(value instanceof Boolean) && !(value instanceof Integer) && !(value instanceof String) && !(value instanceof Float) && !(value instanceof Double) && !(value instanceof Character) && !(value instanceof Long) && !(value instanceof Short) && !(value instanceof Byte)) {
if (serializer != null) {
value = serializer.serialize(value);
}
}
OperationFuture<Boolean> future = processKeyValue(key, value);
synchronized (syncObj) {
future.addListener(listener);
mapFuture.put(future, id);
if (!mapTuples.containsKey(id)) {
mapTuples.put(id, tuple);
}
numTuples++;
}
}
示例8: onComplete
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Override
public void onComplete(OperationFuture<?> f) throws Exception
{
if (!((Boolean)f.get())) {
logger.error("Operation failed {}", f);
failure = true;
return;
}
synchronized (syncObj) {
long idProcessed = mapFuture.get(f);
mapTuples.remove(idProcessed);
mapFuture.remove(f);
numTuples--;
syncObj.notify();
}
}
示例9: setInternal
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Override
protected void setInternal(final MemcachedClient mc, final String path,
final List<INode> inodes) {
if (INode.getPathNames(path).length != inodes.size()) {
return;
}
final String key = getKey(path);
final int[] inodeIds = getINodeIds(inodes);
final long startTime = System.currentTimeMillis();
mc.set(key, keyExpiry, new CacheEntry(inodeIds))
.addListener(new OperationCompletionListener() {
@Override
public void onComplete(OperationFuture<?> f) throws Exception {
long elapsed = System.currentTimeMillis() - startTime;
LOG.debug("SET for path (" + path + ") " + key + "=" +
Arrays.toString(inodeIds) + " in " + elapsed + " msec");
}
});
}
示例10: getStatusWithretriesOnTimeout
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
private static OperationStatus getStatusWithretriesOnTimeout(
OperationFuture<Boolean> rv, int tries) {
int i = 0;
boolean shouldRetry = false;
do {
try {
shouldRetry = false;
return rv.getStatus();
} catch (Exception exception) {
if (exception.getCause() instanceof CheckedOperationTimeoutException
|| exception instanceof CheckedOperationTimeoutException) {
log.warn("Try[" + (tries - i) + "] Wait for response. Of:"
+ rv);
shouldRetry = true;
}
}
} while (++i < tries && shouldRetry);
return rv.getStatus();
}
示例11: add
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
@Override
public boolean add(Object key, Serializable obj) {
try {
if (key == null) {
return Boolean.TRUE;
} else {
String _key = getKey(key);
OperationFuture<Boolean> f = (OperationFuture<Boolean>) client
.add(_key, expireTime, obj);
return WaitResponseUtils.waitForResponse(f, 3, "add");
}
} catch (Exception alle) {
log.warn("For information only, there is exception in memcached add method, please ignore it,"
+ " unable to add key:" + key);
if (log.isDebugEnabled()) {
log.debug(
"For information only, there is exception in memcached add method, please ignore it,"
+ " unable to add key:" + key, alle);
}
return Boolean.FALSE;
} finally {
if (listener != null)
listener.put(key, obj);
}
}
示例12: putWithSlowDownLogic
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
private OperationFuture<Boolean> putWithSlowDownLogic(Object key,
int expiration, Serializable obj) {
OperationFuture<Boolean> rv = null;
while (rv == null) {
try {
rv = (OperationFuture<Boolean>) client.set(getKey(key),
expiration, obj);
} catch (IllegalStateException ex) {
log.debug("slow down"); // Need to slow down a bit when
// we start getting rejections.
try {
if (rv != null) {
rv.get(250, TimeUnit.MILLISECONDS);
} else {
Thread.sleep(250);
}
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
} catch (Exception e2) {
// Ignore exceptions here. We're just trying to slow
// down input.
}
}
}
return rv;
}
示例13: unlock
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
private void unlock(Message<JsonObject> message) throws InterruptedException, ExecutionException {
JsonObject json = message.body();
String key = getMandatoryString("key", message);
Long cas = json.getLong("cas");
if (key == null || cas == null) {
sendError(message, "key and cas must be specified");
return;
}
OperationFuture<Boolean> unlockFuture = client.asyncUnlock(key, cas);
boolean response = unlockFuture.get();
if (response) {
JsonObject reply = new JsonObject();
reply.putString("key", unlockFuture.getKey());
sendOK(message, reply);
}
else {
sendError(message, unlockFuture.getStatus().getMessage());
}
}
示例14: touch
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
private void touch(Message<JsonObject> message) throws InterruptedException, ExecutionException {
JsonObject json = message.body();
String key = getMandatoryString("key", message);
int expiration = json.getInteger("expiration", 0);
if (key == null) {
sendError(message, "key must be specified");
return;
}
OperationFuture<Boolean> touchFuture = client.touch(key, expiration);
boolean response = touchFuture.get();
if (response) {
JsonObject reply = new JsonObject();
reply.putString("key", touchFuture.getKey());
sendOK(message, reply);
}
else {
sendError(message, touchFuture.getStatus().getMessage());
}
}
示例15: store
import net.spy.memcached.internal.OperationFuture; //导入依赖的package包/类
protected OperationFuture<Boolean> store(CouchbaseOperation operation,
String key, Object value, int expiry) {
switch (operation) {
case SET:
return couchbaseClient.set(key, expiry, value);
case ADD:
return couchbaseClient.add(key, expiry, value);
case REPLACE:
return couchbaseClient.replace(key, expiry, value);
case APPEND:
return couchbaseClient.append(key, value);
case PREPEND:
return couchbaseClient.prepend(key, value);
case DELETE:
return couchbaseClient.delete(key);
case TOUCH:
return couchbaseClient.touch(key, expiry);
case EXISTS:
return couchbaseClient.touch(key, expiry);
default:
// Ignore this action.
return null;
}
}