KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mortbay > j2ee > session > LocalStore


1 // ========================================================================
2
// $Id: LocalStore.java,v 1.4 2004/05/09 20:30:47 gregwilkins Exp $
3
// Copyright 2002-2004 Mort Bay Consulting Pty. Ltd.
4
// ------------------------------------------------------------------------
5
// Licensed under the Apache License, Version 2.0 (the "License");
6
// you may not use this file except in compliance with the License.
7
// You may obtain a copy of the License at
8
// http://www.apache.org/licenses/LICENSE-2.0
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
// ========================================================================
15

16 package org.mortbay.j2ee.session;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22
23 import org.jfox.ioc.logger.Logger;
24
25 //----------------------------------------
26

27 public class LocalStore
28   implements Store
29 {
30   protected static final Logger _log=Logger.getLogger(LocalStore.class);
31   Map JavaDoc _sessions=new HashMap JavaDoc();
32
33   protected Manager _manager;
34   public Manager getManager(){return _manager;}
35   public void setManager(Manager manager){_manager=manager;}
36
37   // Store LifeCycle
38
public void start() {}
39   public void stop() {}
40   public void destroy() {}
41
42   // State LifeCycle
43
public State
44     newState(String JavaDoc id, int maxInactiveInterval)
45   {
46     return new LocalState(id, maxInactiveInterval, _actualMaxInactiveInterval);
47   }
48
49   public State
50     loadState(String JavaDoc id)
51   {
52     synchronized (_sessions) {return (State)_sessions.get(id);}
53   }
54
55   public void
56     storeState(State state)
57   {
58     try
59     {
60       synchronized (_sessions) {_sessions.put(state.getId(), state);}
61     }
62     catch (Exception JavaDoc e)
63     {
64       _log.warn("could not store session");
65     }
66   }
67
68   public void
69     removeState(State state)
70   {
71     try
72     {
73       synchronized (_sessions) {_sessions.remove(state.getId());}
74     }
75     catch (Exception JavaDoc e)
76     {
77       _log.error("could not remove session", e);
78     }
79   }
80
81   public String JavaDoc
82     allocateId(HttpServletRequest JavaDoc request)
83   {
84     return getManager().getIdGenerator().nextId(request);
85   }
86
87   public void
88     deallocateId(String JavaDoc id)
89   {
90   }
91
92   public boolean
93     isDistributed()
94   {
95     return false;
96   }
97
98
99   public void
100     passivateSession(StateAdaptor sa)
101   {
102     // we don't do that !
103
sa.invalidate();
104   }
105
106   // there is no need to scavenge distributed state - as there is none.
107
public void setScavengerPeriod(int period) {}
108   public void setScavengerExtraTime(int time) {}
109   public void scavenge() {}
110
111   protected int _actualMaxInactiveInterval=0;
112   public void setActualMaxInactiveInterval(int interval) {_actualMaxInactiveInterval=interval;}
113   public int getActualMaxInactiveInterval() {return _actualMaxInactiveInterval;}
114
115   public Object JavaDoc
116     clone()
117   {
118     LocalStore ls=new LocalStore();
119     ls.setActualMaxInactiveInterval(_actualMaxInactiveInterval);
120     return ls;
121   }
122 }
123
Popular Tags