...
- use of declarative programming
- how to interact with the file system
- how to use a WorkManager thread pool
The source code for the File Binding example is located in the ServiceMix installation directory under the examples\file-binding
directory in the servicemix.xml
file. It is recommended that you refer to the source code while reading this document.
...
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 |
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 |
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 |
...
Useful Code Hints
...
This section describes some interesting aspects of how the ServiceMix JBI container interacts with the File Binding application.
- filePoller 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
...