edu.harvard.mgh.purcell.gCLINE.data
Class Lock

java.lang.Object
  extended by edu.harvard.mgh.purcell.gCLINE.data.Lock

public class Lock
extends java.lang.Object

Deal with the locking and unlocking of a folder.

Author:
Kathe

Field Summary
private  Record data
           
private  ErrorManager error
          This allows us to pass errors
private  StartFrame frame
           
private  java.lang.String key
          The key of this particular instance of the lock.
private  java.io.File lockFile
          The lock file.
private  org.apache.log4j.Logger logger
          A logger for this clas
private  java.lang.String remoteFile
          The directory that the remote lock file is in
static java.lang.String UNLOCKED_KEY
           
 
Constructor Summary
Lock(StartFrame givenFrame, Record d)
          Create a lock from a string representing the local file and set the new key.
 
Method Summary
 boolean availableLock()
           
private  java.lang.String getKey()
          Get the key for this instance of the lock
 boolean hasLock()
           
 boolean lockFile()
          Write the key to the lock file.
private  java.lang.String readLock()
          Read the lock code from the file.
 boolean stealLock()
           
 boolean unlockFile()
          Write a blank file to the lock file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNLOCKED_KEY

public static java.lang.String UNLOCKED_KEY

logger

private org.apache.log4j.Logger logger
A logger for this clas


error

private ErrorManager error
This allows us to pass errors


key

private java.lang.String key
The key of this particular instance of the lock.


lockFile

private java.io.File lockFile
The lock file.


remoteFile

private java.lang.String remoteFile
The directory that the remote lock file is in


data

private Record data

frame

private StartFrame frame
Constructor Detail

Lock

public Lock(StartFrame givenFrame,
            Record d)
Create a lock from a string representing the local file and set the new key.

Parameters:
givenFrame - The main frame this lock is attached to.
d - the Record that this lock is associated with.
Method Detail

availableLock

public boolean availableLock()

hasLock

public boolean hasLock()

stealLock

public boolean stealLock()

getKey

private java.lang.String getKey()
Get the key for this instance of the lock

Returns:
a string that is the lock's key

readLock

private java.lang.String readLock()
Read the lock code from the file.

Returns:
the lock code for this file

lockFile

public boolean lockFile()
Write the key to the lock file.

Returns:
a boolean that is true if the file was writen to sucessfully, false otherwise

unlockFile

public boolean unlockFile()
Write a blank file to the lock file.

Returns:
a boolean that is true if the file was writen to sucessfully, false otherwise