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

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

本文整理了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

  1. public Object get(String key) {
  2. Future<Object> future = client.asyncGet(key, tc);
  3. try {
  4. return future.get(1, TimeUnit.SECONDS);
  5. } catch (Exception e) {
  6. future.cancel(false);
  7. }
  8. return null;
  9. }

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

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

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

  1. @Override
  2. public Status read(
  3. String table, String key, Set<String> fields,
  4. Map<String, ByteIterator> result) {
  5. key = createQualifiedKey(table, key);
  6. try {
  7. GetFuture<Object> future = memcachedClient().asyncGet(key);
  8. Object document = future.get();
  9. if (document != null) {
  10. fromJson((String) document, fields, result);
  11. }
  12. return Status.OK;
  13. } catch (Exception e) {
  14. logger.error("Error encountered for key: " + key, e);
  15. return Status.ERROR;
  16. }
  17. }

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

  1. @Before
  2. public void setUp() throws Exception {
  3. this.createTestMetadata();
  4. keyValueMap = Maps.newHashMap();
  5. keyValueMap.put("sql1", "value1");
  6. keyValueMap.put("sql11", "value11");
  7. MemcachedCacheConfig cacheConfig = new MemcachedCacheConfig();
  8. MemcachedClient memcachedClient = mock(MemcachedClient.class);
  9. MemcachedCache memcachedCache = new MemcachedCache(memcachedClient, cacheConfig, CacheConstants.QUERY_CACHE,
  10. 7 * 24 * 3600);
  11. memCachedAdaptor = new MemCachedCacheAdaptor(memcachedCache);
  12. //Mock put to cache
  13. for (String key : keyValueMap.keySet()) {
  14. String keyS = memcachedCache.serializeKey(key);
  15. String hashedKey = memcachedCache.computeKeyHash(keyS);
  16. String value = keyValueMap.get(key);
  17. byte[] valueE = memcachedCache.encodeValue(keyS, value);
  18. GetFuture<Object> future = mock(GetFuture.class);
  19. when(future.get(cacheConfig.getTimeout(), TimeUnit.MILLISECONDS)).thenReturn(valueE);
  20. when(memcachedClient.asyncGet(hashedKey)).thenReturn(future);
  21. }
  22. }

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

  1. @Override
  2. protected Cancellable restore(final String storageKey, final FutureCallback<byte[]> callback) {
  3. final GetFuture<Object> getFuture = client.asyncGet(storageKey);
  4. getFuture.addListener(new GetCompletionListener() {
  5. @Override
  6. public void onComplete(final GetFuture<?> future) throws Exception {
  7. try {
  8. callback.completed(castAsByteArray(getFuture.get()));
  9. } catch (final ExecutionException ex) {
  10. if (ex.getCause() instanceof Exception) {
  11. callback.failed((Exception) ex.getCause());
  12. } else {
  13. callback.failed(ex);
  14. }
  15. }
  16. }
  17. });
  18. return Operations.cancellable(getFuture);
  19. }

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. @Override
  2. public <T> T get(String key) {
  3. Future<Object> future = client.asyncGet(key, tc);
  4. try {
  5. return (T) future.get(1, TimeUnit.SECONDS);
  6. } catch (Exception e) {
  7. future.cancel(false);
  8. }
  9. return null;
  10. }

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

  1. @Override
  2. public Object get(String key) {
  3. Future<Object> future = client.asyncGet(key, tc);
  4. try {
  5. return future.get(1, TimeUnit.SECONDS);
  6. } catch (Exception e) {
  7. future.cancel(false);
  8. }
  9. return null;
  10. }

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

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

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

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

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

  1. /**
  2. * Get with a single key.
  3. *
  4. * @param <T>
  5. * @param key the key to get
  6. * @param tc the transcoder to serialize and unserialize value
  7. * @return the result from the cache (null if there is none)
  8. * @throws OperationTimeoutException if the global operation timeout is
  9. * exceeded
  10. * @throws IllegalStateException in the rare circumstance where queue
  11. * is too full to accept any more requests
  12. */
  13. public <T> T get(String key, Transcoder<T> tc) {
  14. try {
  15. return asyncGet(key, tc).get(
  16. operationTimeout, TimeUnit.MILLISECONDS);
  17. } catch (InterruptedException e) {
  18. throw new RuntimeException("Interrupted waiting for value", e);
  19. } catch (ExecutionException e) {
  20. throw new RuntimeException("Exception waiting for value", e);
  21. } catch (TimeoutException e) {
  22. throw new OperationTimeoutException("Timeout waiting for value", e);
  23. }
  24. }

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

  1. public byte[] get(String key) throws KeyValueStoreClientException {
  2. if (!isAlive()) {
  3. throw(new KeyValueStoreClientException(new IllegalStateException("client not established")));
  4. }
  5. byte[] raw = null;
  6. try {
  7. Future<byte[]> f = _client.asyncGet(key, _transcoder);
  8. raw = f.get(_timeoutInMs, TimeUnit.MILLISECONDS);
  9. } catch (Exception error) {
  10. throw(new KeyValueStoreClientException(error));
  11. }
  12. return raw;
  13. }

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

  1. @Override
  2. protected Cancellable restore(final String storageKey, final FutureCallback<byte[]> callback) {
  3. final GetFuture<Object> getFuture = client.asyncGet(storageKey);
  4. getFuture.addListener(new GetCompletionListener() {
  5. @Override
  6. public void onComplete(final GetFuture<?> future) throws Exception {
  7. try {
  8. callback.completed(castAsByteArray(getFuture.get()));
  9. } catch (final ExecutionException ex) {
  10. if (ex.getCause() instanceof Exception) {
  11. callback.failed((Exception) ex.getCause());
  12. } else {
  13. callback.failed(ex);
  14. }
  15. }
  16. }
  17. });
  18. return Operations.cancellable(getFuture);
  19. }

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

  1. /**
  2. * Get the value of the key.
  3. * Check the local cache first. If the key is not found, send the command to the server.
  4. *
  5. * @param key the key to fetch
  6. * @param tc the transcoder to serialize and unserialize value
  7. * @return a future that will hold the value of the key
  8. */
  9. @Override
  10. public <T> Future<T> asyncGet(final String key, final Transcoder<T> tc) {
  11. Element frontElement = null;
  12. if (localCacheManager != null) {
  13. frontElement = localCacheManager.getElement(key);
  14. }
  15. if (frontElement == null) {
  16. return super.asyncGet(key, tc);
  17. } else {
  18. return new FrontCacheGetFuture<T>(frontElement);
  19. }
  20. }

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

  1. @Override
  2. @SuppressWarnings("unchecked")
  3. public <T> T get(String key) throws IOException {
  4. notNullValue("key", key);
  5. try {
  6. if (hasNoAvailableServer()) {
  7. return null;
  8. }
  9. return (T) memcached.asyncGet(getKeyWithNamespace(key)).get(getMaxWaitMillis(), TimeUnit.MILLISECONDS);
  10. } catch (Throwable t) {
  11. String failedMessage = "Failed to get value on memcached! (key:" + key + ")";
  12. throw new IOException(failedMessage, t);
  13. }
  14. }

相关文章