From 415ccdba81aeafe0d06c24054226c87317cb77d6 Mon Sep 17 00:00:00 2001 From: pmarguerite Date: Mon, 21 May 2007 09:56:26 +0000 Subject: [PATCH] VamsasSession: increased time before considering the current client is the last one of the session (no modification on the client list). git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@400 be28352e-c001-0410-b1a7-c7978e42abec --- .../vamsas/client/simpleclient/VamsasSession.java | 82 +++++++++++++++----- 1 file changed, 63 insertions(+), 19 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java index 5714bcd..61cf0fb 100644 --- a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java +++ b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java @@ -83,13 +83,15 @@ public class VamsasSession { /** * Count of cycles before considering the current client as the last one of the session (if no other client registered as active ) */ - private final int watchCycleCountBeforeLastClient = 2 ; + private final int watchCycleCountBeforeLastClient = 1100 ; /** * time between checking */ public int WATCH_SLEEP=30; + //protected String clientFileDirectory = "clients"; + /** * called to clear update flag after a successful offline storage event */ @@ -367,12 +369,17 @@ public class VamsasSession { log.debug("Adding client "+client.getClientHandle().getClientUrn()); getClientWatcherElement().haltWatch(); clist.addClient(client.getClientHandle()); - getClientWatcherElement().enableWatch(); + log.debug("Added."); log.debug("Register Client as Active."); - + /* try { + client.createActiveClientFile(); + } catch (IOException e) { + log.debug("Error during active client file creation."); + }*/ //tracks modification to the client list and readds client to the list getClientWatcherElement().setHandler(new AddClientWatchCallBack(client)); + getClientWatcherElement().enableWatch(); } } @@ -404,9 +411,10 @@ public class VamsasSession { boolean isWatchEnable = watcher.isWatchEnabled(); if (lock== null)//no update on the list return isWatchEnable; + // log.debug("change on the client list "); if (client != null) { - + //checks if the client is not already in the lists ClientHandle[] cl = clist.retrieveClientList(lock);//clist.retrieveClientList(); @@ -416,16 +424,19 @@ public class VamsasSession { for (int chi = cl.length-1; !found && chi > -1; chi--) { found = cl[chi].equals(this.client.getClientHandle()); } - } else + + } if (! found) - { - if( log.isDebugEnabled()) - log.debug("the client has not been found in the list. Adding it again :"+cl); - addClient(client); - } + {log.debug("client not in the list "); + if( log.isDebugEnabled()) + log.debug("the client has not been found in the list. Adding it again :"+cl); + addClient(client); + } + else + log.debug("client is in the list"); } - + //log.debug("isWatchEnable "+isWatchEnable); return isWatchEnable; } } @@ -437,6 +448,9 @@ public class VamsasSession { * if the client is the last one from the session (ClientList), the current session is removed * from active session list. * + * The active should add them self to the client list. To insure to close the session,when the current client is the lact active client, + * clears the list of clients and when two cycles to insure there is no more active client, that otherwise would have readd themself to the list + * * @param client client to remove */ protected void removeClient(SimpleClient client)//IClient client) @@ -458,8 +472,17 @@ public class VamsasSession { getClientWatcherElement().setTimeoutBeforeLastCycle(this.watchCycleCountBeforeLastClient); log.info("remove client from list"); clist.clearList(); + log.info("client list cleared"); if (cwe!=null) { cwe.enableWatch(); + + + /* try { + log.debug("Releasing active client file"); + client.releaseActiveClientFile(); + } catch (IOException e) { + log.error("error during active file client release"); + }*/ } @@ -491,7 +514,7 @@ public class VamsasSession { { private SimpleClient client ; - + private boolean manualCheckOfClientCount = false; /** *Inits the handler with the client to check in the list * @param client client to monitor in the client list @@ -509,16 +532,36 @@ public class VamsasSession { { // if lock is null, no client has been added since last, clear. //the client is then the last client - if (client != null && lock == null) + if (client != null) { + + if (lock == null ) + { //checks if the client is not already in the lists // ClientHandle[] cl = clist.retrieveClientList();//lock);//clist.retrieveClientList(); // ask to the client to cpoy application data into the document client.evgen._raise(Events.DOCUMENT_FINALIZEAPPDATA, null, client,null); - + boolean islastClient = true; + if (manualCheckOfClientCount) + { + log.debug("manual checking of count of client"); + //checks if the client is not already in the lists + ClientHandle[] cl = clist.retrieveClientList();//lock);//clist.retrieveClientList(); + if(cl == null || cl.length<1 ) + // {//no client has registered as active + { + islastClient = true; + log.debug("list is empty"); + } + else + islastClient = false; + log.debug("list is not empty"); + } // if(cl == null || cl.length<1 ) // {//no client has registered as active + if (islastClient) + { //the client is the last one, so close current session log.info("last client removed: closing session"); @@ -528,19 +571,20 @@ public class VamsasSession { getSessionManager().removeSession(client.getSessionHandle()); log.debug("Session removed"); + } } - else - { + else + { log.debug("not the last client found "); // ask to the client to cpoy application data into the document // client.evgen._raise(Events.DOCUMENT_FINALIZEAPPDATA, null, client,null); // / } - } - log.debug("Stopping EventGenerator.."); + } + log.debug("Stopping EventGenerator.."); client.evgen.stopWatching(); - + } watcher.setHandler(null);//Do not check if the client is the last client. watcher will shutdown anyway // watcher.haltWatch(); // watcher. -- 1.7.10.2