amsasSession: added addClient and removeClient to add and remove a client to/from...
authorpmarguerite <pmarguerite@issues.jalview.org>
Fri, 15 Dec 2006 15:06:25 +0000 (15:06 +0000)
committerpmarguerite <pmarguerite@issues.jalview.org>
Fri, 15 Dec 2006 15:06:25 +0000 (15:06 +0000)
Attached (as attribute) a SessionManager

Removes  the currentSession of the active session list, if the client to removed is the last one of the list

git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@320 be28352e-c001-0410-b1a7-c7978e42abec

src/uk/ac/vamsas/client/simpleclient/VamsasSession.java

index e2e170c..0fc3bd3 100644 (file)
@@ -15,6 +15,7 @@ import org.apache.log4j.Logger;
 import org.apache.log4j.FileAppender;
 
 import uk.ac.vamsas.client.ClientHandle;
+import uk.ac.vamsas.client.IClient;
 import uk.ac.vamsas.client.UserHandle;
 /**
  * Does all the IO operations for a SimpleClient instance accessing 
@@ -79,6 +80,9 @@ public class VamsasSession {
    */
   public static final String MODIFIEDDOC_FILE="modified";
 
+  
+  private SimpleSessionManager sessionManager = null;
+  
   /**
    * called to clear update flag after a successful offline storage event
    */
@@ -311,7 +315,7 @@ public class VamsasSession {
     return va;
   }
   /**
-   * create a uniquely named file in the session Directory
+   * create a uniquely named uk.ac.vamsas.client.simpleclient.ClientsFile.addClient(ClientHandle)ile in the session Directory
    * @see java.io.File.createTempFile
    * @param pref Prefix for name
    * @param suff Suffix for name
@@ -323,6 +327,62 @@ public class VamsasSession {
     SessionFile tempFile = new SessionFile(tfile);
     return tempFile;
   }
+  
+  /**
+   * add a IClient to the session
+   * 
+   * add the client to the client list file
+   * @param client client to add to the session
+   */
+  protected void addClient(IClient client)
+  {
+    if (client == null)
+      this.slog.error("Try to add a null client to the session ");
+    else
+      this.clist.addClient(client.getClientHandle(), getClientWatcher().getChangedState());
+  }
+  
+/**
+ *  
+ * removes a client from the current session
+ *  removes the client from the session client list
+ *  if the client is the last one from the session  (ClientList), the current session is removed 
+ *  from active session list.
+ *  
+ * @param client client to remove
+ */
+  protected void removeClient(IClient client)
+  {
+    if (client == null)
+      {
+        this.slog.error("Try to remove a null client.");
+        return;
+      }
+    this.clist.removeClient(client.getClientHandle(), getClientWatcher().getChangedState());
+    if (this.clist.retrieveClientList() == null|| this.clist.retrieveClientList().length<1)
+      {//assume it is the last client has been removed shutting down session
+      System.out.println("last client removed: removing session");
+       this.getSessionManager().removeSession(client.getSessionHandle());
+       
+      }
+    else
+    {
+      this.slog.debug("Still "+this.clist.retrieveClientList().length +" active clients");
+      System.out.println("Still "+(this.clist.retrieveClientList()==null?"null":this.clist.retrieveClientList().length+"") +" active clients");
+    }
+  }
+/**
+ * @return the sessionManager
+ */
+protected SimpleSessionManager getSessionManager() {
+  return sessionManager;
+}
+/**
+ * @param sessionManager the sessionManager to set
+ */
+protected void setSessionManager(SimpleSessionManager sessionManager) {
+  this.sessionManager = sessionManager;
+}
 }