From: jprocter Date: Fri, 14 Sep 2007 13:48:50 +0000 (+0000) Subject: implement low level functions for initialising a new vamsas session with a copy of... X-Git-Tag: Release_0.2~54 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=f107db87425f86dd4fed8846d0ac09dc31d1ac46;p=vamsas.git implement low level functions for initialising a new vamsas session with a copy of an existing session document. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@466 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java index 477cec5..a000f46 100644 --- a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java +++ b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java @@ -20,78 +20,66 @@ import uk.ac.vamsas.client.SessionHandle; import uk.ac.vamsas.client.UserHandle; /** - * Does all the IO operations for a SimpleClient instance accessing - * a SimpleClient vamsas session. + * Does all the IO operations for a SimpleClient instance accessing a + * SimpleClient vamsas session. * - * Basically, it defines the various standard names for the files - * in the session directory (that maps to the sessionUrn), - * provides constructors for the file handlers and watchers of - * those file entities, and some higher level methods + * Basically, it defines the various standard names for the files in the session + * directory (that maps to the sessionUrn), provides constructors for the file + * handlers and watchers of those file entities, and some higher level methods * to check and change the state flags for the session. * - * TODO: move the stuff below to the SimpleClientFactory documentation. - * much may not be valid now : - * Vamsas client is intialised with a path to create live session directories. - * This path may contain a vamsas.properties file - * that sets additional parameters (otherwise client - * just uses the one on the classpath). + * TODO: move the stuff below to the SimpleClientFactory documentation. much may + * not be valid now : Vamsas client is intialised with a path to create live + * session directories. This path may contain a vamsas.properties file that sets + * additional parameters (otherwise client just uses the one on the classpath). * - * A vamsas session consists of : - * SessionDir - translates to urn of a live session. - * Contains: Vamsas Document (as a jar), Session client list file, - * both of which may be locked, and additional - * temporary versions of these files when write - * operations are taking place. + * A vamsas session consists of : SessionDir - translates to urn of a live + * session. Contains: Vamsas Document (as a jar), Session client list file, both + * of which may be locked, and additional temporary versions of these files when + * write operations are taking place. * - * Zip file entries - * - vamsasdocument.xml : core info - * one or more: - * - .version.sessionnumber.raw (string given in vamsasdocument.xml applicationData entry) - * - * Lockfile - * - filename given in the vamsasdocument.xml. Should be checked for validity by any client and rewritten if necessary. - * The lockfile can point to the jar itself. - * Mode of operation. - * Initially - documentHandler either: - * - creates a zip for a new session for the client - * - connect to an existing session zip - * 1. reads session urn file - * 2. waits for lock - * 3. examines session - decide whether to create new application data slice or connect to one stored in session. - * 4. writes info into session file - * 5. releases lock and generates local client events. - * 6. Creates Watcher thread to generate events. + * Zip file entries - vamsasdocument.xml : core info one or more: - + * .version.sessionnumber.raw (string given in + * vamsasdocument.xml applicationData entry) * - * During the session - * - Update watcher checks for file change - + * Lockfile - filename given in the vamsasdocument.xml. Should be checked for + * validity by any client and rewritten if necessary. The lockfile can point to + * the jar itself. Mode of operation. Initially - documentHandler either: - + * creates a zip for a new session for the client - connect to an existing + * session zip 1. reads session urn file 2. waits for lock 3. examines session - + * decide whether to create new application data slice or connect to one stored + * in session. 4. writes info into session file 5. releases lock and generates + * local client events. 6. Creates Watcher thread to generate events. + * + * During the session - Update watcher checks for file change - + * + * Procedures for file based session message exchange - session document + * modification flag * - * Procedures for file based session message exchange - * - session document modification flag - * */ public class VamsasSession { /** - * indicator file for informing other processes that - * they should finalise their vamsas datasets for - * storing into a vamsas archive. + * indicator file for informing other processes that they should finalise + * their vamsas datasets for storing into a vamsas archive. */ public static final String CLOSEANDSAVE_FILE = "stored.log"; /** - * session file storing the last_stored_stat data + * session file storing the last_stored_stat data */ public static final String MODIFIEDDOC_FILE = "modified"; private SimpleSessionManager sessionManager = null; /** - * Count of cycles before considering the current client as the last one of the session (if no other client registered as active ) + * 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 = 1220; /** - * time between checking + * time between checking */ public int WATCH_SLEEP = 30; @@ -109,7 +97,7 @@ public class VamsasSession { /** * called to indicate session document has been modified. - * + * */ protected void setUnsavedFlag() { SessionFlagFile laststored = new SessionFlagFile(new File(sessionDir, @@ -120,7 +108,8 @@ public class VamsasSession { /** * - * @return true if session document has been modified since last offline storage event + * @return true if session document has been modified since last offline + * storage event */ protected boolean getUnsavedFlag() { SessionFlagFile laststored = new SessionFlagFile(new File(sessionDir, @@ -136,24 +125,30 @@ public class VamsasSession { private static Log log = LogFactory.getLog(VamsasSession.class); protected Logger slog = Logger.getLogger("uk.ac.vamsas.client.SessionLog"); + /** * the appender that writes to the log file inside the session's directory. */ - private FileAppender slogAppender=null; + private FileAppender slogAppender = null; + /** * setup the sessionLog using Log4j. + * * @throws IOException */ private void initLog() throws IOException { // TODO: fix session event logging // LATER: make dedicated appender format for session log. - /*Appender app = slog.getAppender("log4j.appender.SESSIONLOG"); - // slog.addAppender(new FileAppender(app.getLayout(), new File(sessionDir, SESSION_LOG).getAbsolutePath())); - // slog.addAppender(new FileAppender(app.getLayout(), new File(sessionDir, SESSION_LOG).getAbsolutePath())); - for (Enumeration e = slog.getAllAppenders() ; e.hasMoreElements() ;) { - System.out.println(e.nextElement()); - - }*/ + /* + * Appender app = slog.getAppender("log4j.appender.SESSIONLOG"); // + * slog.addAppender(new FileAppender(app.getLayout(), new File(sessionDir, + * SESSION_LOG).getAbsolutePath())); // slog.addAppender(new + * FileAppender(app.getLayout(), new File(sessionDir, + * SESSION_LOG).getAbsolutePath())); for (Enumeration e = + * slog.getAllAppenders() ; e.hasMoreElements() ;) { + * System.out.println(e.nextElement()); + * } + */ if (slog != null) { File sessionLogFile = new File(this.sessionDir, SESSION_LOG); @@ -164,11 +159,10 @@ public class VamsasSession { log.info("No appender for SessionLog"); } } + private void closeSessionLog() { - if (slog!=null) - { - if (slogAppender!=null) - { + if (slog != null) { + if (slogAppender != null) { slog.removeAppender(slogAppender); slogAppender.close(); slogAppender = null; @@ -197,50 +191,69 @@ public class VamsasSession { /** * sets up the vamsas session files and watchers in sessionDir1 + * * @param sessionDir1 */ protected VamsasSession(File sessionDir1) throws IOException { this(sessionDir1, null); } + /** * sets up the vamsas session files and watchers in sessionDir1 - * @param sessionDir1 - * @param extVamDoc null or an existing archive to initialise the session with - * @throws any IOExceptions from creating session directory and files. - * @throws error if both extVamDoc and sessionDir1 already exist (cannot import new data into session in this way) + * + * @param sessionDir1 + * @param extVamDoc + * null or an existing archive to initialise the session with + * @throws any + * IOExceptions from creating session directory and files. + * @throws error + * if both extVamDoc and sessionDir1 already exist (cannot import + * new data into session in this way) */ protected VamsasSession(File sessionDir1, File extVamDoc) throws IOException { if (sessionDir1 == null) throw new Error("Null directory for VamsasSession."); - if (sessionDir1.exists()) { - if (extVamDoc!=null && extVamDoc.exists()) - throw new Error("Client Initialisation Error: Cannot join an existing session directory with an existing vamsas document to import."); - if (!sessionDir1.isDirectory() || !sessionDir1.canWrite() - || !sessionDir1.canRead()) - throw new IOException("Cannot access '" + sessionDir1 - + "' as a read/writable Directory."); - if (!checkSessionFiles(sessionDir1)) + if (!sessionDir1.exists() && !sessionDir1.mkdir()) { + throw new IOException("Failed to make VamsasSession directory in " + + sessionDir1); + } + if (!sessionDir1.isDirectory() || !sessionDir1.canWrite() + || !sessionDir1.canRead()) { + throw new IOException("Cannot access '" + sessionDir1 + + "' as a read/writable Directory."); + } + boolean existingSession=checkSessionFiles(sessionDir1); + if (existingSession) + { + if (extVamDoc!=null) { + throw new Error( + "Client Initialisation Error: Cannot join an existing session directory with an existing vamsas document to import."); + } else { log - .warn("checkSessionFiles() returned false. Possible client implementation error"); - this.sessionDir = sessionDir1; - initSessionObjects(); - slog.debug("Initialising additional VamsasSession instance"); - log.debug("Attached to VamsasSession in " + sessionDir1); - //} - } else { - // start from scratch - if (!sessionDir1.mkdir()) - throw new IOException("Failed to make VamsasSession directory in " - + sessionDir1); - createSessionFiles(extVamDoc); - initSessionObjects(); - slog.debug("Session directory created."); - log.debug("Initialised VamsasSession in " + sessionDir1); + .debug("Joining an existing session."); + } + } + this.sessionDir = sessionDir1; + initSessionObjects(); + if (existingSession) + { slog.debug("Initialising additional VamsasSession instance"); + } else + { + slog.debug("Founding client has joined VamsasSession instance"); } + + log.debug("Attached to VamsasSession in " + sessionDir1); + if (extVamDoc!=null) + { + setVamsasDocument(extVamDoc); + } + slog.debug("Session directory created."); + log.debug("Initialised VamsasSession in " + sessionDir1); } /** * tests presence of existing sessionfiles files in dir + * * @param dir * @return */ @@ -254,50 +267,24 @@ public class VamsasSession { /** * create new empty files in dir - * - */ - private void createSessionFiles() throws IOException { - createSessionFiles(null); - } - /** * - * @param extVamDoc null or an existing vamsas document to initialise session with - * @throws IOException */ - private void createSessionFiles(File extVamDoc) throws IOException { + private void createSessionFiles() throws IOException { if (sessionDir == null) throw new IOException( "Invalid call to createSessionFiles() with null sessionDir"); File c_file = new File(sessionDir, CLIENT_LIST); File v_doc = new File(sessionDir, VAMSAS_OBJ); if (!c_file.exists() && c_file.createNewFile()) - log.debug("Created new ClientFile " + c_file); // don't care if this works or not - if (!v_doc.exists()) - { - if (extVamDoc==null) - { - if (v_doc.createNewFile()) - { - log.debug("Created new Vamsas Session Document File " + v_doc); - } else { - log.warn("Didn't create Vamsas Session Document file in "+v_doc); - } - } else { - log.debug("Creating new session document from "+extVamDoc); - try { - SessionFile sesdoc = new SessionFile(new File(sessionDir, VAMSAS_OBJ)); - SessionFile extdoc = new SessionFile(extVamDoc); - sesdoc.updateFrom(null, extdoc); - } catch (Exception e) - { - v_doc.delete(); - v_doc.createNewFile(); - log.warn("Problem initialising new session ("+v_doc+") from existing vamsas document ("+extVamDoc+")",e); - throw new IOException("Couldn't initialise session from existing vamsas document"); - } - log.debug("Session document initialised from "+extVamDoc); - } + log.debug("Created new ClientFile " + c_file); // don't care if this + // works or not + if (!v_doc.exists()) { + if (v_doc.createNewFile()) { + log.debug("Created new Vamsas Session Document File " + v_doc); + } else { + log.warn("Didn't create Vamsas Session Document file in " + v_doc); } + } } /** @@ -316,6 +303,7 @@ public class VamsasSession { /** * make a new watcher object for the clientFile + * * @return new ClientFile watcher instance */ public FileWatcher getClientWatcher() { @@ -324,6 +312,7 @@ public class VamsasSession { /** * make a new watcher object for the vamsas Document + * * @return new ClientFile watcher instance */ public FileWatcher getDocWatcher() { @@ -336,6 +325,7 @@ public class VamsasSession { /** * make a new watcher object for the messages file + * * @return new watcher instance */ public FileWatcher getStoreWatcher() { @@ -344,8 +334,10 @@ public class VamsasSession { } /** - * write to the StoreWatcher file to indicate that a storeDocumentRequest has been made. - * The local client's storeWatcher FileWatcher object is updated so the initial change is not registered. + * write to the StoreWatcher file to indicate that a storeDocumentRequest has + * been made. The local client's storeWatcher FileWatcher object is updated so + * the initial change is not registered. + * * @param client * @param user * @return @@ -358,7 +350,8 @@ public class VamsasSession { log.debug("Trying to get lock for " + CLOSEANDSAVE_FILE); RandomAccessFile sfwfile = sfw.fileLock.getRaFile(); sfwfile.setLength(0); // wipe out any old info. - // TODO: rationalise what gets written to this file (ie do we want other clients to read the id of the requestor?) + // TODO: rationalise what gets written to this file (ie do we want other + // clients to read the id of the requestor?) sfwfile.writeUTF(client.getClientUrn() + ":" + user.getFullName() + "@" + user.getOrganization()); sfw.unlockFile(); @@ -369,23 +362,29 @@ public class VamsasSession { } /** - * create a new session with an existing vamsas Document - by copying it into the session. + * create a new session with an existing vamsas Document - by copying it into + * the session. + * * @param archive */ public void setVamsasDocument(File archive) throws IOException { log.debug("Transferring vamsas data from " + archive + " to session:" + vamArchive.sessionFile); SessionFile xtantdoc = new SessionFile(archive); + while (!vamArchive.lockFile()) + log.info("Trying to get lock for " + vamArchive.sessionFile); vamArchive.updateFrom(null, xtantdoc); - // LATER: decide if session archive provenance should be updated to reflect access. - // TODO: soon! do a proper import objects from external file + xtantdoc.unlockFile(); + unlockVamsasDocument(); + // TODO: session archive provenance should be updated to reflect import from external source log.debug("Transfer complete."); } /** - * write session as a new vamsas Document (this will overwrite any existing file without warning) - * TODO: test - * TODO: verify that lock should be released for vamsas document. + * write session as a new vamsas Document (this will overwrite any existing + * file without warning) TODO: test TODO: verify that lock should be released + * for vamsas document. + * * @param destarchive */ protected void writeVamsasDocument(File destarchive, Lock extlock) @@ -396,9 +395,11 @@ public class VamsasSession { if (extlock == null && !vamArchive.lockFile()) while (!vamArchive.lockFile()) log.info("Trying to get lock for " + vamArchive.sessionFile); - // TODO: LATER: decide if a provenance entry should be written in the exported document recording the export from the session + // TODO: LATER: decide if a provenance entry should be written in the + // exported document recording the export from the session newdoc.updateFrom(null, vamArchive); - // LATER: LATER: fix use of updateFrom for file systems where locks cannot be made (because they don't have a lockManager, ie NFS/Unix, etc). + // LATER: LATER: fix use of updateFrom for file systems where locks cannot + // be made (because they don't have a lockManager, ie NFS/Unix, etc). vamArchive.unLock(); newdoc.unlockFile(); log.debug("Transfer complete."); @@ -410,19 +411,23 @@ public class VamsasSession { VamsasArchive _va = null; /** - * Creates a VamsasArchive Vobject for accessing and updating document - * Note: this will lock the Vamsas Document for exclusive access to the client. + * Creates a VamsasArchive Vobject for accessing and updating document Note: + * this will lock the Vamsas Document for exclusive access to the client. + * * @return session vamsas document - * @throws IOException if locks fail or vamsas document read fails. + * @throws IOException + * if locks fail or vamsas document read fails. */ protected VamsasArchive getVamsasDocument() throws IOException { - // check we haven't already done this once - probably should be done by caller + // check we haven't already done this once - probably should be done by + // caller if (_va != null) return _va; - // patiently wait for a lock on the document. (from ArchiveClient.getUpdateable()) + // patiently wait for a lock on the document. (from + // ArchiveClient.getUpdateable()) long tries = 5000; while (vamArchive.getLock() == null && --tries > 0) { - // Thread.sleep(1); + // Thread.sleep(1); log.debug("Trying to get a document lock for the " + tries + "'th time."); } if (tries == 0) @@ -436,6 +441,7 @@ public class VamsasSession { /** * Unlocks the vamsas archive session document after it has been closed. + * * @throws IOException */ protected void unlockVamsasDocument() throws IOException { @@ -448,10 +454,15 @@ public class VamsasSession { } /** - * create a uniquely named uk.ac.vamsas.client.simpleclient.ClientsFile.addClient(ClientHandle)ile 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 + * @param pref + * Prefix for name + * @param suff + * Suffix for name * @return SessionFile object configured for the new file (of length zero) * @throws IOException */ @@ -466,7 +477,9 @@ public class VamsasSession { * add a IClient to the session * * add the client to the client list file - * @param client client to add to the session + * + * @param client + * client to add to the session */ protected void addClient(SimpleClient client) { if (client == null) @@ -483,7 +496,7 @@ public class VamsasSession { } catch (IOException e) { log.debug("Error during active client file creation."); } - //tracks modification to the client list and readds client to the list + // tracks modification to the client list and readds client to the list getClientWatcherElement().setHandler(new AddClientWatchCallBack(client)); getClientWatcherElement().enableWatch(); @@ -500,26 +513,31 @@ public class VamsasSession { private SimpleClient client; /** - *Inits the handler with the client to check in the list - * @param client client to monitor in the client list + * Inits the handler with the client to check in the list + * + * @param client + * client to monitor in the client list */ protected AddClientWatchCallBack(SimpleClient client) { this.client = client; } /** - * If the client list is modified, checks if the current is still in the list. otherwise, readds ti. - * @return true to enable watcher, or false to disable it in future WatcherThread cycles. + * If the client list is modified, checks if the current is still in the + * list. otherwise, readds ti. + * + * @return true to enable watcher, or false to disable it in future + * WatcherThread cycles. */ public boolean handleWatchEvent(WatcherElement watcher, Lock lock) { boolean isWatchEnable = watcher.isWatchEnabled(); - if (lock == null)//no update on the list + 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(); + // checks if the client is not already in the lists + ClientHandle[] cl = clist.retrieveClientList(lock);// clist.retrieveClientList(); boolean found = false; if (cl != null) { for (int chi = cl.length - 1; !found && chi > -1; chi--) { @@ -544,43 +562,46 @@ public class VamsasSession { } /** - * - * 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. - * - * 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 + * + * 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. + * + * 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) + protected void removeClient(SimpleClient client)// IClient client) { if (client == null) { log.error("Null client passed to removeClient"); return; } - //ClientSessionFileWatcherElement cwe=getClientWatcherElement(); - //if (cwe!=null && cwe.isWatchEnabled()) { - // cwe.haltWatch(); - //}; - //set handler to check is the the last active client of the session - //Wait for several watchers cycle to see if the current client was the last client active in the session. - //if yes, close the session - - // getClientWatcherElement().setHandler(new RemoveClientWatchCallBack (client)); + // ClientSessionFileWatcherElement cwe=getClientWatcherElement(); + // if (cwe!=null && cwe.isWatchEnabled()) { + // cwe.haltWatch(); + // }; + // set handler to check is the the last active client of the session + // Wait for several watchers cycle to see if the current client was the last + // client active in the session. + // if yes, close the session + + // getClientWatcherElement().setHandler(new RemoveClientWatchCallBack + // (client)); // getClientWatcherElement().setTimeoutBeforeLastCycle(this.watchCycleCountBeforeLastClient); log.info("remove client from list"); - if (clistWatchElement!=null) - { + if (clistWatchElement != null) { clistWatchElement.haltWatch(); clistWatchElement.watched.unlockFile(); } - //clist.clearList(); - //clist.unlockFile(); + // clist.clearList(); + // clist.unlockFile(); log.info("list cleared"); - //if (cwe!=null) { + // if (cwe!=null) { // cwe.enableWatch(); log.debug("Stopping EventGenerator.."); @@ -595,7 +616,7 @@ public class VamsasSession { client.evgen._raise(Events.SESSION_SHUTDOWN, null, client .getSessionHandle(), null); } - //cwe.haltWatch(); + // cwe.haltWatch(); client.evgen.stopWatching(); try { log.debug("Attempting to release active client locks"); @@ -629,7 +650,7 @@ public class VamsasSession { .debug("current client lockfile is '" + client.getClientlockFile() + "'"); boolean noOtherActiveClient = true; - //create, if need, subdirectory to contain client files + // create, if need, subdirectory to contain client files File clientlockFileDir = new File(this.sessionDir, clientFileDirectory); if (!clientlockFileDir.exists()) { log @@ -639,9 +660,13 @@ public class VamsasSession { try { - //no check every file in the directory and try to get lock on it. + // no check every file in the directory and try to get lock on it. File[] clientFiles = clientlockFileDir.listFiles(); - if (clientFiles == null || clientFiles.length == 0) {//there is not file on the directory. the current client should be the last one. + if (clientFiles == null || clientFiles.length == 0) {// there is not file + // on the directory. + // the current + // client should be + // the last one. return true; } @@ -661,7 +686,7 @@ public class VamsasSession { // Use the file channel to create a lock on the file. // This method blocks until it can retrieve the lock. - // java.nio.channels.FileLock activeClientFilelock = channel.lock(); + // java.nio.channels.FileLock activeClientFilelock = channel.lock(); // Try acquiring the lock without blocking. This method returns // null or throws an exception if the file is already locked. @@ -669,8 +694,9 @@ public class VamsasSession { java.nio.channels.FileLock activeClientFilelock = channel .tryLock(); - //the lock has been acquired. - //the file was not lock and so the corresponding application seems to have die + // the lock has been acquired. + // the file was not lock and so the corresponding application + // seems to have die if (activeClientFilelock != null) { log .debug("lock obtained : file must be from a crashed application"); @@ -681,7 +707,7 @@ public class VamsasSession { channel.close(); log.debug("channel closed"); - //delete file + // delete file clientFile.delete(); log.debug("crashed application file deleted"); @@ -691,7 +717,7 @@ public class VamsasSession { } } catch (OverlappingFileLockException e) { // File is already locked in this thread or virtual machine - //that the expected behaviour + // that the expected behaviour log.debug("lock not accessible ", e); } } catch (Exception e) { @@ -720,34 +746,40 @@ public class VamsasSession { private boolean manualCheckOfClientCount = false; /** - *Inits the handler with the client to check in the list - * @param client client to monitor in the client list + * Inits the handler with the client to check in the list + * + * @param client + * client to monitor in the client list */ protected RemoveClientWatchCallBack(SimpleClient client) { this.client = client; } /** - * If the client list is modified, checks if the current is still in the list. otherwise, readds ti. - * @return true to enable watcher, or false to disable it in future WatcherThread cycles. + * If the client list is modified, checks if the current is still in the + * list. otherwise, readds ti. + * + * @return true to enable watcher, or false to disable it in future + * WatcherThread cycles. */ public boolean handleWatchEvent(WatcherElement watcher, Lock lock) { // if lock is null, no client has been added since last, clear. - //the client is then the last client + // the client is then the last client if (client != null) { if (lock == null) { - //checks if the client is not already in the lists - // ClientHandle[] cl = clist.retrieveClientList();//lock);//clist.retrieveClientList(); + // checks if the client is not already in the lists + // ClientHandle[] cl = + // clist.retrieveClientList();//lock);//clist.retrieveClientList(); 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(); + // 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 + // {//no client has registered as active { islastClient = true; log.debug("list is empty"); @@ -755,39 +787,44 @@ public class VamsasSession { islastClient = false; log.debug("list is not empty"); } - // if(cl == null || cl.length<1 ) - // {//no client has registered as active + // if(cl == null || cl.length<1 ) + // {//no client has registered as active if (islastClient) { - //the client is the last one, so close current session + // the client is the last one, so close current session log.info("last client removed: closing session"); closeSession(client); } } 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); + // ask to the client to cpoy application data into the document + // client.evgen._raise(Events.DOCUMENT_FINALIZEAPPDATA, null, + // client,null); - // / } + // / } } log.debug("Stopping EventGenerator.."); - // TODO: ensure ClientsFile lock is really released!! clist.unlockFile(); + // 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 - // watcher.haltWatch(); + watcher.setHandler(null);// Do not check if the client is the last + // client. watcher will shutdown anyway + // watcher.haltWatch(); // watcher. return false; } } /** - * closes the current session, - * and send an event to the last client to close the document - * @param client the last client of the client + * closes the current session, and send an event to the last client to close + * the document + * + * @param client + * the last client of the client */ private void closeSession(SimpleClient client) { - // close document + // close document client.evgen._raise(Events.DOCUMENT_REQUESTTOCLOSE, null, client, null); log.debug("close document request done"); closeSession(client.getSessionHandle()); @@ -795,7 +832,9 @@ public class VamsasSession { /** * CLoses the current session - * @param sessionHandle sessionHandle of the session to remove + * + * @param sessionHandle + * sessionHandle of the session to remove */ private void closeSession(SessionHandle sessionHandle) { getSessionManager().removeSession(sessionHandle); @@ -810,7 +849,8 @@ public class VamsasSession { } /** - * @param sessionManager the sessionManager to set + * @param sessionManager + * the sessionManager to set */ protected void setSessionManager(SimpleSessionManager sessionManager) { this.sessionManager = sessionManager; @@ -827,6 +867,7 @@ public class VamsasSession { /** * get or create a watcher on clist. + * * @return the contents of clistWatchElement or initialise it */ public ClientSessionFileWatcherElement getClientWatcherElement() { @@ -835,20 +876,4 @@ public class VamsasSession { } return clistWatchElement; } - /** - * writes a vector of vorba Ids to the session. - * @param modObjects - public void setModObjectList(Vector modObjects) { - log.debug("Writing "+modObjects.size()+" ids to ModObjectList"); - // TODO Auto-generated method stub - } - ** - * get current list of modified objects. - * @return null or Vector of objects - * - public Vector getModObjectList() { - log.debug("Reading modObjectList"); - return null; - } - */ }