/* * Copyright 2006 www.webtair.com * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webtair.session.config; /** * Config Bean – implements basic configuration information * needed for properly working SessionMan. * * @author Vyacheslav Yakovenko (Vaclav) */ public class ConfigBean { /** Minimally admissible time of a session life */ protected static final int MIN_SESSION_LIFETIME = 60000; /** Minimally admissible cleanup interval */ protected static final int MIN_CLEANUP_INTERVAL = MIN_SESSION_LIFETIME + 60000; /** Prospective quantity of sessions */ protected static final int DEFAULT_USER_COUNT = 256; /** Default session life in ms = 30min * 60s * 1000ms */ protected static final long DEFAULT_SESSION_LIFETIME = 30 * 60 * 1000; /** Default session cleanus interval 10min */ protected static final long DEFAULT_CLEANUP_INTERVAL = 10 * 60 * 1000; /** Current value of user count */ private int userCount; /** Current session's life time in ms */ private long sessionLifeTime; /** Current interval beween cleanup activity in ms */ private long cleanupInterval; /** * Default constructor init all fields of bean * with values defined in constants */ public ConfigBean(){ this(DEFAULT_USER_COUNT, DEFAULT_SESSION_LIFETIME, DEFAULT_CLEANUP_INTERVAL); } /** * Constructor that specifies only session life time and cleanup * interval. * @param sessionLifeTime - session life time in ms; * @param cleanupInterval - cleanup interval in ms; */ public ConfigBean(long sessionLifeTime, long cleanupInterval){ this(DEFAULT_USER_COUNT, sessionLifeTime, cleanupInterval); } /** * Constructor that specifies all fields of the bean * @param userCount - predicted value of users for HashMap init * @param sessionLifeTime - session life time in ms; * @param cleanupInterval - cleanup interval in ms; */ public ConfigBean(int userCount, long sessionLifeTime, long cleanupInterval){ this.setUserCount(userCount); this.setSessionLifeTime(sessionLifeTime); this.setCleanupInterval(cleanupInterval); } /** * Return current cleanup interval in ms; * @return the cleanupInterval; */ public long getCleanupInterval() { return cleanupInterval; } /** * Set current cleanup interval in ms; * @param cleanupInterval the cleanup interval in ms; */ public void setCleanupInterval(long cleanupInterval) { if (cleanupInterval < MIN_CLEANUP_INTERVAL){ this.cleanupInterval = MIN_CLEANUP_INTERVAL; }else{ this.cleanupInterval = cleanupInterval; } } /** * Return current session lifetime in ms * @return the sessionLifeTime in ms */ public long getSessionLifeTime() { return sessionLifeTime; } /** * Set session lifetime in ms; * @param sessionLifeTime the session lifetime in ms; */ public void setSessionLifeTime(long sessionLifeTime) { if (sessionLifeTime < MIN_SESSION_LIFETIME){ this.sessionLifeTime = MIN_SESSION_LIFETIME; }else{ this.sessionLifeTime = sessionLifeTime; } } /** * Return current user count (initial size of HashMap) * @return userCount - initial user count */ public int getUserCount() { return userCount; } /** * Set current user count (initial size of HashMap) * @param userCount the userCount to set */ public void setUserCount(int userCount) { if (userCount < DEFAULT_USER_COUNT){ userCount = DEFAULT_USER_COUNT; }else{ this.userCount = userCount; } } }