From: jprocter Date: Thu, 16 Mar 2006 18:02:21 +0000 (+0000) Subject: changed semaphore implementation and session modified flag. X-Git-Tag: Release_0.2~335 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=83a284f644324c5c597474e8cfc1cab808a31a3a;p=vamsas.git changed semaphore implementation and session modified flag. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@185 be28352e-c001-0410-b1a7-c7978e42abec --- diff --git a/src/org/vamsas/client/simpleclient/SimpleClient.java b/src/org/vamsas/client/simpleclient/SimpleClient.java index daf3ca5..0445e2a 100644 --- a/src/org/vamsas/client/simpleclient/SimpleClient.java +++ b/src/org/vamsas/client/simpleclient/SimpleClient.java @@ -254,7 +254,7 @@ public class SimpleClient implements IClient { // Events.DOCUMENT_FINALIZEAPPDATA try { _session.writeVamsasDocument(location, vamlock); - _session.updateLastStoredStat(); + _session.clearUnsavedFlag(); } catch (Exception e) { log.warn("Exception whilst trying to store document in "+location,e); } @@ -322,7 +322,7 @@ public class SimpleClient implements IClient { throw new Exception("Failed to start event generator thread - client cannot be instantiated."); } if (evgen.countHandlersFor(Events.DOCUMENT_CREATE)>0) { - //TODO: check vamsas document for presence of an AppData entry for this application + //TODO: is this application connecting to a newly created session document ? //evgen.raise(Events.DOCUMENT_CREATE); } } diff --git a/src/org/vamsas/client/simpleclient/VamsasSession.java b/src/org/vamsas/client/simpleclient/VamsasSession.java index 7971f57..4e6f430 100644 --- a/src/org/vamsas/client/simpleclient/VamsasSession.java +++ b/src/org/vamsas/client/simpleclient/VamsasSession.java @@ -15,9 +15,17 @@ import org.apache.log4j.FileAppender; import org.vamsas.client.ClientHandle; import org.vamsas.client.UserHandle; /** - * Holds the file handlers and watchers for a session. + * Does all the IO operations for a SimpleClient instance accessing + * a SimpleClient vamsas session. * - * TODO: delete the stuff below - prolly irrelevant now + * 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 @@ -52,6 +60,9 @@ import org.vamsas.client.UserHandle; * During the session * - Update watcher checks for file change - * + * Procedures for file based session message exchange + * - session document modification flag + * */ public class VamsasSession { @@ -62,11 +73,34 @@ public class VamsasSession { */ public static final String CLOSEANDSAVE_FILE="stored.log"; /** - * state of vamsas document when it was last stored outside the session directory + * session file storing the last_stored_stat data */ - protected long last_stored_stat[]=null; - protected void updateLastStoredStat() { - + public static final String MODIFIEDDOC_FILE="modified"; + + /** + * called to clear update flag after a successful offline storage event + */ + protected void clearUnsavedFlag() { + SessionFlagFile laststored = new SessionFlagFile(new File(sessionDir, MODIFIEDDOC_FILE)); + if (!laststored.clearFlag()) + log.warn("Unsaved flag was not cleared for "+sessionDir); + } + /** + * called to indicate session document has been modified. + * + */ + protected void setUnsavedFlag() { + SessionFlagFile laststored = new SessionFlagFile(new File(sessionDir, MODIFIEDDOC_FILE)); + if (!laststored.setFlag()) + log.warn("Couldn't set the Unsaved flag for "+sessionDir); + } + /** + * + * @return true if session document has been modified since last offline storage event + */ + protected boolean getUnsavedFlag() { + SessionFlagFile laststored = new SessionFlagFile(new File(sessionDir, MODIFIEDDOC_FILE)); + return laststored.checkFlag(); } /** * log file location @@ -79,7 +113,7 @@ public class VamsasSession { * @throws IOException */ private void initLog() throws IOException { - // TODO: LATER: make dedicated appender format for session log. + // LATER: make dedicated appender format for session log. Appender app = slog.getAppender("SESSION_LOG"); slog.addAppender(new FileAppender(app.getLayout(), new File(sessionDir, SESSION_LOG).getAbsolutePath())); } @@ -170,20 +204,27 @@ public class VamsasSession { public FileWatcher getClientWatcher() { return new FileWatcher(clist.sessionFile); } + FileWatcher session_doc_watcher=null; /** * make a new watcher object for the vamsas Document * @return new ClientFile watcher instance */ public FileWatcher getDocWatcher() { + if (session_doc_watcher==null) + return session_doc_watcher = new FileWatcher(vamArchive.sessionFile); return new FileWatcher(vamArchive.sessionFile); } FileWatcher store_doc_file=null; /** * make a new watcher object for the messages file + * (thread safe - keeps a reference to the first watcher) * @return new watcher instance */ public FileWatcher getStoreWatcher() { - return store_doc_file = new FileWatcher(new File(CLOSEANDSAVE_FILE)); + if (store_doc_file==null) + return store_doc_file = new FileWatcher(new File(CLOSEANDSAVE_FILE)); + return new FileWatcher(new File(CLOSEANDSAVE_FILE)); + } /** * write to the StoreWatcher file to indicate that a storeDocumentRequest has been made. @@ -230,7 +271,7 @@ public class VamsasSession { log.info("Trying to get lock for "+vamArchive.sessionFile); // TODO: LATER: decide if session archive provenance should be written in vamsasDocument file for this export. newdoc.updateFrom(extlock, vamArchive); - // TODO: SOON: 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.");