Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Component or Bean ID

Description

filePoller

This component periodically checks the "inbox" directory looking for files. If there is a file or directory present, it adds the file to the "workingSet", which is a collection of files to be processed. The workManger is invoked to schedule the work of processing the file from the workingSet. Another thread is created and the processing of the file begins. Processing consists of marshalling the file (streaming it from disk into a normalized message). The normalized message is sent over the Normalized Message Router (NMR) to the fileSender component per the specified "destinationService" which is specified in the servicmix.xml file in the filePoller component. In this case the "destinationService" is the fileSender component. Finally, after it has been processed, the filePoller deletes the file from the source directory.

fileSender

This component is the "destinationService" for the filePoller. It receives normalized messages from filePoller. The messages it receives are the files that filePoller has transferred to it via the NMR. It converts the normalized message to its original file format and sends it to the destination directory, in this case the outbox directory. This component creates the filename to copy the file to by concatenating the string "sample_" with the process id following by ".xml". The concatenated string is passed to the org.servicemix.expression.JaxenStringXPathExpression bean as an argument to the constructor, as can be seen by the constructor-arg value tag in the XML file. Therefore, the source file name from the inbox directory is not the destination file name in the outbox directory.

workManager

This bean is used by the filePoller to increase the throughput of the application. The workManager is a thread pool whose size can be adjusted declaratively in the servicemix.xml file. Threads are used by this application to do the work of processing files.

Some Java Code Hints

FILE POLLER DETAILS

1. Servicemix container reads servicemix.xml file and sees it needs to install
2. l a filePoller
3. container calls init method of filePoller as well as init methods of its parents
4. container determines that filePoller is an MBean and therefore calls its "start" method of filePoller, which it inherits from its parent PollingComponentSupport
5. Analyzing the start method, the start method will
a. Create a timerTask, which overrides the "run()" method inline, the run() method will eventually get the WorkManager and schedule work
b. Start method uses the "timer" (created in the init method) to schedule the timerTask it just created at a fixed rate, timer.scheduleAtFixedRate(timerTask, firstTime, period)
c. Timer will call the run method of the timerTask periodically
d. timerTask's run method is defined inline.
e. it will get the workManager object (see below for details)
f. the work manager will call scheduleWork(PollingComponentSupport.this). note: it passes in PollingComponent support, which by virtual of its inheritance hierarchy, is also of type "Work", which is also a "runnable"
g. WorkManager.scheduleWork(Work) will likely create or get a Thread, passing in a runnable, i.e. PollingComponentSupport, and call its "run" method
h. PollingComponent's run method calls poll(), which is implemented in filePoller
i. From this point on the call sequence can be followed in filePoller
6. The start method of PollingComponentSupport, will eventually call super.start(), which propagates up to call the start method of BaseLifeCycle, which sets the component state to RUNNING

WORK MANAGER DETAILS

Work manager is used in two ways:

When the application is run, it has an inbox and outbox. Each instance of the application may move files between different source and destination directories, i.e. a different inbox and outbox as specified in its own servicemix.xml file.

Each The work manager will allocate a thread for each instance of the application.

The work manager will also allocate a thread to process one file (read, normalize and send to NMR). The work manager calls a scheduleWork method with is non-blocking. Therefore, if multiple files need to be processes, filePoller can continue making request to the work manager to schedule work.

1. The Timer object schedules a TimerTask

which was defined in the servicemix.xml and "given" to the filePoller.

Workmanager is a property of the filePoller object. This property is actually given a local reference to a bean, which is defined in the same xml file (the workmanager is an org.activemq.work.springworkmanager type

The spring workmanager is a spring bean, which by default, when a spring bean starts the properties are set, which are defined in the service.xml file. A method called "afterpropertiesset" is called by the container

Related Documentation

For more information on the following topics please see:

...