import java.beans.PropertyChangeSupport;
import java.io.File;
import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.nio.channels.FileChannel;
+
+import java.nio.channels.OverlappingFileLockException;
import java.util.Hashtable;
import java.util.Vector;
protected ClientHandle client = null;
protected EventGeneratorThread evgen = null;
protected ClientDocument cdocument = null;
+
+
+
+
+ private Lock activeClientFilelock = null;
+ private File clientlockFile = null;
+
/**
* object hash table that persists in each client holding vorbaIds and hash values after a document write
*/
// more complex if data is already present in document. Could have a 'clearSession' method, too, or dump and overwrite instead.
log.error("importDocument is not yet implemented for a SimpleClient Session.");
- /* try {
+ /*try {
this._session.setVamsasDocument(location);
} catch (IOException e) {
log.error("importDocument failed.");
pickmanager = new SimplePickManager(new uk.ac.vamsas.client.picking.SocketManager());
}
}
+
+
+ protected void releaseActiveClientFile() throws IOException
+ {
+
+ log.debug("Releasing active client file");
+ if( activeClientFilelock != null)
+ {// Release the lock
+ activeClientFilelock.release();
+ activeClientFilelock = null;
+ } else {
+ log.debug("ReleaseActiveClientFile called when client has no lock on its clientLockFile");
+ }
+ if (this.clientlockFile != null)
+ {
+ if (this.clientlockFile.exists())
+ this.clientlockFile.delete();
+ log.debug("deleted active client lock file");
+ } else {
+ log.debug("ReleaseActiveClientFile called when client has no clientLockFile");
+ }
+
+ }
+
+ protected void createActiveClientFile() throws IOException
+ {
+ if(this.clientlockFile != null )return;
+ log.debug("createActiveClientFile");
+ //create, if need, subdirectory to contain client files
+ File clientlockFileDir = new File ( this.get_session().sessionDir, this.get_session().clientFileDirectory);
+ if( !clientlockFileDir.exists())
+ {//the directory does not exist, create it
+ if (! clientlockFileDir.mkdirs())
+ {
+ throw new IOException("Failed to create sub directory to session directory for client lock files'"+clientlockFileDir.getAbsolutePath()+"'");
+ }
+ }
+ else
+ {
+ if (!(clientlockFileDir.isDirectory() && clientlockFileDir.canWrite()))
+ {
+ throw new IOException("Directory for client lock files is not a directory or is not accessibl: '"+clientlockFileDir.getAbsolutePath()+"'");
+ }
+ }
+ this.clientlockFile = new File (clientlockFileDir, this.getClientHandle().getClientUrn().replaceAll("[:;/\\\\]+",""));
+
+ log.debug("Creating active client lock file "+ this.clientlockFile.getAbsolutePath());
+ Lock clientLock = uk.ac.vamsas.client.simpleclient.LockFactory.getLock(clientlockFile, false);
+ if (clientLock==null || !clientLock.isLocked())
+ {
+ log.fatal("IMPLEMENTATION ERROR: Couldn't get a lock for the client lock file "+clientlockFile);
+ }
+ activeClientFilelock = clientLock;
+ }
+ /**
+ * @return the clientlockFile
+ */
+ protected File getClientlockFile() {
+ return clientlockFile;
+ }
}