public static final String VAMSAS_OBJ = "VamDoc.jar";
/**
- * sets up the vamsas session files and watchers in sessionDir
+ * 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)
+ */
+ 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
if (!sessionDir1.mkdir())
throw new IOException("Failed to make VamsasSession directory in "
+ sessionDir1);
- createSessionFiles();
+ createSessionFiles(extVamDoc);
initSessionObjects();
slog.debug("Session directory created.");
log.debug("Initialised VamsasSession in " + sessionDir1);
*
*/
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 {
if (sessionDir == null)
throw new IOException(
"Invalid call to createSessionFiles() with null sessionDir");
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() && v_doc.createNewFile())
- log.debug("Created new Vamsas Session Document File " + v_doc);
+ 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);
+ }
+ }
}
/**
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
- newdoc.updateFrom(extlock, vamArchive);
+ 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).
vamArchive.unLock();
newdoc.unlockFile();