2 * @author Robert Koenighofer, member of the ISAC-team,
3 * Copyright (c) 2006 by Robert Koenighofer
4 * created Jul 11, 2006 10:09:13 AM
5 * Institute for Softwaretechnology, Graz University of Technology, Austria.
7 * Use is subject to PGPL license terms.
12 import isac.users.User;
13 import isac.users.UserLogger;
14 import isac.users.UserManager;
16 import java.io.Serializable;
17 import java.rmi.RemoteException;
18 import java.rmi.server.UnicastRemoteObject;
19 import java.util.HashMap;
21 import org.apache.log4j.Logger;
24 * This class administrates all sessions. It is implemented as Singleton (design
25 * Pattern of Gamma et.al.), which means, that there can be only one instance of
26 * this class. This instance can be accessed by the getInstance() method. The
27 * class allows to generate new Sessions and to deliver session objects with a
28 * specific session id. The session id is always unique.
30 * @author Robert Koenighofer
32 public class SessionManager extends UnicastRemoteObject implements
33 ISessionManager, Serializable {
35 static final long serialVersionUID = 284066283;// FIXXME generate with
39 private static final Logger logger = Logger.getLogger(SessionManager.class
44 private static SessionManager instance_ = null;
46 private HashMap<String, Session> sessionid_map_session_;
48 private HashMap<String, String> sessionid_map_username_;
50 public ICompod compod_;
53 * The constructor is private, since this class is implemented as singleton.
54 * Use the getInstance() method to get the one and only instance of this
57 * @throws RemoteException
58 * if remote object is not available
60 private SessionManager() throws RemoteException {
61 sessionid_map_session_ = new HashMap<String, Session>();
62 sessionid_map_username_ = new HashMap<String, String>();
64 compod_ = new CompodDummy();
66 compod_.setLMSID("isac");
67 } catch (Exception e) {
73 * This method creates a new session for the user with the name 'user_name'.
74 * It returns the created session. One user can have more than one session
78 * the name of the user of the new session
79 * @return the created session
80 * @throws RemoteException
81 * if remote object is not available
83 public Session addSession(User user) throws RemoteException {
84 String new_id = String.valueOf(next_id_++);
85 Session new_session = new Session(new_id, user, compod_);
86 sessionid_map_session_.put(new_id, new_session);
87 sessionid_map_username_.put(new_id, user.getUsername());
88 if (logger.isDebugEnabled())
89 logger.debug(" SM: new Session with ID: " + new_id + " created");
94 * This method removes the session with the specified id from the maps. It
95 * is called, whenever a logout is done (by closing the WindowApplication).
98 * the id of the session to remove
99 * @throws RemoteException
100 * if remote object is not available any more
102 public void removeSession(String session_id) throws RemoteException {
103 // WN0710 the similar UI_CLOSE_WORKSHEET is done in the gui;
104 // analogously this could be done on closing the WindowApplication:
105 UserLogger user_logger = getSessionByID(session_id).getUserLogger();
106 user_logger.logStopSession();
108 sessionid_map_session_.remove(session_id);
109 sessionid_map_username_.remove(session_id);
113 * returns the session with the desired session_id. If the session does not
114 * exist, null is returned.
117 * the unique id of the desired session
118 * @return the desired session or null if it doesn't exist
119 * @throws RemoteException
120 * if remote object is not available
122 public Session getSessionByID(String session_id) throws RemoteException {
123 return sessionid_map_session_.get(session_id);
127 * returns the name of the user, which owns a specific session, as String.
128 * If the session does not exist, null is returned.
131 * the unique id of the desired session
132 * @return the desired user name or null if the session does not exist
133 * @throws RemoteException
134 * if remote object is not available
136 public String getUserNameByID(String session_id) throws RemoteException {
137 return sessionid_map_username_.get(session_id);
140 public HashMap getSessionMap() {
141 return sessionid_map_session_;
145 * returns the instance of the singleton SessionManager. Since the
146 * constructor is private, this is the only method to get a SessionManager.
147 * It always returns one and the same instance of this class.
149 * @return the one and only instance of this class.
150 * @throws RemoteException
151 * if remote object is not available
153 public static SessionManager getInstance() throws RemoteException {
154 if (instance_ == null) {
156 instance_ = new SessionManager();
157 } catch (RemoteException e) {