xmlBlaster 2.1.0 API

org.xmlBlaster.client.filepoller
Class DirectoryManager

java.lang.Object
  extended by org.xmlBlaster.client.filepoller.DirectoryManager

public class DirectoryManager
extends java.lang.Object

DirectoryManager

Author:
Michele Laghi

Field Summary
private  boolean copyOnMove
           
private  long delaySinceLastFileChange
           
private  java.io.File directory
           
private  java.util.Map directoryEntries
           
private  java.lang.String directoryName
           
private  java.io.File discardedDirectory
          this is the name of the directory where files are moved if they could not be send (too big)
private  java.io.FileFilter fileFilter
          all files matching the filter will be processed.
private  Global global
           
private  java.lang.String lockExt
          convenience for performance: if lockExtention is '*.gif', then this will be '.gif'
private  java.io.FileFilter lockExtention
          if set, then files will only be published when the lock-file has been removed.
private  java.util.Set lockFiles
           
private static java.util.logging.Logger log
           
private  java.lang.String ME
           
private  java.io.File sentDirectory
          this is the the directory where files are moved to after successful publishing.
 
Constructor Summary
DirectoryManager(Global global, java.lang.String name, java.lang.String directoryName, long delaySinceLastFileChange, java.lang.String filter, java.lang.String sent, java.lang.String discarded, java.lang.String lockExtention, boolean trueRegex, boolean copyOnMove)
           
 
Method Summary
private  boolean deleteFile(java.io.File tempFile)
          On Windows sometimes the file is not deleted (even if the stream.close() were called before) We try as long until the file is away See http://forum.java.sun.com/thread.jspa?forumID=4&threadID=158689
(package private)  void deleteOrMoveEntry(java.lang.String entryName, boolean success)
          Removes the specified entry from the map.
 byte[] getContent(FileInfo info)
          Gets the content from the specified file as a byte[].
(package private)  java.util.Set getEntries()
          Gets all entries which are ready to be sent (i.e.
private  java.util.Map getNewFiles(java.io.File directory)
          Retrieves all files from the specified directory
private  java.io.File initDirectory(java.io.File parent, java.lang.String propNameForLogging, java.lang.String dirName)
          Returns the specified directory or null or if needed it will create one
static boolean isFileNameCasesensitive()
           
private  boolean isReady(FileInfo info, long currentTime)
          Returns false if the info object is null, if the size is zero or if it has not passed sufficient time since the last change.
static void main(java.lang.String[] args)
          java org.xmlBlaster.client.filepoller.DirectoryManager -path /tmp/filepoller -filter "*.xml" -filterType simple
private  void moveTo(java.io.File file, java.lang.String origName, java.io.File destinationDirectory)
           
private  java.util.TreeSet prepareEntries(java.io.File directory, java.util.Map existingFiles)
           
private  void updateExistingFiles(java.util.Map existingFiles, java.util.Map newFiles)
          It updates the existing list of files: - if a file which previously existed is not found in the new list anymore it is deleted - new files are added to the list - if something has changed (timestamp or size, then the corresponding info object is touched
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

private java.lang.String ME

global

private Global global

log

private static java.util.logging.Logger log

delaySinceLastFileChange

private long delaySinceLastFileChange

directoryName

private java.lang.String directoryName

directory

private java.io.File directory

sentDirectory

private java.io.File sentDirectory
this is the the directory where files are moved to after successful publishing. If null they will be erased


discardedDirectory

private java.io.File discardedDirectory
this is the name of the directory where files are moved if they could not be send (too big)


directoryEntries

private java.util.Map directoryEntries

fileFilter

private java.io.FileFilter fileFilter
all files matching the filter will be processed. Null means everything will be processed


lockExtention

private java.io.FileFilter lockExtention
if set, then files will only be published when the lock-file has been removed.


lockExt

private java.lang.String lockExt
convenience for performance: if lockExtention is '*.gif', then this will be '.gif'


lockFiles

private java.util.Set lockFiles

copyOnMove

private boolean copyOnMove
Constructor Detail

DirectoryManager

public DirectoryManager(Global global,
                        java.lang.String name,
                        java.lang.String directoryName,
                        long delaySinceLastFileChange,
                        java.lang.String filter,
                        java.lang.String sent,
                        java.lang.String discarded,
                        java.lang.String lockExtention,
                        boolean trueRegex,
                        boolean copyOnMove)
                 throws XmlBlasterException
Throws:
XmlBlasterException
Method Detail

initDirectory

private java.io.File initDirectory(java.io.File parent,
                                   java.lang.String propNameForLogging,
                                   java.lang.String dirName)
                            throws XmlBlasterException
Returns the specified directory or null or if needed it will create one

Parameters:
propName -
dirName -
Returns:
Throws:
XmlBlasterException

getNewFiles

private java.util.Map getNewFiles(java.io.File directory)
                           throws XmlBlasterException
Retrieves all files from the specified directory

Parameters:
directory -
Returns:
never returns null.
Throws:
XmlBlasterException

deleteFile

private boolean deleteFile(java.io.File tempFile)
On Windows sometimes the file is not deleted (even if the stream.close() were called before) We try as long until the file is away See http://forum.java.sun.com/thread.jspa?forumID=4&threadID=158689

Parameters:
tempFile -
Returns:
true if successfully deleted

isFileNameCasesensitive

public static boolean isFileNameCasesensitive()

isReady

private boolean isReady(FileInfo info,
                        long currentTime)
Returns false if the info object is null, if the size is zero or if it has not passed sufficient time since the last change.

Parameters:
info -
currentTime -
Returns:

prepareEntries

private java.util.TreeSet prepareEntries(java.io.File directory,
                                         java.util.Map existingFiles)

updateExistingFiles

private void updateExistingFiles(java.util.Map existingFiles,
                                 java.util.Map newFiles)
It updates the existing list of files: - if a file which previously existed is not found in the new list anymore it is deleted - new files are added to the list - if something has changed (timestamp or size, then the corresponding info object is touched

Parameters:
existingFiles -
newFiles -

getEntries

java.util.Set getEntries()
                   throws XmlBlasterException
Gets all entries which are ready to be sent (i.e. to be published)

Returns:
all entries as a TreeSet. Elements in the set are of type FileInfo
Throws:
XmlBlasterException - if the application has no read or write rights on the directory

deleteOrMoveEntry

void deleteOrMoveEntry(java.lang.String entryName,
                       boolean success)
                 throws XmlBlasterException
Removes the specified entry from the map. This method does also remove the entry from the file system or it moves it to the requested directory. If for some reason this is not possible, then an exception is thrown.

Parameters:
entryName - the name of the entry to remove.
Throws:
XmlBlasterException

moveTo

private void moveTo(java.io.File file,
                    java.lang.String origName,
                    java.io.File destinationDirectory)
             throws XmlBlasterException
Throws:
XmlBlasterException

getContent

public byte[] getContent(FileInfo info)
                  throws XmlBlasterException
Gets the content from the specified file as a byte[]. If this is not possible it will throw an exception.

Parameters:
info -
Returns:
Throws:
XmlBlasterException

main

public static void main(java.lang.String[] args)
java org.xmlBlaster.client.filepoller.DirectoryManager -path /tmp/filepoller -filter "*.xml" -filterType simple


xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.