atg.distributor
Class DistributorReader

java.lang.Object
  extended by java.lang.Thread
      extended by atg.distributor.DistributorProcess
          extended by atg.distributor.DistributorReader
All Implemented Interfaces:
DistributorConstants, java.lang.Runnable

public class DistributorReader
extends DistributorProcess

The DistributorReader is a thread process which handles the communication protocol from the DistributorReceiver.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
static java.lang.String CLASS_VERSION
          Class version string
 
Fields inherited from class atg.distributor.DistributorProcess
sResourceBundle
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Fields inherited from interface atg.distributor.DistributorConstants
DEBUG_PREFIX, DEFAULT_FILE_BUFFER_SIZE, ERROR_PREFIX, FAILURE_FLAG, FILECHECK_CMD, INFO_PREFIX, MAX_RETRIES_FOR_FILE_ACCESS, MY_RESOURCE_NAME, PUT_CMD, SUCCESS_FLAG, WARNING_PREFIX
 
Constructor Summary
DistributorReader(java.net.Socket pConnection, atg.distributor.DistributorReceiver pManager)
          Constructs an instanceof DistributorReader
 
Method Summary
 java.net.Socket getConnection()
          Returns property Connection
protected  java.lang.String localizeDirectoryPath(java.lang.String pDirectoryPath)
           
 void processConnection(java.net.Socket pConnection, java.io.File pCache)
          Handle processing a connection from a client.
protected  void processFileCheckCommand(java.io.DataInputStream pInput, java.io.DataOutputStream pOutput, java.io.File pCache)
           
protected  void processPutCommand(java.io.DataInputStream pInput, java.io.DataOutputStream pOutput, java.io.File pCache)
          Reads from the input stream the PUT protocol and creates a file in the local cache directory.
 void run()
          Handle processing connections from clients
 java.lang.String toString()
           
protected  void transmitFailureStatusCode(java.io.DataOutputStream pOutput)
          Sends the failure status code to the remote client
protected  void transmitSuccessStatusCode(java.io.DataOutputStream pOutput)
          Sends the success status code to the remote client
protected  boolean writeFile(java.io.File pFilePath, long pFileSize, java.io.DataInputStream pInput)
          Reads the data from the supplied input stream and writes the data to the given file
 
Methods inherited from class atg.distributor.DistributorProcess
isLoggingDebug, isLoggingError, isLoggingInfo, isLoggingWarning, logDebug, logDebug, logDebug, logError, logError, logError, logInfo, logInfo, logInfo, logWarning, logWarning, logWarning, setLoggingDebug, setLoggingError, setLoggingInfo, setLoggingWarning
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLASS_VERSION

public static java.lang.String CLASS_VERSION
Class version string

Constructor Detail

DistributorReader

public DistributorReader(java.net.Socket pConnection,
                         atg.distributor.DistributorReceiver pManager)
Constructs an instanceof DistributorReader

Method Detail

getConnection

public java.net.Socket getConnection()
Returns property Connection


run

public void run()
Handle processing connections from clients

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread

transmitSuccessStatusCode

protected void transmitSuccessStatusCode(java.io.DataOutputStream pOutput)
                                  throws java.io.IOException
Sends the success status code to the remote client

Parameters:
pOutput - the output stream to return a status to the client
Throws:
If - an error occurs while sending the status code
java.io.IOException

transmitFailureStatusCode

protected void transmitFailureStatusCode(java.io.DataOutputStream pOutput)
                                  throws java.io.IOException
Sends the failure status code to the remote client

Parameters:
pOutput - the output stream to return a status to the client
Throws:
If - an error occurs while sending the status code
java.io.IOException

writeFile

protected boolean writeFile(java.io.File pFilePath,
                            long pFileSize,
                            java.io.DataInputStream pInput)
                     throws java.io.IOException
Reads the data from the supplied input stream and writes the data to the given file

Parameters:
pFilePath - the file to store the data sent
pFileSize - the total amount of bytes that are being sent from the client
pInput - the input stream to read from the client
Returns:
true if the all the data was received, written to the given file successfully, and the client was properly notified
Throws:
java.io.IOException

localizeDirectoryPath

protected java.lang.String localizeDirectoryPath(java.lang.String pDirectoryPath)

processPutCommand

protected void processPutCommand(java.io.DataInputStream pInput,
                                 java.io.DataOutputStream pOutput,
                                 java.io.File pCache)
                          throws java.io.IOException
Reads from the input stream the PUT protocol and creates a file in the local cache directory. If this process was accomplished returns a success status code to the remote client.

Parameters:
pInput - the input stream to read from the client
pOutput - the output stream to return a status to the client
Throws:
java.io.IOException - if an error occurs while processing the command

processFileCheckCommand

protected void processFileCheckCommand(java.io.DataInputStream pInput,
                                       java.io.DataOutputStream pOutput,
                                       java.io.File pCache)
                                throws java.io.IOException
Throws:
java.io.IOException

processConnection

public void processConnection(java.net.Socket pConnection,
                              java.io.File pCache)
Handle processing a connection from a client. This method will process many commands.

A single transaction consists of the following:

  1. Client sends UTF string of command type (PUT, DELETE)
  2. Client sends UTF string of file name
  3. If the command is PUT, the client sends a long of the file size
  4. If the command is PUT, the client sends actual file as array of bytes
  5. Server performs command, saving the data as the desired file (PUT), deleting (DELETE) the requested file, or deleting all the files
  6. Server replies with UTF string 'SUCCESS' when operation has been completed
It is important to note that the return code is not sent until the file is actualy on disk or deleted.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Thread