当前位置: 首页>>代码示例>>Java>>正文


Java CASValue.getCas方法代码示例

本文整理汇总了Java中net.spy.memcached.CASValue.getCas方法的典型用法代码示例。如果您正苦于以下问题:Java CASValue.getCas方法的具体用法?Java CASValue.getCas怎么用?Java CASValue.getCas使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.spy.memcached.CASValue的用法示例。


在下文中一共展示了CASValue.getCas方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gets

import net.spy.memcached.CASValue; //导入方法依赖的package包/类
public com.quickserverlab.quickcached.client.CASValue gets(String key, long timeoutMiliSec) 
		throws TimeoutException, com.quickserverlab.quickcached.client.MemcachedException{
	com.quickserverlab.quickcached.client.CASValue value = null;
	try{
		OperationFuture <CASValue<Object>> f =  getCache().asyncGets(key);
		try {
			CASValue<Object> cv = (CASValue<Object>) f.get(timeoutMiliSec, TimeUnit.MILLISECONDS);
			if(cv != null){
				value = new com.quickserverlab.quickcached.client.CASValue(cv.getCas(), cv.getValue());
			}else{
				throw new com.quickserverlab.quickcached.client.MemcachedException("Object not found");
			}
		}catch(InterruptedException ie){
			throw new com.quickserverlab.quickcached.client.MemcachedException("InterruptedException "+ ie);
		}catch(ExecutionException ee){
			throw new com.quickserverlab.quickcached.client.MemcachedException("ExecutionException "+ ee);
		}catch(java.util.concurrent.TimeoutException te){
			throw new TimeoutException("Timeout "+ te);
		}finally{
			f.cancel(false);
		}
	}catch(IllegalStateException ise){
		throw new com.quickserverlab.quickcached.client.MemcachedException("IllegalStateException "+ ise);
	}
	return value;				
}
 
开发者ID:QuickServerLab,项目名称:QuickCached,代码行数:27,代码来源:SpyMemcachedImpl.java

示例2: testGets

import net.spy.memcached.CASValue; //导入方法依赖的package包/类
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());
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:12,代码来源:GemcachedDevelopmentJUnitTest.java

示例3: retrieveWithCas

import net.spy.memcached.CASValue; //导入方法依赖的package包/类
/**
 * Retrieves an object along with its cas using the given key
 * 
 * @param keyString
 * @return
 * @throws Exception
 */
private ObjectWithCas retrieveWithCas(final String keyString) {
  CASValue<Object> retrieved = null;

  if (configuration.isUsingAsyncGet()) {
    Future<CASValue<Object>> future;
    if (configuration.isCompressionEnabled()) {
      future = client.asyncGets(keyString, new CompressorTranscoder());
    } else {
      future = client.asyncGets(keyString);
    }

    try {
      retrieved = future.get(configuration.getTimeout(), configuration.getTimeUnit());
    } catch (Exception e) {
      future.cancel(false);
      throw new CacheException(e);
    }
  } else {
    if (configuration.isCompressionEnabled()) {
      retrieved = client.gets(keyString, new CompressorTranscoder());
    } else {
      retrieved = client.gets(keyString);
    }
  }

  if (retrieved == null) {
    return null;
  }

  return new ObjectWithCas(retrieved.getValue(), retrieved.getCas());
}
 
开发者ID:mybatis,项目名称:memcached-cache,代码行数:39,代码来源:MemcachedClientWrapper.java

示例4: do_simple_test

import net.spy.memcached.CASValue; //导入方法依赖的package包/类
public boolean do_simple_test(client cli) throws Exception {
  // Pick a key
  String key = cli.ks.get_key();

  // Insert an item
  if (!cli.before_request())
    return false;
  byte[] val = cli.vset.get_value();
  Future<Boolean> fb = 
    cli.next_ac.set(key, cli.conf.client_exptime, val, raw_transcoder.raw_tc);
  boolean ok = fb.get(1000L, TimeUnit.MILLISECONDS);
  if (!ok) {
    System.out.printf("set failed. id=%d key=%s\n", cli.id, key);
  }
  if (!cli.after_request(ok))
    return false;

  // Gets
  Future<CASValue<byte[]>> fcv = 
    cli.next_ac.asyncGets(key, raw_transcoder.raw_tc);
  CASValue<byte[]> casv = fcv.get(1000L, TimeUnit.MILLISECONDS);
  ok = (casv != null);
  if (!cli.after_request(ok))
    return false;
  if (!ok) {
    System.out.printf("gets failed. id=%d key=%s\n", cli.id, key);
    return true; // stop doing CAS operations.
  }

  byte[] get_val = casv.getValue();
  long cas_num = casv.getCas();
  if (!Arrays.equals(val, get_val)) {
    System.out.printf("gets value does not match the original value." +
                      " id=%d key=%s\n", cli.id, key);
  }
  
  // CAS.  Use cas_num+1 to see if it fails.
  val = cli.vset.get_value();
  Future<CASResponse> fcr = 
    cli.next_ac.asyncCAS(key, cas_num+1, val, raw_transcoder.raw_tc);
  CASResponse casr = fcr.get(1000L, TimeUnit.MILLISECONDS);
  ok = (casr != CASResponse.OK);
  if (!cli.after_request(ok))
    return false;
  if (!ok) {
    System.out.println("CAS returns an unexpected OK response." +
                       " id=" + cli.id + " key=" + key + 
                       " response=" + casr);
  }

  // CAS.  Use cas_num.  This time, CAS should succeed.
  fcr = cli.next_ac.asyncCAS(key, cas_num, val, raw_transcoder.raw_tc);
  casr = fcr.get(1000L, TimeUnit.MILLISECONDS);
  ok = (casr == CASResponse.OK);
  if (!cli.after_request(ok))
    return false;
  if (!ok) {
    System.out.println("CAS returns an unexpected non-OK response." +
                       " id=" + cli.id + " key=" + key + 
                       " response=" + casr);
  }

  return true;
}
 
开发者ID:naver,项目名称:arcus-misc,代码行数:65,代码来源:torture_cas.java


注:本文中的net.spy.memcached.CASValue.getCas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。