xmlBlaster 2.2.0 API

org.xmlBlaster.contrib.filewriter
Class FileWriterCallback

java.lang.Object
  extended by org.xmlBlaster.contrib.filewriter.FileWriterCallback
All Implemented Interfaces:
ContribConstants, I_Update

public class FileWriterCallback
extends java.lang.Object
implements I_Update, ContribConstants

FileWriterCallback stores messages to the file system.

Author:
Michele Laghi

Field Summary
private static int BUF_SIZE
           
private  java.io.File directory
           
private  java.lang.String dirName
           
private  boolean keepDumpFiles
          if true it cleans up the chunks after processing, otherwise it leaves them.
private  java.lang.String lockExtention
           
private static java.util.logging.Logger log
           
private  boolean overwrite
           
private  java.io.File tmpDirectory
           
private  java.lang.String tmpDirName
           
 
Fields inherited from interface org.xmlBlaster.contrib.ContribConstants
FILE_DATE, FILENAME_ATTR, FILENAME_ATTR_OLD_FASHION, SUBDIR_ATTR, TIMESTAMP_ATTR, TOPIC_NAME
 
Constructor Summary
FileWriterCallback(java.lang.String dirName, java.lang.String tmpDirName, java.lang.String lockExtention, boolean overwrite, boolean keepDumpFiles)
          Creates a callback
 
Method Summary
private static boolean deleteFile(java.io.File file)
          Deletes the specified file from the file system.
private  long extractNumberPostfixFromFile(java.lang.String filename, java.lang.String prefix)
          Returns the number used as the postfix of this file.
private  java.io.File[] getChunkFilenames(java.lang.String fileName, char sep)
          The filename prefix for which to retrieve all chunks.
private  void putAllChunksTogether(java.lang.String fileName, java.lang.String subDir, long expectedChunks, java.io.InputStream is, boolean isCompleteMsg)
          Puts all chunks stored in separate files together in one single one.
private static void storeChunk(java.io.File tmpDir, java.lang.String fileName, long chunkNumber, char sep, boolean overwrite, java.io.InputStream is)
           
 void update(java.lang.String topic, java.io.InputStream is, java.util.Map attrMap)
          The message received from the MoM or from another source.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

BUF_SIZE

private static final int BUF_SIZE
See Also:
Constant Field Values

dirName

private java.lang.String dirName

lockExtention

private java.lang.String lockExtention

directory

private java.io.File directory

overwrite

private boolean overwrite

tmpDirName

private java.lang.String tmpDirName

tmpDirectory

private java.io.File tmpDirectory

keepDumpFiles

private boolean keepDumpFiles
if true it cleans up the chunks after processing, otherwise it leaves them.

Constructor Detail

FileWriterCallback

public FileWriterCallback(java.lang.String dirName,
                          java.lang.String tmpDirName,
                          java.lang.String lockExtention,
                          boolean overwrite,
                          boolean keepDumpFiles)
                   throws java.lang.Exception
Creates a callback

Parameters:
dirName - The name of the directory where to store the files.
tmpDirName - the name of the directory where to store the temporary files.
lockExtention - The extension to use to lock the reading of the file. This is used if the entries have to be retrieved by the file poller. Until such a file exists, the entry is not processed by the file poller.
overwrite - if set to true it will overwrite existing files.
Throws:
java.lang.Exception
Method Detail

storeChunk

private static void storeChunk(java.io.File tmpDir,
                               java.lang.String fileName,
                               long chunkNumber,
                               char sep,
                               boolean overwrite,
                               java.io.InputStream is)
                        throws java.lang.Exception
Throws:
java.lang.Exception

extractNumberPostfixFromFile

private long extractNumberPostfixFromFile(java.lang.String filename,
                                          java.lang.String prefix)
                                   throws java.lang.Exception
Returns the number used as the postfix of this file. If there is no such number, -1 is returned. If the content is null or empty, an exception is thrown. If there is a postfix but it is not a number, a -1 is returned.

Parameters:
filename - the filename to check.
prefix - the prefix of the filename (the part before the number)
Returns:
a long specifying the postfix number of the file.
Throws:
java.lang.Exception - if the content is null or empty.

getChunkFilenames

private java.io.File[] getChunkFilenames(java.lang.String fileName,
                                         char sep)
                                  throws java.lang.Exception
The filename prefix for which to retrieve all chunks.

Parameters:
fileName -
sep -
Returns:
Throws:
java.lang.Exception

putAllChunksTogether

private void putAllChunksTogether(java.lang.String fileName,
                                  java.lang.String subDir,
                                  long expectedChunks,
                                  java.io.InputStream is,
                                  boolean isCompleteMsg)
                           throws java.lang.Exception
Puts all chunks stored in separate files together in one single one.

Parameters:
fileName - The name of the complete (destination) file.
expectedChunks - The number of expected chunks. If the number of chunks found is bigger, the exceeding ones are ignored and a warning is written to the logs. If the number is too low it checks if the file already exists. If it exists a warning is written and the method returns, otherwise an exception is thrown. Keeps also track of locking the file.
lastContent - the content of the last chunk of the message (can be null).
isCompleteMsg - is true if the content of the message is contained in one single chunk (i.e. if the message is not chunked).
Throws:
java.lang.Exception - If an error occurs when writing / reading the files. This method tries to clean up the destination file in case of an exception when writing.

deleteFile

private static final boolean deleteFile(java.io.File file)
Deletes the specified file from the file system. Never throws Exceptions

Parameters:
file - the file object to be deleted.
Returns:
if it can not delete the file it returns false, true otherwise.

update

public void update(java.lang.String topic,
                   java.io.InputStream is,
                   java.util.Map attrMap)
            throws java.lang.Exception
Description copied from interface: I_Update
The message received from the MoM or from another source.

Specified by:
update in interface I_Update
Parameters:
topic - The topic name
attrMap - A map with attribute, can be null
Throws:
java.lang.Exception

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.