From 8879baa96b917d81b39fee0c2e2cc9e5021865bc Mon Sep 17 00:00:00 2001 From: jprocter Date: Tue, 27 Feb 2007 22:19:12 +0000 Subject: [PATCH] ensured single instance of vamsasarchive io handler to prevent lock contention. git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@346 be28352e-c001-0410-b1a7-c7978e42abec --- .../ac/vamsas/client/simpleclient/SimpleClient.java | 17 +++++++++-------- .../ac/vamsas/client/simpleclient/VamsasSession.java | 13 +++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java index ad74209..677094c 100644 --- a/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java +++ b/src/uk/ac/vamsas/client/simpleclient/SimpleClient.java @@ -321,20 +321,13 @@ public class SimpleClient implements IClient { _session.slog.warn("Session Document updated but may not be valid (false return from org.vamsas.simpleclient.ClientDocument.updateSessionDocument()"); } log.debug("Document update successful."); + _session.setUnsavedFlag(); } catch (IOException e) { log.warn("IO Problems when updating document!",e); _session.slog.error("IO problems when attempting to update document."); } } - try { - _session.setUnsavedFlag(); - _session.unlockVamsasDocument(); - evgen.enableDocumentWatch(); - } catch (IOException e) { - log.warn("IO Problems when releasing lock on session document!",e); - _session.slog.error("IO problems when attempting to release lock on session document."); - } // garbage collect the ClientDocument instance. try { log.debug("Finalizing ClientDocument instance."); @@ -343,6 +336,14 @@ public class SimpleClient implements IClient { log.error("Exception when trying to garbage collect ClientDocument for "+session.getSessionUrn(), e); } cdocument = null; // this is probably done by finalize + + try { + _session.unlockVamsasDocument(); + evgen.enableDocumentWatch(); + } catch (IOException e) { + log.warn("IO Problems when releasing lock on session document!",e); + _session.slog.error("IO problems when attempting to release lock on session document."); + } } /* diff --git a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java index c849893..05014ab 100644 --- a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java +++ b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java @@ -294,7 +294,10 @@ public class VamsasSession { newdoc.unlockFile(); log.debug("Transfer complete."); } - + /** + * extant archive IO handler + */ + 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. @@ -302,7 +305,9 @@ public class VamsasSession { * @throws IOException if locks fail or vamsas document read fails. */ protected VamsasArchive getVamsasDocument() throws IOException { - // TODO: 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()) long tries=5000; while (vamArchive.getLock()==null && --tries>0) { @@ -321,8 +326,12 @@ public class VamsasSession { * @throws IOException */ protected void unlockVamsasDocument() throws IOException { + if (_va!=null) + _va.closeArchive(); + _va=null; if (vamArchive!=null) vamArchive.unLock(); + } /** * create a uniquely named uk.ac.vamsas.client.simpleclient.ClientsFile.addClient(ClientHandle)ile in the session Directory -- 1.7.10.2