2 * This file is part of the Vamsas Client version 0.1.
\r
3 * Copyright 2009 by Jim Procter, Iain Milne, Pierre Marguerite,
\r
4 * Andrew Waterhouse and Dominik Lindner.
\r
6 * Earlier versions have also been incorporated into Jalview version 2.4
\r
7 * since 2008, and TOPALi version 2 since 2007.
\r
9 * The Vamsas Client is free software: you can redistribute it and/or modify
\r
10 * it under the terms of the GNU Lesser General Public License as published by
\r
11 * the Free Software Foundation, either version 3 of the License, or
\r
12 * (at your option) any later version.
\r
14 * The Vamsas Client is distributed in the hope that it will be useful,
\r
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
17 * GNU Lesser General Public License for more details.
\r
19 * You should have received a copy of the GNU Lesser General Public License
\r
20 * along with the Vamsas Client. If not, see <http://www.gnu.org/licenses/>.
\r
22 package uk.ac.vamsas.client.simpleclient;
\r
24 import java.io.File;
\r
25 import java.io.IOException;
\r
27 import uk.ac.vamsas.client.SessionHandle;
\r
30 * Class to deal with sessions
\r
32 * retrieves list of available sessions
\r
34 * adds an active session
\r
36 * removes a close session (the last client has been closed)
\r
40 public class SimpleSessionManager {
\r
41 private SessionsFile sessionFile = null;
\r
43 protected SimpleSessionManager(File sessionsFile) throws IOException {
\r
44 this.initManagerObjects(sessionsFile);
\r
48 * construct SessionFile objects and watchers for each
\r
50 private void initManagerObjects(File sessionsFile) throws IOException {
\r
51 if (this.sessionFile != null)
\r
52 throw new IOException(
\r
53 "initFactoryObjects called for initialised ClientFactory object.");
\r
54 this.sessionFile = new SessionsFile(sessionsFile);
\r
58 * make a new watcher object for the sessionsFile
\r
60 * @return new SessionsFile watcher instance
\r
62 public FileWatcher getSessionsWatcher() {
\r
63 return new FileWatcher(this.getSessionFile().sessionFile);
\r
67 * @see uk.ac.vamsas.client.IClientFactory#getCurrentSessions()
\r
69 public String[] getCurrentSessions() {
\r
70 String[] sessions = null;
\r
71 if (this.sessionFile != null) {
\r
72 SessionHandle[] sessionHandles = this.sessionFile.retrieveSessionsList();
\r
73 if (sessionHandles != null) {
\r
74 sessions = new String[sessionHandles.length];
\r
75 for (int i = sessionHandles.length - 1; i > -1; i--) {
\r
76 SessionHandle sessionHandle = sessionHandles[i];
\r
77 sessions[i] = sessionHandle.getSessionUrn();
\r
85 * adds SessionHandle me to the sessionList
\r
88 * session to add to the session list
\r
89 * @return session index in list or 0 if lock was invalid or addSession
\r
92 public int addSession(SessionHandle newSession) {
\r
93 return this.sessionFile.addSession(newSession, false, this
\r
94 .getSessionsWatcher().getChangedState());
\r
98 * @return the sessionFile
\r
100 private SessionsFile getSessionFile() {
\r
101 return this.sessionFile;
\r
105 * Removes a session from the list of currently active session
\r
108 * SessionHandle of the session to remove
\r
110 protected void removeSession(SessionHandle session) {
\r
111 this.getSessionFile().removeSession(session,
\r
112 this.getSessionsWatcher().getChangedState());
\r