uk.ac.vamsas.client.simpleclient
Class SessionsFile

java.lang.Object
  extended byuk.ac.vamsas.client.simpleclient.SessionFile
      extended byuk.ac.vamsas.client.simpleclient.ListFile
          extended byuk.ac.vamsas.client.simpleclient.SessionsFile

public class SessionsFile
extends ListFile

Author:
Pierre MARGUERITE

Field Summary
 
Fields inherited from class uk.ac.vamsas.client.simpleclient.SessionFile
fileLock, sessionFile
 
Constructor Summary
SessionsFile(java.io.File file)
           
 
Method Summary
protected  int addSession(SessionHandle session, boolean disambiguate)
          Adds a SessionHandle to the SessionList file - optionally disambiguating the SessionHandle (modifes the URN).
 int addSession(SessionHandle newSession, boolean disambig, Lock extantLock)
          adds SessionsHandle me to the sessionsList under an existing lock.
 int addSession(SessionHandle newSession, Lock extantLock)
          adds SessionHandle me to the sessionList under an existing lock extantLock.
 void clearList()
           
protected  boolean putSessionsList(SessionHandle[] clients)
          safely writes sessions array to the file referred to by sessionFile.
 void removeSession(SessionHandle session, Lock sessionlock)
          removes the current session from the SessionsList without complaint if the session isn't in the sessionsList already.
 SessionHandle[] retrieveSessionsList()
          get the SessionsList from the file.
 SessionHandle[] retrieveSessionsList(Lock extantlock)
          get list from the locked SessionsList.
 
Methods inherited from class uk.ac.vamsas.client.simpleclient.SessionFile
backupSessionFile, backupSessionFile, eraseExistence, getBufferedInputStream, getBufferedOutputStream, getFileInputStream, getFileOutputStream, lockFile, lockFile, unlockFile, updateFrom
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SessionsFile

public SessionsFile(java.io.File file)
             throws java.io.IOException
Parameters:
file -
Method Detail

retrieveSessionsList

public SessionHandle[] retrieveSessionsList()
get the SessionsList from the file. May return null if lock failed!

Returns:
sessionsList

retrieveSessionsList

public SessionHandle[] retrieveSessionsList(Lock extantlock)
get list from the locked SessionsList.

Parameters:
extantlock -
Returns:
sessionList or null if lock failed (or file was empty)

addSession

public int addSession(SessionHandle newSession,
                      Lock extantLock)
adds SessionHandle me to the sessionList under an existing lock extantLock.

Parameters:
newSession -
extantLock -
Returns:
session index in list or 0 if lock was invalid or addSession operation failed.

addSession

public int addSession(SessionHandle newSession,
                      boolean disambig,
                      Lock extantLock)
adds SessionsHandle me to the sessionsList under an existing lock.

Parameters:
newSession - - sessionsHandle
disambig - - if true then add will fail if an identical sessionHandle already exists
extantLock - - existing lock
Returns:
client index in list or 0 if addSession (or the lock) failed.

removeSession

public void removeSession(SessionHandle session,
                          Lock sessionlock)
removes the current session from the SessionsList without complaint if the session isn't in the sessionsList already.

Parameters:
session - session handle to be removed
sessionlock - existing lock passed from watcher.

addSession

protected int addSession(SessionHandle session,
                         boolean disambiguate)
Adds a SessionHandle to the SessionList file - optionally disambiguating the SessionHandle (modifes the URN). Note: Caller is left to release the lock on the SessionList.

Parameters:
session -
disambiguate - - flag indicating if the URN for me should be disambiguated to differentiate between sessions.
Returns:
index of sessionHandle in new list, or -1-position of existing sessionHandle (if disambiguate is true)

putSessionsList

protected boolean putSessionsList(SessionHandle[] clients)
safely writes sessions array to the file referred to by sessionFile.

Parameters:
clients -
Returns:
true if successful write. Throws Errors otherwise.

clearList

public void clearList()