- private java.nio.channels.FileLock activeClientFilelock = null;
-
- private FileChannel activeClientFileChannel = null;
+ private Lock activeClientFilelock = null;
private File clientlockFile = null;
/**
log.debug("Releasing active client file");
if( activeClientFilelock != null)
- // Release the lock
+ {// Release the lock
activeClientFilelock.release();
-
- if (activeClientFileChannel != null)
- // Close the file
- activeClientFileChannel.close();
+ 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");
}
}
}
}
this.clientlockFile = new File (clientlockFileDir, this.getClientHandle().getClientUrn().replaceAll("[:;/\\\\]+",""));
-
- log.debug("Creating active client lock file "+ this.clientlockFile.getAbsolutePath());
- if (clientlockFile.exists())
- {//should not happen, file should be deleted when the application closes or when a crashed application has been detected
- log.error("client lock file already exits");
- }
- try {
- //create the empty file
- if(! clientlockFile.createNewFile())
- {
- log.error("Unable to create active client lock file");
-
- return;
- }
- else
- log.debug("file created");
- // Get a file channel for the file
- FileChannel channel = new RandomAccessFile(clientlockFile, "rw").getChannel();
-
- // Use the file channel to create a lock on the file.
- // This method blocks until it can retrieve the lock.
- java.nio.channels.FileLock activeClientFilelock ;// = channel.lock();
-
- // Try acquiring the lock without blocking. This method returns
- // null or throws an exception if the file is already locked.
- try
- {
- activeClientFilelock = channel.tryLock();
- log.debug("Got lock");
- }
- catch (OverlappingFileLockException e)
- {
- // File is already locked in this thread or virtual machine
- log.error("Oups the file is already locked",e);
-
- }
-
- // Release the lock
- /* lock.release();
-
- // Close the file
- channel.close();*/
- } catch (Exception e) {
- log.error("Error during lock file creation",e);
- }
-
-
+ 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
*/