safety checks and informational Errors generated when IClientDocument is not stored...
[vamsas.git] / src / uk / ac / vamsas / client / simpleclient / VamsasSession.java
index b24ef68..2ae181d 100644 (file)
@@ -486,52 +486,38 @@ public class VamsasSession {
       client.evgen.stopWatching();
       cwe.setHandler(null);
       
-//    ask to the client to copy application data into the document
+      // ask to the client to copy application data into the document
       client.evgen._raise(Events.DOCUMENT_FINALIZEAPPDATA, null, client,null);
-      
-      if ( this.isLastActiveClient(client))
-        {
+      boolean closeSession=isLastActiveClient(client);
+      if (closeSession)
+      {
         log.debug("Raising request-to-save event");
         client.evgen._raise(Events.DOCUMENT_REQUESTTOCLOSE, null, client, null);
-        //client.evgen._raise(Events.SESSION_SHUTDOWN, null, client.getSessionHandle(), null);
-        log.debug("Last active client: closing session");
-        log.info("Closing session");
-          getSessionManager().removeSession(client.getSessionHandle());
-        }
-      
+        client.evgen._raise(Events.SESSION_SHUTDOWN, null, client.getSessionHandle(), null);
+      }
       try 
         {
-          log.debug("Releasing  active client file");
+          log.debug("Attempting to release active client locks");
           client.releaseActiveClientFile();
         }
       catch (IOException e)
         {
           log.error("error during active file client release");
          }
-    }
-   
-  
-   
-    /*clist.removeClient(client.getClientHandle(),null);
-    if (this.clist.retrieveClientList() == null|| this.clist.retrieveClientList().length<1)
-      {//assume it is the last client has been removed shutting down session
-        slog.info("last client removed: removing session");
-        log.debug("last client removed: removing session");
-        this.getSessionManager().removeSession(client.getSessionHandle());
-      }
-    else
+      if (closeSession)
       {
-        int active=clist.retrieveClientList().length;
-        log.debug("Still "+active+" active clients");
-        slog.info("Still "+active+" active clients");
-      }*/
-   
+        log.debug("Last active client: closing session");
+        log.info("Closing session");
+          getSessionManager().removeSession(client.getSessionHandle());
+      }
+    }
   }
   
   
   private boolean isLastActiveClient(SimpleClient client)
     {
     log.debug("Testing if current client is the last one.");
+    log.debug("current client lockfile is '"+client.getClientlockFile()+"'");
       boolean noOtherActiveClient = true;
       //create, if need,  subdirectory to contain client files
       File clientlockFileDir = new File (this.sessionDir, clientFileDirectory);
@@ -554,7 +540,7 @@ public class VamsasSession {
           {
              File clientFile = clientFiles[i];
              log.debug("testing file for lock: "+clientFile.getAbsolutePath());
-             if(client.getClientlockFile().equals(clientFile)) 
+             if(client.getClientLock().isTargetLockFile(clientFile)) 
                {
                log.debug("current client file found");
                  continue;
@@ -693,6 +679,7 @@ public class VamsasSession {
          
             }
               log.debug("Stopping EventGenerator..");
+              // TODO: ensure ClientsFile lock is really released!! clist.unlockFile();
           client.evgen.stopWatching();
         }
           watcher.setHandler(null);//Do not check if the client is the last client. watcher will shutdown anyway
@@ -712,7 +699,7 @@ public class VamsasSession {
 //   close document 
       client.evgen._raise(Events.DOCUMENT_REQUESTTOCLOSE, null, client,null);
       log.debug("close document request done");
-      this.closeSession(client.getSessionHandle());
+      closeSession(client.getSessionHandle());
     }
   
   /**