8 package uk.ac.vamsas.client.simpleclient;
11 import java.io.IOException;
13 import uk.ac.vamsas.client.SessionHandle;
16 * Class to deal with sessions
18 * retrieves list of available sessions
20 * adds an active session
22 * removes a close session (the last client has been closed)
26 public class SimpleSessionManager
28 private SessionsFile sessionFile = null;
31 protected SimpleSessionManager(File sessionsFile) throws IOException
33 this.initManagerObjects(sessionsFile);
37 * construct SessionFile objects and watchers for each
39 private void initManagerObjects(File sessionsFile) throws IOException
41 if (this.sessionFile!=null )
42 throw new IOException("initFactoryObjects called for initialised ClientFactory object.");
43 this.sessionFile = new SessionsFile(sessionsFile);
48 * make a new watcher object for the sessionsFile
49 * @return new SessionsFile watcher instance
51 public FileWatcher getSessionsWatcher() {
52 return new FileWatcher(this.getSessionFile().sessionFile);
56 * @see uk.ac.vamsas.client.IClientFactory#getCurrentSessions()
58 public String[] getCurrentSessions()
60 String[] sessions = null;
61 if (this.sessionFile!=null )
63 SessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList();
64 if (sessionHandles != null)
66 sessions = new String[sessionHandles.length];
67 for (int i = sessionHandles.length -1; i > -1; i--)
69 SessionHandle sessionHandle = sessionHandles[i];
70 sessions [i] = sessionHandle.getSessionUrn();
78 * adds SessionHandle me to the sessionList
79 * @param newSession session to add to the session list
80 * @return session index in list or 0 if lock was invalid or addSession operation failed.
82 public int addSession(SessionHandle newSession)
84 return this.sessionFile.addSession(newSession, false,this.getSessionsWatcher().getChangedState());
88 * @return the sessionFile
90 private SessionsFile getSessionFile()
92 return this.sessionFile;
96 * Removes a session from the list of currently active session
98 * @param session SessionHandle of the session to remove
100 protected void removeSession(SessionHandle session)
102 this.getSessionFile().removeSession(session,this.getSessionsWatcher().getChangedState());