net.spy.memcached.MemcachedClient.asyncGet()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.7k)|赞(0)|评价(0)|浏览(192)

本文整理了Java中net.spy.memcached.MemcachedClient.asyncGet()方法的一些代码示例,展示了MemcachedClient.asyncGet()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MemcachedClient.asyncGet()方法的具体详情如下:
包路径:net.spy.memcached.MemcachedClient
类名称:MemcachedClient
方法名:asyncGet

MemcachedClient.asyncGet介绍

[英]Get the given key asynchronously and decode with the default transcoder.
[中]异步获取给定密钥,并使用默认转码器进行解码。

代码示例

代码示例来源:origin: ninjaframework/ninja

public Object get(String key) {
  Future<Object> future = client.asyncGet(key, tc);
  try {
    return future.get(1, TimeUnit.SECONDS);
  } catch (Exception e) {
    future.cancel(false);
  }
  return null;
}

代码示例来源:origin: apache/kylin

when(memcachedClient.asyncGet(hashedKey)).thenReturn(future);
when(memcachedClient.asyncGet(hashedKey)).thenReturn(future);
when(future.get(cacheConfig.getTimeout(), TimeUnit.MILLISECONDS)).thenReturn(valueE);

代码示例来源:origin: brianfrankcooper/YCSB

@Override
public Status read(
  String table, String key, Set<String> fields,
  Map<String, ByteIterator> result) {
 key = createQualifiedKey(table, key);
 try {
  GetFuture<Object> future = memcachedClient().asyncGet(key);
  Object document = future.get();
  if (document != null) {
   fromJson((String) document, fields, result);
  }
  return Status.OK;
 } catch (Exception e) {
  logger.error("Error encountered for key: " + key, e);
  return Status.ERROR;
 }
}

代码示例来源:origin: apache/kylin

@Before
public void setUp() throws Exception {
  this.createTestMetadata();
  keyValueMap = Maps.newHashMap();
  keyValueMap.put("sql1", "value1");
  keyValueMap.put("sql11", "value11");
  MemcachedCacheConfig cacheConfig = new MemcachedCacheConfig();
  MemcachedClient memcachedClient = mock(MemcachedClient.class);
  MemcachedCache memcachedCache = new MemcachedCache(memcachedClient, cacheConfig, CacheConstants.QUERY_CACHE,
      7 * 24 * 3600);
  memCachedAdaptor = new MemCachedCacheAdaptor(memcachedCache);
  //Mock put to cache
  for (String key : keyValueMap.keySet()) {
    String keyS = memcachedCache.serializeKey(key);
    String hashedKey = memcachedCache.computeKeyHash(keyS);
    String value = keyValueMap.get(key);
    byte[] valueE = memcachedCache.encodeValue(keyS, value);
    GetFuture<Object> future = mock(GetFuture.class);
    when(future.get(cacheConfig.getTimeout(), TimeUnit.MILLISECONDS)).thenReturn(valueE);
    when(memcachedClient.asyncGet(hashedKey)).thenReturn(future);
  }
}

代码示例来源:origin: apache/httpcomponents-client

@Override
protected Cancellable restore(final String storageKey, final FutureCallback<byte[]> callback) {
  final GetFuture<Object> getFuture = client.asyncGet(storageKey);
  getFuture.addListener(new GetCompletionListener() {
    @Override
    public void onComplete(final GetFuture<?> future) throws Exception {
      try {
        callback.completed(castAsByteArray(getFuture.get()));
      } catch (final ExecutionException ex) {
        if (ex.getCause() instanceof Exception) {
          callback.failed((Exception) ex.getCause());
        } else {
          callback.failed(ex);
        }
      }
    }
  });
  return Operations.cancellable(getFuture);
}

代码示例来源:origin: com.google.code.maven-play-plugin.spy/memcached

/**
 * Get the given key asynchronously and decode with the default
 * transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public Future<Object> asyncGet(final String key) {
  return asyncGet(key, transcoder);
}

代码示例来源:origin: net.spy/spymemcached

/**
 * Get the given key asynchronously and decode with the default transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public GetFuture<Object> asyncGet(final String key) {
 return asyncGet(key, transcoder);
}

代码示例来源:origin: naver/arcus-java-client

/**
 * Get the given key asynchronously and decode with the default
 * transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue
 *                               is too full to accept any more requests
 */
public Future<Object> asyncGet(final String key) {
 return asyncGet(key, transcoder);
}

代码示例来源:origin: com.google.code.simple-spring-memcached/spymemcached

/**
 * Get the given key asynchronously and decode with the default transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
public GetFuture<Object> asyncGet(final String key) {
 return asyncGet(key, transcoder);
}

代码示例来源:origin: com.amazonaws/elasticache-java-cluster-client

/**
 * Get the given key asynchronously and decode with the default transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue is too
 *           full to accept any more requests
 */
@Override
public GetFuture<Object> asyncGet(final String key) {
 return asyncGet(key, transcoder);
}

代码示例来源:origin: com.google.code.maven-play-plugin.spy/spymemcached

/**
 * Get the given key asynchronously and decode with the default
 * transcoder.
 *
 * @param key the key to fetch
 * @return a future that will hold the return value of the fetch
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public Future<Object> asyncGet(final String key) {
  return asyncGet(key, transcoder);
}

代码示例来源:origin: org.osgl/osgl-cache

@Override
public <T> T get(String key) {
  Future<Object> future = client.asyncGet(key, tc);
  try {
    return (T) future.get(1, TimeUnit.SECONDS);
  } catch (Exception e) {
    future.cancel(false);
  }
  return null;
}

代码示例来源:origin: com.google.code.maven-play-plugin.org.playframework/play

@Override
public Object get(String key) {
  Future<Object> future = client.asyncGet(key, tc);
  try {
    return future.get(1, TimeUnit.SECONDS);
  } catch (Exception e) {
    future.cancel(false);
  }
  return null;
}

代码示例来源:origin: net.anthavio/hatatitla

@Override
protected CacheEntry<V> doGet(String cacheKey) throws Exception {
  if (cacheKey.length() > MaxKeyLength) {
    throw new IllegalArgumentException("Key length exceded maximum " + MaxKeyLength);
  }
  Future<Object> future = client.asyncGet(cacheKey);
  try {
    return (CacheEntry<V>) future.get(operationTimeout, TimeUnit.MILLISECONDS);
  } catch (CheckedOperationTimeoutException cotx) {
    logger.warn("GET operation timeout: " + operationTimeout + " millis, Key: " + cacheKey);
    return null;
  }
}

代码示例来源:origin: caskdata/coopr

@Override
byte[] getValue(String tenantId, String clusterId) throws IOException {
 // to prevent continuous retries if the memcache server is down
 // Try to get a value, for up to 5 seconds, and cancel if it doesn't return
 Future<Object> f = client.asyncGet(getKey(tenantId, clusterId));
 try {
  return (byte[]) f.get(timeoutSeconds, TimeUnit.SECONDS);
 } catch (TimeoutException e) {
  LOG.error("Timed out after {} seconds getting credentials for tenant {} and cluster {} from memcache.",
       timeoutSeconds, tenantId, clusterId, e);
  // Since we don't need this, go ahead and cancel the operation.  This
  // is not strictly necessary, but it'll save some work on the server.
  f.cancel(false);
  throw new IOException(e);
 } catch (Exception e) {
  LOG.error("Exception getting credentials for tenant {} and cluster {} from memcache.", e);
  throw new IOException(e);
 }
}

代码示例来源:origin: com.google.code.maven-play-plugin.spy/spymemcached

/**
 * Get with a single key.
 *
 * @param <T>
 * @param key the key to get
 * @param tc the transcoder to serialize and unserialize value
 * @return the result from the cache (null if there is none)
 * @throws OperationTimeoutException if the global operation timeout is
 *           exceeded
 * @throws IllegalStateException in the rare circumstance where queue
 *         is too full to accept any more requests
 */
public <T> T get(String key, Transcoder<T> tc) {
  try {
    return asyncGet(key, tc).get(
      operationTimeout, TimeUnit.MILLISECONDS);
  } catch (InterruptedException e) {
    throw new RuntimeException("Interrupted waiting for value", e);
  } catch (ExecutionException e) {
    throw new RuntimeException("Exception waiting for value", e);
  } catch (TimeoutException e) {
    throw new OperationTimeoutException("Timeout waiting for value", e);
  }
}

代码示例来源:origin: yyuu/jetty-nosql-memcached

public byte[] get(String key) throws KeyValueStoreClientException {
  if (!isAlive()) {
    throw(new KeyValueStoreClientException(new IllegalStateException("client not established")));
  }
  byte[] raw = null;
  try {
    Future<byte[]> f = _client.asyncGet(key, _transcoder);
    raw = f.get(_timeoutInMs, TimeUnit.MILLISECONDS);
  } catch (Exception error) {
    throw(new KeyValueStoreClientException(error));
  }
  return raw;
}

代码示例来源:origin: org.apache.httpcomponents.client5/httpclient5-cache

@Override
protected Cancellable restore(final String storageKey, final FutureCallback<byte[]> callback) {
  final GetFuture<Object> getFuture = client.asyncGet(storageKey);
  getFuture.addListener(new GetCompletionListener() {
    @Override
    public void onComplete(final GetFuture<?> future) throws Exception {
      try {
        callback.completed(castAsByteArray(getFuture.get()));
      } catch (final ExecutionException ex) {
        if (ex.getCause() instanceof Exception) {
          callback.failed((Exception) ex.getCause());
        } else {
          callback.failed(ex);
        }
      }
    }
  });
  return Operations.cancellable(getFuture);
}

代码示例来源:origin: naver/arcus-java-client

/**
 * Get the value of the key.
 * Check the local cache first. If the key is not found, send the command to the server.
 *
 * @param key the key to fetch
 * @param tc  the transcoder to serialize and unserialize value
 * @return a future that will hold the value of the key
 */
@Override
public <T> Future<T> asyncGet(final String key, final Transcoder<T> tc) {
 Element frontElement = null;
 if (localCacheManager != null) {
  frontElement = localCacheManager.getElement(key);
 }
 if (frontElement == null) {
  return super.asyncGet(key, tc);
 } else {
  return new FrontCacheGetFuture<T>(frontElement);
 }
}

代码示例来源:origin: com.m3/memcached-client-facade

@Override
@SuppressWarnings("unchecked")
public <T> T get(String key) throws IOException {
  notNullValue("key", key);
  try {
    if (hasNoAvailableServer()) {
      return null;
    }
    return (T) memcached.asyncGet(getKeyWithNamespace(key)).get(getMaxWaitMillis(), TimeUnit.MILLISECONDS);
  } catch (Throwable t) {
    String failedMessage = "Failed to get value on memcached! (key:" + key + ")";
    throw new IOException(failedMessage, t);
  }
}

相关文章