_idManager.stop(); _idManager.setScavengePeriod((int) TimeUnit.SECONDS.toMillis(_scavengePeriod)); _idManager.setWorkerName("node0"); _idManager.start(); _idManager = new MemcachedSessionIdManager(_server, config, clientFactory); _idManager.setScavengePeriod((int)TimeUnit.SECONDS.toMillis(_scavengePeriod)); _idManager.setKeyPrefix("MemcachedTestServer::"); _idManager.setKeySuffix("::MemcachedTestServer"); _idManager.setDefaultExpiry(_idManager.getDefaultExpiry()); _idManager.setServerString(_idManager.getServerString()); _idManager.setTimeoutInMs(_idManager.getTimeoutInMs());
protected boolean addKey(final String idInCluster, final byte[] raw) { return addKey(idInCluster, raw, getDefaultExpiry()); }
protected boolean deleteKey(final String idInCluster) { return ((KeyValueStoreSessionIdManager) _sessionIdManager).deleteKey(mangleKey(idInCluster)); }
protected boolean setKey(final String idInCluster, final byte[] raw) { return setKey(idInCluster, raw, getDefaultExpiry()); }
@Override public void renewSessionId(final String oldClusterId, final String oldNodeId, final HttpServletRequest request) { //generate a new id String newClusterId = newSessionId(request.hashCode()); //tell all contexts to update the id Handler[] contexts = _server.getChildHandlersByClass(ContextHandler.class); for (int i = 0; contexts != null && i < contexts.length; i++) { SessionHandler sessionHandler = ((ContextHandler) contexts[i]).getChildHandlerByClass(SessionHandler.class); if (sessionHandler != null) { SessionManager manager = sessionHandler.getSessionManager(); if (manager != null && manager instanceof KeyValueStoreSessionManager) { ((KeyValueStoreSessionManager) manager).renewSessionId(oldClusterId, oldNodeId, newClusterId, getNodeId(newClusterId, request)); } } } } }
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; }
/** * is the session id known to memcached, and is it valid */ public boolean idInUse(final String idInCluster) { return getKey(idInCluster) != null; // note "null" may also mean be caused by connection problem. Anyway: Treating this as "not in use" // do not check the validity of the session since // we do not save invalidated sessions anymore. }
@Override protected void doStart() throws Exception { log.info("starting..."); super.doStart(); log.info("started."); }
@Override protected void doStop() throws Exception { log.info("stopping..."); super.doStop(); log.info("stopped."); }
protected boolean addKey(final String idInCluster, final ISerializableSession data) throws TranscoderException { byte[] raw = getSessionFactory().pack(data); if (raw == null) { return false; } else { return ((KeyValueStoreSessionIdManager) _sessionIdManager).addKey(mangleKey(idInCluster), raw, getMaxInactiveInterval()); } }
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 ISerializableSession getKey(final String idInCluster) throws TranscoderException { byte[] raw = ((KeyValueStoreSessionIdManager) _sessionIdManager).getKey(mangleKey(idInCluster)); if (raw == null) { return null; } else { return getSessionFactory().unpack(raw); } }
_idManager.stop(); _idManager.setScavengePeriod((int) TimeUnit.SECONDS.toMillis(_scavengePeriod)); _idManager.setWorkerName("node0"); _idManager.start(); _idManager = new MemcachedSessionIdManager(_server, configString, clientFactory); _idManager.setScavengePeriod((int)TimeUnit.SECONDS.toMillis(_scavengePeriod)); _idManager.setKeyPrefix("MemcachedTestServer::"); _idManager.setKeySuffix("::MemcachedTestServer"); _idManager.setDefaultExpiry(_idManager.getDefaultExpiry()); _idManager.setServerString(_idManager.getServerString()); _idManager.setTimeoutInMs(_idManager.getTimeoutInMs());
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; }