| 
 | Apache Tomcat 6.0.53 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.apache.catalina.ha.deploy.FileMessageFactory
public class FileMessageFactory
This factory is used to read files and write files by splitting them up into
 smaller messages. So that entire files don't have to be read into memory.
 
 The factory can be used as a reader or writer but not both at the same time.
 When done reading or writing the factory will close the input or output
 streams and mark the factory as closed. It is not possible to use it after
 that. 
 To force a cleanup, call cleanup() from the calling object. 
 This class is not thread safe.
| Field Summary | |
|---|---|
| protected  boolean | closedOnce the factory is used, it can not be reused. | 
| protected  byte[] | dataThe bytes that we hold the data in, not thread safe. | 
| protected  java.io.File | fileThe file that we are reading/writing | 
| protected  java.io.FileInputStream | inWhen openForWrite=false, the input stream is held by this variable | 
| protected  boolean | isWritingFlag that indicates if a thread is writing messages to disk. | 
| protected  java.util.concurrent.atomic.AtomicLong | lastMessageProcessedThe number of the last message procssed. | 
| static Log | log | 
| protected  java.util.Map<java.lang.Long,FileMessage> | msgBufferMessages received out of order are held in the buffer until required. | 
| protected  int | nrOfMessagesProcessedThe number of messages we have written | 
| protected  boolean | openForWriteTrue means that we are writing with this factory. | 
| protected  java.io.FileOutputStream | outWhen openForWrite=true, the output stream is held by this variable | 
| static int | READ_SIZEThe number of bytes that we read from file | 
| protected  long | sizeThe total size of the file | 
| protected  long | totalNrOfMessagesThe total number of packets that we split this file into | 
| Method Summary | |
|---|---|
| protected  void | checkState(boolean openForWrite)Check to make sure the factory is able to perform the function it is asked to do. | 
|  void | cleanup()Closes the factory, its streams and sets all its references to null | 
|  java.io.File | getFile() | 
| static FileMessageFactory | getInstance(java.io.File f,
            boolean openForWrite)Creates a factory to read or write from a file. | 
| static void | main(java.lang.String[] args)Example usage. | 
|  FileMessage | readMessage(FileMessage f)Reads file data into the file message and sets the size, totalLength, totalNrOfMsgs and the message number If EOF is reached, the factory returns null, and closes itself, otherwise the same message is returned as was passed in. | 
|  boolean | writeMessage(FileMessage msg)Writes a message to file. | 
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static Log log
public static final int READ_SIZE
protected java.io.File file
protected boolean openForWrite
protected boolean closed
protected java.io.FileInputStream in
protected java.io.FileOutputStream out
protected int nrOfMessagesProcessed
protected long size
protected long totalNrOfMessages
protected java.util.concurrent.atomic.AtomicLong lastMessageProcessed
protected java.util.Map<java.lang.Long,FileMessage> msgBuffer
protected byte[] data
protected boolean isWriting
| Method Detail | 
|---|
public static FileMessageFactory getInstance(java.io.File f,
                                             boolean openForWrite)
                                      throws java.io.FileNotFoundException,
                                             java.io.IOException
f - File - the file to be read or writtenopenForWrite - boolean - true, means we are writing to the file, false means
            we are reading from it
java.io.FileNotFoundException - -
             if the file to be read doesn't exist
java.io.IOException - -
             if it fails to create the file that is to be written
public FileMessage readMessage(FileMessage f)
                        throws java.lang.IllegalArgumentException,
                               java.io.IOException
f - FileMessage - the message to be populated with file data
java.lang.IllegalArgumentException - -
             if the factory is for writing or is closed
java.io.IOException - -
             if a file read exception occurs
public boolean writeMessage(FileMessage msg)
                     throws java.lang.IllegalArgumentException,
                            java.io.IOException
msg - FileMessage - message containing data to be written
java.lang.IllegalArgumentException - -
             if the factory is opened for read or closed
java.io.IOException - -
             if a file write error occurspublic void cleanup()
protected void checkState(boolean openForWrite)
                   throws java.lang.IllegalArgumentException
openForWrite - boolean
java.lang.IllegalArgumentException
public static void main(java.lang.String[] args)
                 throws java.lang.Exception
args - String[], args[0] - read from filename, args[1] write to
            filename
java.lang.Exceptionpublic java.io.File getFile()
| 
 | Apache Tomcat 6.0.53 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||