uk.ac.vamsas.client.simpleclient
Class SessionFile

java.lang.Object
  extended byuk.ac.vamsas.client.simpleclient.SessionFile
Direct Known Subclasses:
ListFile, VamsasFile

public class SessionFile
extends java.lang.Object

Basic methods for classes handling locked IO on files monitored by all (simpleclient) clients in a vamsas session.

Author:
jimp TODO: support non nio file locking capable systems

Field Summary
protected  Lock fileLock
           
protected  java.io.File sessionFile
           
 
Constructor Summary
protected SessionFile(java.io.File file)
           
 
Method Summary
protected  java.io.File backupSessionFile()
          Makes a backup of the sessionFile.
protected  java.io.File backupSessionFile(Lock extantLock, java.lang.String backupPrefix, java.lang.String backupSuffix, java.io.File backupDir)
           
protected  void eraseExistence()
          remove all trace of the sessionFile file
 java.io.BufferedInputStream getBufferedInputStream(boolean atStart)
           
 java.io.BufferedOutputStream getBufferedOutputStream(boolean clear)
           
 java.io.FileInputStream getFileInputStream(boolean atStart)
           
 java.io.FileOutputStream getFileOutputStream(boolean clear)
           
protected  boolean lockFile()
          Get a lock for the SessionFile
protected  boolean lockFile(Lock extantlock)
           
protected  void unlockFile()
          Explicitly release the SessionFile's lock.
protected  void updateFrom(Lock extantLock, SessionFile newData)
          Replaces data in sessionFile with data from file handled by another sessionFile passes up any exceptions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

sessionFile

protected java.io.File sessionFile

fileLock

protected Lock fileLock
Constructor Detail

SessionFile

protected SessionFile(java.io.File file)
Method Detail

lockFile

protected boolean lockFile(Lock extantlock)

lockFile

protected boolean lockFile()
Get a lock for the SessionFile

Returns:
true if lock was made

unlockFile

protected void unlockFile()
Explicitly release the SessionFile's lock.

Returns:
true if lock was released.

backupSessionFile

protected java.io.File backupSessionFile()
Makes a backup of the sessionFile.

Returns:
Backed up SessionFile or null if failed to make backup.

backupSessionFile

protected java.io.File backupSessionFile(Lock extantLock,
                                         java.lang.String backupPrefix,
                                         java.lang.String backupSuffix,
                                         java.io.File backupDir)

updateFrom

protected void updateFrom(Lock extantLock,
                          SessionFile newData)
                   throws java.io.IOException
Replaces data in sessionFile with data from file handled by another sessionFile passes up any exceptions.

Parameters:
newData - source for new data
Throws:
java.io.IOException

eraseExistence

protected void eraseExistence()
remove all trace of the sessionFile file


getBufferedInputStream

public java.io.BufferedInputStream getBufferedInputStream(boolean atStart)
                                                   throws java.io.IOException
Throws:
java.io.IOException

getBufferedOutputStream

public java.io.BufferedOutputStream getBufferedOutputStream(boolean clear)
                                                     throws java.io.IOException
Throws:
java.io.IOException

getFileInputStream

public java.io.FileInputStream getFileInputStream(boolean atStart)
                                           throws java.io.IOException
Throws:
java.io.IOException

getFileOutputStream

public java.io.FileOutputStream getFileOutputStream(boolean clear)
                                             throws java.io.IOException
Throws:
java.io.IOException