sessionmanager.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,493 行 · 第 1/3 页
JAVA
1,493 行
/** * True if the session should be invalidated after the listener. */ public void setInvalidateAfterListener(boolean inv) { _isInvalidateAfterListener = inv; } /** * True if the session should be invalidated after the listener. */ public boolean isInvalidateAfterListener() { return _isInvalidateAfterListener; } /** * Returns the current number of active sessions. */ public int getActiveSessionCount() { if (_sessions == null) return -1; else return _sessions.size(); } /** * Returns the active sessions. */ public int getSessionActiveCount() { return getActiveSessionCount(); } /** * Returns the created sessions. */ public long getSessionCreateCount() { return _sessionCreateCount; } /** * Returns the timeout sessions. */ public long getSessionTimeoutCount() { return _sessionTimeoutCount; } /** * Returns the invalidate sessions. */ public long getSessionInvalidateCount() { return _sessionInvalidateCount; } /** * Adds a new HttpSessionListener. */ public void addListener(HttpSessionListener listener) { if (_listeners == null) _listeners = new ArrayList<HttpSessionListener>(); _listeners.add(listener); } /** * Adds a new HttpSessionListener. */ ArrayList<HttpSessionListener> getListeners() { return _listeners; } /** * Adds a new HttpSessionActivationListener. */ public void addActivationListener(HttpSessionActivationListener listener) { if (_activationListeners == null) _activationListeners = new ArrayList<HttpSessionActivationListener>(); _activationListeners.add(listener); } /** * Returns the activation listeners. */ ArrayList<HttpSessionActivationListener> getActivationListeners() { return _activationListeners; } /** * Adds a new HttpSessionAttributeListener. */ public void addAttributeListener(HttpSessionAttributeListener listener) { if (_attributeListeners == null) _attributeListeners = new ArrayList<HttpSessionAttributeListener>(); _attributeListeners.add(listener); } /** * Gets the HttpSessionAttributeListener. */ ArrayList<HttpSessionAttributeListener> getAttributeListeners() { return _attributeListeners; } /** * True if serialization errors should just fail silently. */ boolean getIgnoreSerializationErrors() { return _ignoreSerializationErrors; } /** * True if serialization errors should just fail silently. */ public void setIgnoreSerializationErrors(boolean ignore) { _ignoreSerializationErrors = ignore; } /** * True if the server should reuse the current session id if the * session doesn't exist. */ public int getReuseSessionId() { return _reuseSessionId; } /** * True if the server should reuse the current session id if the * session doesn't exist. */ public boolean reuseSessionId(boolean fromCookie) { int reuseSessionId = _reuseSessionId; return reuseSessionId == TRUE || fromCookie && reuseSessionId == COOKIE; } /** * True if the server should reuse the current session id if the * session doesn't exist. */ public void setReuseSessionId(String reuse) throws ConfigException { if (reuse == null) _reuseSessionId = COOKIE; else if (reuse.equalsIgnoreCase("true") || reuse.equalsIgnoreCase("yes") || reuse.equalsIgnoreCase("cookie")) _reuseSessionId = COOKIE; else if (reuse.equalsIgnoreCase("false") || reuse.equalsIgnoreCase("no")) _reuseSessionId = FALSE; else if (reuse.equalsIgnoreCase("all")) _reuseSessionId = TRUE; else throw new ConfigException(L.l("'{0}' is an invalid value for reuse-session-id. 'true' or 'false' are the allowed values.", reuse)); } /** * Returns true if the sessions are closed. */ public boolean isClosed() { return _isClosed; } /** * Sets the file store. */ public StoreManager createFileStore() throws ConfigException { if (_cluster.getStore() != null) throw new ConfigException(L.l("<file-store> may not be used with a defined <persistent-store>. Use <use-persistent-store> instead.")); StoreManager fileStore = _cluster.createPrivateFileStore(); _storeManager = fileStore; _isWebAppStore = true; return fileStore; } /** * Sets the cluster store. */ public void setUsePersistentStore(boolean enable) throws Exception { if (! enable) return; StoreManager store = _cluster.getStore(); if (store != null) { } else if (! Resin.getCurrent().isProfessional()) { throw new ConfigException(L.l("use-persistent-store in <session-config> requires Resin professional.")); } else throw new ConfigException(L.l("use-persistent-store in <session-config> requires a configured <persistent-store> in the <server>")); if (_isWebAppStore) throw new ConfigException(L.l("use-persistent-store may not be used with <jdbc-store> or <file-store>.")); _storeManager = store; } public String getDistributionId() { return _distributionId; } public void setDistributionId(String distributionId) { _distributionId = distributionId; } /** * Returns the default session timeout in milliseconds. */ public long getSessionTimeout() { return _sessionTimeout; } /** * Set the default session timeout in minutes */ public void setSessionTimeout(long timeout) { if (timeout <= 0 || Integer.MAX_VALUE / 2 < timeout) _sessionTimeout = Long.MAX_VALUE / 2; else _sessionTimeout = 60000L * timeout; } /** * Returns the idle time. */ public long getMaxIdleTime() { return _sessionTimeout; } /** * Returns the maximum number of sessions. */ public int getSessionMax() { return _sessionMax; } /** * Returns the maximum number of sessions. */ public void setSessionMax(int max) { if (max < 1) throw new ConfigException(L.l("session-max '{0}' is too small. session-max must be a positive number", max)); _sessionMax = max; } /** * Returns true if sessions use the cookie header. */ public boolean enableSessionCookies() { return _enableSessionCookies; } /** * Returns true if sessions use the cookie header. */ public void setEnableCookies(boolean enableCookies) { _enableSessionCookies = enableCookies; } /** * Returns true if sessions can use the session rewriting. */ public boolean enableSessionUrls() { return _enableSessionUrls; } /** * Returns true if sessions can use the session rewriting. */ public void setEnableUrlRewriting(boolean enableUrls) { _enableSessionUrls = enableUrls; } /** * Returns the default cookie name. */ public String getCookieName() { return _cookieName; } /** * Returns the SSL cookie name. */ public String getSSLCookieName() { if (_sslCookieName != null) return _sslCookieName; else return _cookieName; } /** * Returns the default session cookie domain. */ public String getCookieDomain() { return _cookieDomain; } /** * Sets the default session cookie domain. */ public void setCookieDomain(String domain) { _cookieDomain = domain; } /** * Returns the max-age of the session cookie. */ public long getCookieMaxAge() { return _cookieMaxAge; } /** * Sets the max-age of the session cookie. */ public void setCookieMaxAge(Period maxAge) { _cookieMaxAge = maxAge.getPeriod(); } /** * Returns the secure of the session cookie. */ public boolean getCookieSecure() { if (_cookieSecure) return true; else return ! _cookieName.equals(_sslCookieName); } /** * Sets the secure of the session cookie. */ public void setCookieSecure(boolean secure) { _cookieSecure = secure; } /** * Returns the http-only of the session cookie. */ public boolean isCookieHttpOnly() { if (_isCookieHttpOnly == SET_TRUE) return true; else if (_isCookieHttpOnly == SET_FALSE) return true; else return getWebApp().getCookieHttpOnly(); } /** * Sets the http-only of the session cookie. */ public void setCookieHttpOnly(boolean httpOnly) { _isCookieHttpOnly = httpOnly ? SET_TRUE : SET_FALSE; } /** * Sets the cookie length */ public void setCookieLength(int cookieLength) { if (cookieLength < 7) cookieLength = 7; _cookieLength = cookieLength; } /** * Returns the cookie length. */ public long getCookieLength() { return _cookieLength; } /** * Sets module session id generation. */ public void setCookieModuloCluster(boolean isModulo) { _isModuloSessionId = isModulo; } /** * Sets module session id generation. */ public void setCookieAppendServerIndex(boolean isAppend) { _isAppendServerIndex = isAppend; } /** * Sets module session id generation. */ public boolean isCookieAppendServerIndex() { return _isAppendServerIndex; } public void init() { if (_sessionSaveMode == SAVE_ON_SHUTDOWN && (_alwaysSaveSession == SET_TRUE || _alwaysLoadSession == SET_TRUE)) throw new ConfigException(L.l("save-mode='on-shutdown' cannot be used with <always-save-session/> or <always-load-session/>")); _sessions = new LruCache<String,SessionImpl>(_sessionMax); _sessionIter = _sessions.values(); if (_isWebAppStore) { // for backward compatibility if (_alwaysLoadSession == SET_TRUE) _storeManager.setAlwaysLoad(true); else if (_alwaysLoadSession == SET_FALSE) _storeManager.setAlwaysLoad(false); if (_alwaysSaveSession == SET_TRUE) _storeManager.setAlwaysSave(true); else if (_alwaysSaveSession == SET_FALSE) _storeManager.setAlwaysSave(false); _storeManager.init(); _storeManager.updateIdleCheckInterval(_sessionTimeout); } if (_storeManager != null) { _sessionStore = _storeManager.createStore(_distributionId, _objectManager); _sessionStore.setMaxIdleTime(_sessionTimeout); if (_alwaysLoadSession == SET_TRUE) _sessionStore.setAlwaysLoad(true); else if (_alwaysLoadSession == SET_FALSE) _sessionStore.setAlwaysLoad(false); if (_alwaysSaveSession == SET_TRUE) _sessionStore.setAlwaysSave(true); else if (_alwaysSaveSession == SET_FALSE) _sessionStore.setAlwaysSave(false); } _objectManager.setStore(_sessionStore); } public void start() throws Exception { _alarm.queue(60000);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?