fileLock.release();
fileLock = null;
if (sessionFile != null) {
- if (sessionFile.exists()) {
- // TODO: see if we need to loop-wait for locks or they just block until
- // lock is made...
- do {
- if (fileLock!=null)
- fileLock.release();
- fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
- } while (!fileLock.isLocked());
- // fileLock = new Lock(sessionFile);
- return fileLock.isLocked();
+ if (!sessionFile.exists()) {
+ // create new file
+ try {
+ if (!sessionFile.createNewFile()) {
+ log.error("Failed to create file prior to locking: "+sessionFile);
+ return false;
+ }
+ } catch (IOException e) {
+ log.error("Exception when trying to create file "+sessionFile, e);
+ return false;
+ }
}
+ // TODO: see if we need to loop-wait for locks or they just block until
+ // lock is made...
+ do {
+ if (fileLock!=null)
+ fileLock.release();
+ fileLock = new Lock(sessionFile); // TODO: wait around if we can't get the lock.
+ } while (!fileLock.isLocked());
+ // fileLock = new Lock(sessionFile);
+ return fileLock.isLocked();
} else
log.error("lockFile called for non-initialised SessionFile!");