KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > server > SrvSessionList


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.filesys.server;
18
19 import java.util.Enumeration JavaDoc;
20 import java.util.Hashtable JavaDoc;
21
22 /**
23  * Server Session List Class
24  */

25 public class SrvSessionList
26 {
27
28     // Session list
29

30     private Hashtable JavaDoc<Integer JavaDoc, SrvSession> m_sessions;
31
32     /**
33      * Class constructor
34      */

35     public SrvSessionList()
36     {
37         m_sessions = new Hashtable JavaDoc<Integer JavaDoc, SrvSession>();
38     }
39
40     /**
41      * Return the number of sessions in the list
42      *
43      * @return int
44      */

45     public final int numberOfSessions()
46     {
47         return m_sessions.size();
48     }
49
50     /**
51      * Add a session to the list
52      *
53      * @param sess SrvSession
54      */

55     public final void addSession(SrvSession sess)
56     {
57         m_sessions.put(sess.getSessionId(), sess);
58     }
59
60     /**
61      * Find the session using the unique session id
62      *
63      * @param id int
64      * @return SrvSession
65      */

66     public final SrvSession findSession(int id)
67     {
68         return findSession(id);
69     }
70
71     /**
72      * Find the session using the unique session id
73      *
74      * @param id Integer
75      * @return SrvSession
76      */

77     public final SrvSession findSession(Integer JavaDoc id)
78     {
79         return m_sessions.get(id);
80     }
81
82     /**
83      * Remove a session from the list
84      *
85      * @param id int
86      * @return SrvSession
87      */

88     public final SrvSession removeSession(int id)
89     {
90         return removeSession(new Integer JavaDoc(id));
91     }
92
93     /**
94      * Remove a session from the list
95      *
96      * @param sess SrvSession
97      * @return SrvSession
98      */

99     public final SrvSession removeSession(SrvSession sess)
100     {
101         return removeSession(sess.getSessionId());
102     }
103
104     /**
105      * Remove a session from the list
106      *
107      * @param id Integer
108      * @return SrvSession
109      */

110     public final SrvSession removeSession(Integer JavaDoc id)
111     {
112
113         // Find the required session
114

115         SrvSession sess = findSession(id);
116
117         // Remove the session and return the removed session
118

119         m_sessions.remove(id);
120         return sess;
121     }
122
123     /**
124      * Enumerate the session ids
125      *
126      * @return Enumeration<Integer>
127      */

128     public final Enumeration JavaDoc<Integer JavaDoc> enumerate()
129     {
130         return m_sessions.keys();
131     }
132 }
133
Popular Tags