XmlBlaster Logo

REQUIREMENT

client.filepoller

XmlBlaster Logo


Type OLD
Priority HIGH
Status DEPRECATED
Topic You can publish messages by putting files on a certain location in the file system.
Des
cription

This is deprecated. It has been replaced by the contrib.filewatcher requirement.

This is a native plugin which is listening on a certain directory in the file system. It detects by polling on the directory if a new file has arrived. Once the plugin assumes it has completely written, it will read its contents and publish them.
  • The Poller is running as a native xmlBlaster plugin
  • Every registered Poller is listening on exactly one single directory
  • The polling interval is expressed in ms and is configurable
  • All files in a directory on which a Poller instance is listening, are published on a single configurable topic.
  • It is possible to specify a filter for the file name, then only the files matching the filter will be processed by the current plugin instance.
  • It is possible to have several plugins polling for the same directory provided they all have a filter specified. The choice of the filters must be such to avoid that the same file will match more than one filter. If the user does not ensure that, unpredicted behavior will result.
  • After a successful publish of the content of a file, the file is removed from the file system. Alternatively, if a 'sent' directory is specified in the configuration, processed files will be moved to that destination. If for some reason it is not possible to move the file to that direction (for example if necessary rights are missing), then the plugin will continue to poll but will not process any file anymore until the problem has been manually removed.
  • It is possible to configure a maximum file size. Files bigger than the specified size are not published. If a 'discarded' directory is specified in the properties, then the file will be moved to that directory, otherwise it will be deleted.
  • When moving files, wether to the 'sent' or 'discarded' directories, if a file with the same relative name already exists, it is overwritten.
  • Detection of 'file ready for publishing':

    If lockExtention is specified in the plugin configuration, then publishing of a file is controlled by a lock file. This means that if you specified *.lck as the lockExtention, and want to publish a file called someFile.gif, then the publishing of the file will be inhibited until a file someFile.gif.lck will be present in the directory.

    The plugin will wait delaySinceLastFileChange milliseconds since the last modification of the file to be published (date and size are checked) before processing anyway. This way, by choosing a sufficiently long delaySinceLastFileChange it is possible to work in an optimistic way without any lock file.

    Note however that this optimistic publishing is not to 100% safe. Suppose the writing of the file to be published is stalled for a time which is longer than what specified in delaySinceLastFileChange, then the file will be published in its incomplete state.

  • If permissions to read the directory are missing or xmlBlaster has no read rights on a specific file, or if an IO exception occurs when reading a file or trying to delete or move a file, an error is reported (logged) and the plugin does temporarly stop working. (to ensure correct sequence). The plugin continues however to poll and when the rights are manually fixed, it continues working again.
  • To be able to track the message origin, filename and date are sent in the client properties as:
    • _fileName
    • (the relative file name as a String)
    • _fileDate
    • (the timestamp of the file in ms as a long)
  • To listen to different directories and/or to publish on different topics you need to configure different plugins. When doing so assign to each plugin a different id (this is actually a general requirement for the plugins).
  • The files to be published are sorted in the first place chronologically. Files having the same last change timestamp are sorted alphabetically. The best precision for the timestamp is one millisecond. If the operating system does not offer such a precision, the precision of the operating system will be determinant. Also, the timestamp is the last change timestamp. Depending on the operating system this time could be the time when the writing operation is started, when it is ended or in between. This would have to be considered when the applications writing to the directory on which the filepoller is listening are working multithreaded.
Example
any

Testing your filter pattern

You have two options to test your regular expression or your 'simple' filter in your configuration.

First, you can use the jconsole (see admin.jmx requirement) to test your filter pattern. Go to the MBean -> org.xmlBlaster -> node -> [your cluster name] -> service -> FilePollerPlugin[xxx] area. Here you can adjust all settings dynamically and test the settings under the tab Operations by clicking the triggerScan button.

Further you can test the pattern on command line:

 java org.xmlBlaster.client.filepoller.DirectoryManager -path /tmp/filepoller -filter "*.xml" -filterType simple 

 java org.xmlBlaster.client.filepoller.DirectoryManager -path /tmp/filepoller -filter "hi.*\.xml" -filterType regex 
Configure

The plugin is configured in the xmlBlasterPlugins.xml configuration file. Here an example where all properties are used:


  <xmlBlaster>
    ...

     <plugin id='FilePollerPlugin' className='org.xmlBlaster.client.filepoller.FilePollerPlugin'>
        <attribute id='directoryName'>/tmp/filePoller</attribute>
        <attribute id='topicName'>poller.test</attribute>
        <attribute id='publishKey'><key oid='poller.test'><poller><test/></poller></key></attribute>
        <attribute id='publishQos'><qos><expiration lifeTime='4000'/></qos></attribute>
        <attribute id='connectQos'></attribute>
        <attribute id='maximumFileSize'>10000000</attribute>
        <attribute id='delaySinceLastFileChange'>10000</attribute>
        <attribute id='pollInterval'>2000</attribute>

        <attribute id='loginName'>fritz</attribute>
        <attribute id='password'>secret</attribute>
        <attribute id='sent'>Sent</attribute>
        <attribute id='discarded'>Discarded</attribute>
        <attribute id='fileFilter'></attribute>
        <attribute id='lockExtention'>*.lck</attribute>
        <attribute id='filterType'>simple</attribute>

        <action do='LOAD' onStartupRunlevel='9' sequence='6' onFail='resource.configuration.pluginFailed'/>
        <action do='STOP' onShutdownRunlevel='6' sequence='5'/>
     </plugin>
   ...

 </xmlBlaster>

and here a minimalistic one:

  <xmlBlaster>
    ...

     <plugin id='FilePollerPlugin' className='org.xmlBlaster.client.filepoller.FilePollerPlugin'>
        <attribute id='directoryName'>/tmp/filePoller</attribute>
        <attribute id='topicName'>poller.test</attribute>
        <!-- determines on which level to start/shutdown the plugin and what to do in case of an exception -->
        <action do='LOAD' onStartupRunlevel='9' sequence='6' onFail='resource.configuration.pluginFailed'/>
        <action do='STOP' onShutdownRunlevel='6' sequence='5'/>
     </plugin>
   ...

 </xmlBlaster>

and here a more detailed description about each attribute:
id (name) type default value Comment
directoryName String null mandatory: The name of the directory on which this plugin instance will listen. If the directory does not exist, one will be created. You can specify an absolute name or a relative one. A relative one is based on the ${user.home}.
topicName String null mandatory unless publishKey defined. If both are specified this attribute is ignored and a warning is logged. This is the name of the topic on which to publish (the oid).
publishKey String null optional unless topicName has not been specified in which case it is mandatory. If you need to specify a more complex key for the publishing (for example to make it searcheable) of the messages you can specify it here. Note that you can only specify one single key which will be used for all messages published by this plugin. If you need to differentiate you can use more plugins.
publishQos String null optional. If you need to specify a more complex qos for the publishing you can specify it here. Note that you can only specify one single qos which will be used for all messages published by this plugin. If you need to differentiate you can use more plugins.
connectQos String null optional. If you need to specify more complex connection behavior you can do it here. Note however that this is a plugin which per default uses the local protocol.
loginName String '_' + id of plugin optional. If the id of the plugin is poller1, then the default loginName is _poller1. If you specify a connectQos, then this attribute is ignored.
password String null optional. This is the password to be used to authenticate the loginName. If you specify a connectQos, then this attribute is ignored.
pollInterval long 2000 optional: The time in milliseconds the plugin sleeps between each poll sweep. This time is also the one used to retry an action which has failed (reading, deleting or moving a file).
delaySinceLastFileChange long 10000 optional: This is the time expressed in milliseconds which the plugin will wait before publishing a file after its latest detected change. The plugin detects changes on discrete times (every time it polls), so the acurancy is never better than what specified in pollInterval. A file is considered to have changed either if its size has changed or its date. The plugin always waits what specified here even when using a lock file. So if you always control your publishes with a locking file you can set this attribute to zero to avoid delay.
maximumFileSize long 10000000 optional: The maximum file size expressed in bytes to be allowed to be published. If the file exceeds this size, then it is not published. It is either deleted or moved to the directory specified in the discarded attribute.
fileFilter String null optional: If you want this plugin to be listening only on a specified filename extention you can specify it here. Let's say you only want files with the gif extention to be sent, then you specify *.gif. If something is specified here, files on the directory not matching this pattern are left untouched and are not published.
lockExtention String null optional: If you want to use the locking approach you need to specify here the extention of the lock files. The syntax is of the kind *.lck, i.e. the first character is a '*'.
sent String null optional: If nothing is specified here, files are deleted after having been published. If something is specified here it is assumed to be a directory and files published are moved to this location. If the directory does not exist, one is created once the plugin is initialized. You can either specify an absolute or a relative directory name. Relative names are put in the directory specified in the directoryName attribute.
discarded String null optional: If nothing is specified here, files which are too big to be published are deleted. If something is specified it is assumed to be a directory and the files which are too bif are moved to this location. If the directory does not exist, one is created once the plugin is initialized. You can either specify an absolute or a relative directory name. Relative names are put in the directory specified in the directoryName attribute.
filterType String simple optional: If nothing is specified here, 'simple' is assumed. Valid types are 'simple' and 'regex'. This attribute decides which filter to use when processing both the fileFilter. If you choose 'simple' then you can specify filters of the kind '*.xml' which are very simple to be used but somehow limited if you want more advanced things to be done. The type 'regex' allows you to use regex syntax for the fileFilter. Note that lockExtention is not affected by this flag and is always considered of type 'simple'.
copyOnMove boolean true optional: This flag has only effect if sent or discarded have been defined. If this flag is set to false then the file will be simply moved (or renamed). This is fast but it does not work on all OS systems. Particularly on non-local file systems this is known to fail. Leaving this flag true (default) forces a complete copy/delete of the file. This is slower but works even on file systems mounted remotely like nfs, samba or cifs.

NOTE: Configuration parameters are specified on command line (-someValue 17) or in the xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
Columns named Impl tells you if the feature is implemented.
Columns named Hot tells you if the configuration is changeable in hot operation.

See REQ engine.runlevel
See TEST org.xmlBlaster.test.client.TestFilePollerPlugin

This page is generated from the requirement XML file xmlBlaster/doc/requirements/client.filepoller.xml

Back to overview