KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > ftp > FTPSessionList


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.ftp;
18
19 import java.util.*;
20
21 /**
22  * FTP Server Session List Class
23  *
24  * @author GKSpencer
25  */

26 public class FTPSessionList
27 {
28
29     // Session list
30

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

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

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

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

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

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

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

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

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

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

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

129     public final Enumeration enumerate()
130     {
131         return m_sessions.keys();
132     }
133 }
134
Popular Tags