public Counter(MemcachedClient memcachedClient, String key, long initialValue) { super(); this.memcachedClient = memcachedClient; this.key = key; this.initialValue = initialValue; try { this.memcachedClient.add(key, 0, String.valueOf(this.initialValue)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { throw new IllegalStateException("Initialize counter failed", e); } }
public Counter(MemcachedClient memcachedClient, String key, long initialValue) { super(); this.memcachedClient = memcachedClient; this.key = key; this.initialValue = initialValue; try { this.memcachedClient.add(key, 0, String.valueOf(this.initialValue)); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } catch (Exception e) { throw new IllegalStateException("Initialize counter failed", e); } }
@Override public boolean add(final String key, final int exp, final Object value) throws TimeoutException, CacheException { try { return memcachedClient.add(key, exp, value); } catch (MemcachedException | InterruptedException e) { throw new CacheException(e); } }
@Override public <T> boolean add(final String key, final int exp, final T value, final CacheTranscoder transcoder) throws TimeoutException, CacheException { try { return memcachedClient.add(key, exp, value, getTranscoder(transcoder)); } catch (MemcachedException | InterruptedException e) { throw new CacheException(e); } }
public boolean add(String key, byte[] raw, int exp) throws KeyValueStoreClientException { if (!isAlive()) { throw(new KeyValueStoreClientException(new IllegalStateException("client not established"))); } boolean result = false; try { result = _client.add(key, exp, raw); } catch (Exception error) { throw(new KeyValueStoreClientException(error)); } return result; }
@Override public void cacheValue(byte[] key, byte[] bytes, int expireSecond) { if(client.isShutdown()){ buildClient(); } try { client.add(new String(key,"UTF-8"),expireSecond,bytes); } catch (TimeoutException e) { logger.error("Failed to add cache value by memcached",e); } catch (InterruptedException e) { logger.error("Failed to add cache value by memcached", e); } catch (MemcachedException e) { logger.error("Failed to add cache value by memcached",e); } catch (UnsupportedEncodingException e) { logger.error("Failed to add cache value by memcached", e); } }
@Override public void cacheValue(byte[] key, byte[] bytes, int expireSecond) { if(client.isShutdown()){ buildClient(); } try { client.add(new String(key,"UTF-8"),expireSecond,bytes); } catch (TimeoutException e) { logger.error("Failed to add cache value by memcached",e); } catch (InterruptedException e) { logger.error("Failed to add cache value by memcached", e); } catch (MemcachedException e) { logger.error("Failed to add cache value by memcached",e); } catch (UnsupportedEncodingException e) { logger.error("Failed to add cache value by memcached", e); } }