@Override protected void doStart() throws Exception { log.info("starting..."); super.doStart(); _client = newClient(_serverString); if (_client == null) { throw new IllegalStateException("newClient(" + _serverString + ") returns null."); } log.info("use " + _client.getClass().getSimpleName() + " as client factory."); _client.establish(); log.info("started."); }
protected byte[] getKey(final String idInCluster) { log.debug("get: id=" + idInCluster); byte[] raw = null; try { raw = _client.get(mangleKey(idInCluster)); } catch (KeyValueStoreClientException error) { log.warn("unable to get key: id=" + idInCluster, error); } return raw; }
@Override protected void doStop() throws Exception { log.info("stopping..."); if (_client != null) { _client.shutdown(); _client = null; } super.doStop(); log.info("stopped."); }
protected boolean deleteKey(final String idInCluster) { log.debug("delete: id=" + idInCluster); boolean result = false; try { result = _client.delete(mangleKey(idInCluster)); } catch (KeyValueStoreClientException error) { log.warn("unable to delete key: id=" + idInCluster, error); } return result; }
protected boolean setKey(final String idInCluster, final byte[] raw, int expiry) { if (expiry < 0) { expiry = 0; // 0 means forever } log.debug("set: id=" + idInCluster + ", expiry=" + expiry); boolean result = false; try { result = _client.set(mangleKey(idInCluster), raw, expiry); } catch (KeyValueStoreClientException error) { log.warn("unable to set key: id=" + idInCluster, error); } return result; }
protected boolean addKey(final String idInCluster, final byte[] raw, int expiry) { if (expiry < 0) { expiry = 0; // 0 means forever } log.debug("add: id=" + idInCluster + ", expiry=" + expiry); boolean result = false; try { result = _client.add(mangleKey(idInCluster), raw, expiry); } catch (KeyValueStoreClientException error) { log.warn("unable to add key: id=" + idInCluster, error); } return result; }