/** * Auto reconect to memcached server * * @param session */ protected void reconnect(MemcachedTCPSession session) { if (!this.client.isShutdown()) { // Prevent reconnecting repeatedly synchronized (session) { if (!session.isAllowReconnect()) { return; } session.setAllowReconnect(false); } MemcachedSession memcachedTCPSession = session; InetSocketAddressWrapper inetSocketAddressWrapper = memcachedTCPSession.getInetSocketAddressWrapper(); this.client.getConnector().addToWatingQueue( new ReconnectRequest(inetSocketAddressWrapper, 0, this.client.getHealSessionInterval())); } }
public boolean isAlive() { return this._client != null && !this._client.isShutdown(); }
private static void buildClient(){ if(client==null||client.isShutdown()){ synchronized (MemcachedClient.class){ if(client==null||client.isShutdown()){ try { client=clientBuilder.build(); } catch (IOException e) { throw new IllegalStateException("Failed to build memcached client",e); } } } } }
private static void buildClient(){ if(client==null||client.isShutdown()){ synchronized (MemcachedClient.class){ if(client==null||client.isShutdown()){ try { client=clientBuilder.build(); } catch (IOException e) { throw new IllegalStateException("Failed to build memcached client",e); } } } } }
@Override public void shutdown() { if (memcached == null) { throw new IllegalStateException("Memcached client instance has not been initialized yet."); } try { if (!memcached.isShutdown()) { memcached.shutdown(); } } catch (IOException e) { String message = "Failed to shutdown memcached client because " + e.getMessage(); log.info(message); if (log.isDebugEnabled()) { log.debug(message, e); } } }
public boolean establish() throws KeyValueStoreClientException { if (_client != null) { if (!_client.isShutdown()) { return true; } else { shutdown(); } } this._builder = getClientBuilder(_serverString); try { this._client = _builder.build(); } catch (IOException error) { throw(new KeyValueStoreClientException(error)); } return true; }
@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); } }
@Override public byte[] getValue(byte[] key) { if(client.isShutdown()){ buildClient(); } try { byte[] bytes = client. get(new String(key,"UTF-8")); return bytes; } catch (TimeoutException e) { logger.error("Failed to get cache value from memcached", e); } catch (InterruptedException e) { logger.error("Failed to get cache value from memcached", e); } catch (MemcachedException e) { logger.error("Failed to get cache value from memcached", e); } catch (UnsupportedEncodingException e) { logger.error("Failed to get cache value from memcached", e); } return null; } }
@Override public byte[] getValue(byte[] key) { if(client.isShutdown()){ buildClient(); } try { byte[] bytes = client. get(new String(key,"UTF-8")); return bytes; } catch (TimeoutException e) { logger.error("Failed to get cache value from memcached", e); } catch (InterruptedException e) { logger.error("Failed to get cache value from memcached", e); } catch (MemcachedException e) { logger.error("Failed to get cache value from memcached", e); } catch (UnsupportedEncodingException e) { logger.error("Failed to get cache value from memcached", e); } return null; } }
/** * Auto reconect to memcached server * * @param session */ protected void reconnect(MemcachedTCPSession session) { if (!this.client.isShutdown()) { // Prevent reconnecting repeatedly synchronized (session) { if (!session.isAllowReconnect()) { return; } session.setAllowReconnect(false); } MemcachedSession memcachedTCPSession = session; InetSocketAddressWrapper inetSocketAddressWrapper = memcachedTCPSession.getInetSocketAddressWrapper(); this.client.getConnector().addToWatingQueue( new ReconnectRequest(inetSocketAddressWrapper, 0, this.client.getHealSessionInterval())); } }