uk.ac.vamsas.client.simpleclient
Class ClientsFile

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

public class ClientsFile
extends ListFile

Handler for the clientsFile within a vamsas session thread.

Author:
jim

Field Summary
 
Fields inherited from class uk.ac.vamsas.client.simpleclient.SessionFile
fileLock, sessionFile
 
Constructor Summary
ClientsFile(java.io.File filelist)
           
 
Method Summary
 int addClient(ClientHandle me)
          adds the ClientHandle to the list - if it is not unique, then the ClientHandle object is modified to make it unique in the list.
protected  int addClient(ClientHandle me, boolean disambiguate)
          Adds a ClientHandle to the ClientList file - optionally disambiguating the ClientHandle (modifes the URN).
 int addClient(ClientHandle me, boolean disambig, Lock extantLock)
          adds clientHandle me to the clientList under an existing lock.
 int addClient(ClientHandle me, Lock extantLock)
          adds clientHandle me to the clientList under an existing lock extantLock.
 void clearList()
           
protected  boolean putClientList(ClientHandle[] clients)
          safely writes clients array to the file referred to by sessionFile.
 void removeClient(ClientHandle me, Lock clientlock)
          removes 'me' from the session ClientList without complaint if 'me' isn't in the clientList already.
 ClientHandle[] retrieveClientList()
          get the clientList from the file.
 ClientHandle[] retrieveClientList(Lock extantlock)
          get list from the locked ClientList.
 
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

ClientsFile

public ClientsFile(java.io.File filelist)
            throws java.io.IOException
Method Detail

retrieveClientList

public ClientHandle[] retrieveClientList()
get the clientList from the file. May return null if lock failed!

Returns:
clientList

retrieveClientList

public ClientHandle[] retrieveClientList(Lock extantlock)
get list from the locked ClientList.

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

addClient

public int addClient(ClientHandle me,
                     Lock extantLock)
adds clientHandle me to the clientList under an existing lock extantLock.

Parameters:
me -
extantLock -
Returns:
client index in list or 0 if lock was invalid or addClient operation failed.

addClient

public int addClient(ClientHandle me,
                     boolean disambig,
                     Lock extantLock)
adds clientHandle me to the clientList under an existing lock.

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

addClient

public int addClient(ClientHandle me)
adds the ClientHandle to the list - if it is not unique, then the ClientHandle object is modified to make it unique in the list. returns the clientNumber for the client in the session.

Parameters:
me -
Returns:

removeClient

public void removeClient(ClientHandle me,
                         Lock clientlock)
removes 'me' from the session ClientList without complaint if 'me' isn't in the clientList already.

Parameters:
me - client handle to be removed
clientlock - existing lock passed from watcher.

addClient

protected int addClient(ClientHandle me,
                        boolean disambiguate)
Adds a ClientHandle to the ClientList file - optionally disambiguating the ClientHandle (modifes the URN). Note: Caller is left to release the lock on the ClientList.

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

putClientList

protected boolean putClientList(ClientHandle[] clients)
safely writes clients array to the file referred to by sessionFile.

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

clearList

public void clearList()