From: jprocter Date: Mon, 8 Jun 2009 12:30:46 +0000 (+0000) Subject: use simpleclientsession handle rather than bare sessionhandle X-Git-Tag: Release_0.2~17 X-Git-Url: http://source.jalview.org/gitweb/?p=vamsas.git;a=commitdiff_plain;h=d2eba80523b083c994737c434a05c8b7f2e2c8d2 use simpleclientsession handle rather than bare sessionhandle git-svn-id: https://svn.lifesci.dundee.ac.uk/svn/repository/trunk@504 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 af5ab37..310c6c2 100644 --- a/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java +++ b/src/uk/ac/vamsas/client/simpleclient/VamsasSession.java @@ -22,7 +22,6 @@ package uk.ac.vamsas.client.simpleclient; import java.io.File; -import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; @@ -36,8 +35,6 @@ import org.apache.log4j.PatternLayout; import uk.ac.vamsas.client.ClientHandle; import uk.ac.vamsas.client.Events; -import uk.ac.vamsas.client.IClient; -import uk.ac.vamsas.client.SessionHandle; import uk.ac.vamsas.client.UserHandle; /** @@ -217,7 +214,7 @@ public class VamsasSession { protected VamsasSession(File sessionDir1) throws IOException { this(sessionDir1, null); } - + private SimpleSessionHandle sessionHandle = null; /** * sets up the vamsas session files and watchers in sessionDir1 * @@ -231,6 +228,7 @@ public class VamsasSession { * new data into session in this way) */ protected VamsasSession(File sessionDir1, File extVamDoc) throws IOException { + // TODO: refactor to separate extVamDoc path from session URN - enables non-local URLs to be locally bound to sessions. if (sessionDir1 == null) throw new Error("Null directory for VamsasSession."); if (!sessionDir1.exists() && !sessionDir1.mkdir()) { @@ -252,6 +250,12 @@ public class VamsasSession { } } this.sessionDir = sessionDir1; + if (extVamDoc==null) { + sessionHandle = new SimpleSessionHandle(new SessionUrn(sessionDir).getSessionUrn(),sessionDir); + } else { + // Construct Session URN from the original vamsas document. + sessionHandle = new SimpleSessionHandle(new SessionUrn(extVamDoc).getSessionUrn(),sessionDir); + } initSessionObjects(); if (existingSession) { slog.debug("Initialising additional VamsasSession instance"); @@ -650,7 +654,7 @@ public class VamsasSession { if (closeSession) { log.debug("Last active client: closing session"); log.info("Closing session"); - getSessionManager().removeSession(client.getSessionHandle()); + closeSession(client.getSessionHandle()); } } @@ -859,9 +863,15 @@ public class VamsasSession { * @param sessionHandle * sessionHandle of the session to remove */ - private void closeSession(SessionHandle sessionHandle) { - getSessionManager().removeSession(sessionHandle); - log.debug("Session removed"); + private void closeSession(uk.ac.vamsas.client.SessionHandle sessionHandle) { + //if (sessionHandle instanceof SimpleSessionHandle) + //{ + getSessionManager().removeSession(sessionHandle); + log.debug("Session removed"); + //} else { + // log.error("Cannot close a sessionHandle (URN="+sessionHandle.getSessionUrn()+") which is of type "+sessionHandle.getClass()); + // throw new Error("Tried to close a non-SimpleClient vamsas sessionHandle"); + //} } /** @@ -899,4 +909,8 @@ public class VamsasSession { } return clistWatchElement; } + + public uk.ac.vamsas.client.simpleclient.SimpleSessionHandle getSessionUrn() { + return sessionHandle; + } }