001: // ========================================================================
002: // $Id: LocalStore.java,v 1.4 2004/05/09 20:30:47 gregwilkins Exp $
003: // Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
004: // ------------------------------------------------------------------------
005: // Licensed under the Apache License, Version 2.0 (the "License");
006: // you may not use this file except in compliance with the License.
007: // You may obtain a copy of the License at
008: // http://www.apache.org/licenses/LICENSE-2.0
009: // Unless required by applicable law or agreed to in writing, software
010: // distributed under the License is distributed on an "AS IS" BASIS,
011: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
012: // See the License for the specific language governing permissions and
013: // limitations under the License.
014: // ========================================================================
015:
016: package org.mortbay.j2ee.session;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import javax.servlet.http.HttpServletRequest;
022:
023: import org.jboss.logging.Logger;
024:
025: //----------------------------------------
026:
027: public class LocalStore implements Store {
028: protected static final Logger _log = Logger
029: .getLogger(LocalStore.class);
030:
031: Map _sessions = new HashMap();
032:
033: protected Manager _manager;
034:
035: public Manager getManager() {
036: return _manager;
037: }
038:
039: public void setManager(Manager manager) {
040: _manager = manager;
041: }
042:
043: // Store LifeCycle
044: public void start() {
045: }
046:
047: public void stop() {
048: }
049:
050: public void destroy() {
051: }
052:
053: // State LifeCycle
054: public State newState(String id, int maxInactiveInterval) {
055: return new LocalState(id, maxInactiveInterval,
056: _actualMaxInactiveInterval);
057: }
058:
059: public State loadState(String id) {
060: synchronized (_sessions) {
061: return (State) _sessions.get(id);
062: }
063: }
064:
065: public void storeState(State state) {
066: try {
067: synchronized (_sessions) {
068: _sessions.put(state.getId(), state);
069: }
070: } catch (Exception e) {
071: _log.warn("could not store session");
072: }
073: }
074:
075: public void removeState(State state) {
076: try {
077: synchronized (_sessions) {
078: _sessions.remove(state.getId());
079: }
080: } catch (Exception e) {
081: _log.error("could not remove session", e);
082: }
083: }
084:
085: public String allocateId(HttpServletRequest request) {
086: return getManager().getIdGenerator().nextId(request);
087: }
088:
089: public void deallocateId(String id) {
090: }
091:
092: public boolean isDistributed() {
093: return false;
094: }
095:
096: public void passivateSession(StateAdaptor sa) {
097: // we don't do that !
098: sa.invalidate();
099: }
100:
101: // there is no need to scavenge distributed state - as there is none.
102: public void setScavengerPeriod(int period) {
103: }
104:
105: public void setScavengerExtraTime(int time) {
106: }
107:
108: public void scavenge() {
109: }
110:
111: protected int _actualMaxInactiveInterval = 0;
112:
113: public void setActualMaxInactiveInterval(int interval) {
114: _actualMaxInactiveInterval = interval;
115: }
116:
117: public int getActualMaxInactiveInterval() {
118: return _actualMaxInactiveInterval;
119: }
120:
121: public Object clone() {
122: LocalStore ls = new LocalStore();
123: ls.setActualMaxInactiveInterval(_actualMaxInactiveInterval);
124: return ls;
125: }
126: }
|