+ /**
+ * Get a lock for the SessionFile
+ *
+ * @return true if lock was made
+ */
+ protected boolean lockFile() {
+ if (fileLock != null) {
+ if (fileLock.isLocked()) {
+ if (!ensureSessionFile())
+ return false;
+ return true;
+ } else {
+ // lock failed for some reason.
+ fileLock.release();
+ log.info("Unexpected session file lock failure. Trying to get it again.");
+ fileLock=null;
+ }
+ }
+ if (!ensureSessionFile())
+ return false;
+ // TODO: see if we need to loop-wait for locks or they just block until
+ // lock is made...
+ long tries=5000;
+ do {
+ tries--;
+ if (fileLock==null || !fileLock.isLocked()) {
+ //try { Thread.sleep(1); } catch (Exception e) {};
+ fileLock = LockFactory.getLock(sessionFile,true); // TODO: wait around if we can't get the lock.
+ }
+ } while (tries>0 && !fileLock.isLocked());
+ if (!fileLock.isLocked())
+ log.error("Failed to get lock for "+sessionFile);
+ // fileLock = new Lock(sessionFile);
+ return fileLock.isLocked();
+ }