org.biffle.cliff.pearl
Class PearlTCPConnection

java.lang.Object
  |
  +--org.biffle.cliff.pearl.PearlTCPConnection
All Implemented Interfaces:
PearlConnection
Direct Known Subclasses:
Pearl2TCPConnection

public class PearlTCPConnection
extends java.lang.Object
implements PearlConnection

Provides a TCP implementation of the Pearl protocol.


Field Summary
protected static int AUTHENTICATE
          Message type for Authenticate message.
protected  boolean authenticated
           
protected static int BUSY
          Message type for Busy message.
protected static int DELETE_FILE
          Message type for Delete File message.
protected static int GET_ALL_FILE_INFO
          Message type for Get All File Info message.
protected static int GET_DATABASE_LOCK
          Message type for Get Database Lock message.
protected static int GET_DEVICE_INFO
          Message type for Get Device Info message.
protected static int GET_DEVICE_SETTINGS
          Message type for Get Device Settings message.
protected static int GET_FILE_INFO
          Message type for Get File Info message.
protected static int GET_SALT
          Message type for Get Salt message.
protected static int GET_STORAGE_INFO
          Message type for Get Storage Info message.
protected static int NAK
          Message type for NAK message.
protected static int PROTOCOL_VERSION
          Message type for Protocol Version message.
protected static int READ
          Message type for Read message.
protected  boolean readLock
           
protected static int RELEASE_DATABASE_LOCK
          Message type for Release Database Lock message.
protected  java.net.Socket saki
          The socket used to communicate with the Pearl device.
protected static int SET_FILE_INFO
          Message type for Set File Info message.
protected static byte[] signature
          Protocol signature (Rio, accented, in UTF-8)
protected static int WRITE
          Message type for Write message.
protected  boolean writeLock
           
 
Constructor Summary
PearlTCPConnection(java.net.InetAddress addr, int port)
           
 
Method Summary
 void authenticate(java.lang.String password)
          Attempts to authenticate using a given password.
 void close()
          Closes a connection.
 void deleteFile(int fid)
          Removes a file from the device.
 void getAllFileInfo(FileInfoListener target)
          Retrieves all file information from the device using a callback mechanism.
 DeviceInfo getDeviceInfo()
          Returns an object encapsulating basic device information -- number of storage devices, system software name, and firmware version.
 DeviceSettings getDeviceSettings()
          Retrieves the Pearl device's settings as a DeviceSettings object.
 FileInfo getFileInfo(int fid)
          Retrieves information on a single file, by FID.
protected  Message getMessage()
           
protected  java.lang.String getNullTermString()
           
 StorageInfo getStorageInfo(int idx)
          Retrieves information about a storage device in the Pearl device.
 int[] getVersion()
          Returns the version of the protocol being used as an array of two integers: the major and minor versions, respectively.
 boolean isAuthenticated()
          Checks to see if the underlying session has been successfully authenticated.
protected  void lockDatabase(int lockType)
           
 long readFileChunk(int fid, long offset, long size, byte[] buffer)
          Retrieves a chunk of a file into a supplied buffer.
protected  void sendMessage(Message m)
           
 void setFileInfo(int fid, FileInfo newInfo)
          Updates information for a file identified by FID.
protected  void unlockDatabase()
           
 void writeFileChunk(int fid, int storageID, long offset, long size, byte[] buffer)
          Writes a chunk of a file from a supplied buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

signature

protected static final byte[] signature
Protocol signature (Rio, accented, in UTF-8)


PROTOCOL_VERSION

protected static final int PROTOCOL_VERSION
Message type for Protocol Version message.

See Also:
Constant Field Values

NAK

protected static final int NAK
Message type for NAK message.

See Also:
Constant Field Values

BUSY

protected static final int BUSY
Message type for Busy message.

See Also:
Constant Field Values

GET_SALT

protected static final int GET_SALT
Message type for Get Salt message.

See Also:
Constant Field Values

AUTHENTICATE

protected static final int AUTHENTICATE
Message type for Authenticate message.

See Also:
Constant Field Values

GET_DEVICE_INFO

protected static final int GET_DEVICE_INFO
Message type for Get Device Info message.

See Also:
Constant Field Values

GET_STORAGE_INFO

protected static final int GET_STORAGE_INFO
Message type for Get Storage Info message.

See Also:
Constant Field Values

GET_DEVICE_SETTINGS

protected static final int GET_DEVICE_SETTINGS
Message type for Get Device Settings message.

See Also:
Constant Field Values

GET_DATABASE_LOCK

protected static final int GET_DATABASE_LOCK
Message type for Get Database Lock message.

See Also:
Constant Field Values

RELEASE_DATABASE_LOCK

protected static final int RELEASE_DATABASE_LOCK
Message type for Release Database Lock message.

See Also:
Constant Field Values

WRITE

protected static final int WRITE
Message type for Write message.

See Also:
Constant Field Values

GET_ALL_FILE_INFO

protected static final int GET_ALL_FILE_INFO
Message type for Get All File Info message.

See Also:
Constant Field Values

GET_FILE_INFO

protected static final int GET_FILE_INFO
Message type for Get File Info message.

See Also:
Constant Field Values

SET_FILE_INFO

protected static final int SET_FILE_INFO
Message type for Set File Info message.

See Also:
Constant Field Values

READ

protected static final int READ
Message type for Read message.

See Also:
Constant Field Values

DELETE_FILE

protected static final int DELETE_FILE
Message type for Delete File message.

See Also:
Constant Field Values

saki

protected java.net.Socket saki
The socket used to communicate with the Pearl device.


authenticated

protected boolean authenticated

readLock

protected boolean readLock

writeLock

protected boolean writeLock
Constructor Detail

PearlTCPConnection

public PearlTCPConnection(java.net.InetAddress addr,
                          int port)
                   throws java.io.IOException,
                          PearlException
Method Detail

getVersion

public int[] getVersion()
                 throws PearlException
Returns the version of the protocol being used as an array of two integers: the major and minor versions, respectively.

Specified by:
getVersion in interface PearlConnection
PearlException

isAuthenticated

public boolean isAuthenticated()
Checks to see if the underlying session has been successfully authenticated.

Specified by:
isAuthenticated in interface PearlConnection

authenticate

public void authenticate(java.lang.String password)
                  throws PearlException
Attempts to authenticate using a given password.

Specified by:
authenticate in interface PearlConnection
PearlException

getDeviceInfo

public DeviceInfo getDeviceInfo()
                         throws PearlException
Returns an object encapsulating basic device information -- number of storage devices, system software name, and firmware version.

Specified by:
getDeviceInfo in interface PearlConnection
PearlException

getStorageInfo

public StorageInfo getStorageInfo(int idx)
                           throws PearlException
Retrieves information about a storage device in the Pearl device.

Specified by:
getStorageInfo in interface PearlConnection
PearlException

getDeviceSettings

public DeviceSettings getDeviceSettings()
                                 throws PearlException
Retrieves the Pearl device's settings as a DeviceSettings object.

Specified by:
getDeviceSettings in interface PearlConnection
PearlException

getAllFileInfo

public void getAllFileInfo(FileInfoListener target)
                    throws PearlException
Retrieves all file information from the device using a callback mechanism. As each file comes in, it is delivered as a FileInfo object to the target.

Specified by:
getAllFileInfo in interface PearlConnection
PearlException

getFileInfo

public FileInfo getFileInfo(int fid)
                     throws PearlException
Retrieves information on a single file, by FID.

Specified by:
getFileInfo in interface PearlConnection
PearlException

setFileInfo

public void setFileInfo(int fid,
                        FileInfo newInfo)
                 throws PearlException
Updates information for a file identified by FID.

Specified by:
setFileInfo in interface PearlConnection
PearlException

writeFileChunk

public void writeFileChunk(int fid,
                           int storageID,
                           long offset,
                           long size,
                           byte[] buffer)
                    throws PearlException
Writes a chunk of a file from a supplied buffer.

Specified by:
writeFileChunk in interface PearlConnection
Parameters:
fid - The FID of the file to write.
storageID - The index of the storage device to write to.
offset - The offset within the file to begin writing.
size - The number of bytes to be written.
buffer - The buffer from which bytes are sent.
PearlException

readFileChunk

public long readFileChunk(int fid,
                          long offset,
                          long size,
                          byte[] buffer)
                   throws PearlException
Retrieves a chunk of a file into a supplied buffer.

Specified by:
readFileChunk in interface PearlConnection
Parameters:
fid - The FID of the file to read.
offset - The offset within the file to begin reading.
size - The number of bytes desired. If the end of the file is encountered, this will be fewer than were requested.
buffer - The buffer into which bytes are copied.
Returns:
The number of bytes read.
PearlException

deleteFile

public void deleteFile(int fid)
                throws PearlException
Removes a file from the device.

Specified by:
deleteFile in interface PearlConnection
PearlException

close

public void close()
Description copied from interface: PearlConnection
Closes a connection.

Specified by:
close in interface PearlConnection

lockDatabase

protected void lockDatabase(int lockType)
                     throws PearlException
PearlException

unlockDatabase

protected void unlockDatabase()
                       throws PearlException
PearlException

sendMessage

protected void sendMessage(Message m)
                    throws java.io.IOException
java.io.IOException

getMessage

protected Message getMessage()
                      throws java.io.IOException
java.io.IOException

getNullTermString

protected java.lang.String getNullTermString()
                                      throws java.io.IOException
java.io.IOException