...
Component or Bean ID | Description |
---|---|
myComponent | This JMS binding component subscribes to the "demo.org.servicemix.source" topic via its defaultDestinationName |
pxe:ProcessSVC | PXE is a runtime component for executing processes defined by the BPEL4WS 1.1 specification and forthcoming WS-BPEL 2.0 OASIS standard. PXE BPEL engine uses JMX to provide management and introspection functionality. Business Process Execution Language (BPEL) defines a notation for specifying business process behavior |
Useful Code Hints
This section describes the start-up sequence and how the ServiceMix container interacts with the BPEL application. The Java class files are located in the servicemix-1.0.1.jar file in the ServiceMix installation directory. To look at the Java source code, unjar and decompile the .class files or download the source code. Please note: the downloadable source code is slightly different than the compiled binary code.
Viewing the Java source code is recommended for understanding the information in this section.
filePoller Details
- The ServiceMix container reads the
servicemix.xml
file and sees it needs to instantiate a FilePoller. - The container calls the init() method of FilePoller, as well as the init() methods of its parents.
- The container determines that FilePoller is an MBean and, therefore, calls the start() method of FilePoller, which it inherits from its parent PollingComponentSupport.
- The start() method will: (See: PollingComponentSupport.java code fragment below)
A. Create a timerTask.
B. Schedule the timerTask at a fixed rate. The start() method uses the "timer" (created in the init method) to schedule the timerTask at a fixed rate: timer.scheduleAtFixedRate(timerTask, firstTime, period). Recall "period" is a property of FilePoller. It was assigned the value of 1000ms by dependency injection from theservicemix.xml
file.
C. timer will call the run() method of the timerTask periodically. timerTask's run method() is defined inline. This run() method will get the workManager object (see below for details).
D. The workManager will call "scheduleWork(PollingComponentSupport.this)". Note: it passes in PollingComponent support, which by virtue of its inheritance hierarchy, is of type "Work", which is a "Runnable" object.
E. "workManager.scheduleWork(Work)" will get a Thread, passing in a Runnable object, i.e. PollingComponentSupport, and call its run() method.
F. PollingComponent's run() method calls poll(), which is implemented in FilePoller.
G. From this point on the call sequence can be followed in FilePoller...
H. 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."
Eventually, one of the threads that is polling (see step G) for a file in the inbox
directory will see a one. It will use workManager's thread pool to get a thread for processing the file. Processing the file consists of streaming it from inbox
, creating a normalized message, and sending the message to the NMR.
Code Block | ||||
---|---|---|---|---|
| ||||
timerTask = new TimerTask() {
public void run() {
try {
getWorkManager().scheduleWork(PollingComponentSupport.this);
}
catch (Throwable e) {
log.error("Failed to schedule work: " + e, e);
}
}
};
if (firstTime != null) {
timer.scheduleAtFixedRate(timerTask, firstTime, period);
}
else {
timer.scheduleAtFixedRate(timerTask, delay, period);
}
}
super.start();
|
workManager Details
workManager is a property of the FilePoller object. This property is defined by a local reference, the "ref" attribute in the servicemix.xml
file. The local reference is a bean which instantiates org.activemq.work.SpringWorkManager.
The SpringWorkManager is a Spring bean. By default when a Spring bean starts, the properties are set, and then the afterPropertiesSet() method is called by the container.
The workManager is used to allocate threads. The FilePoller asks for threads from the workManager for two operations:
- The timerTask uses threads from the thread pool to periodically check the
inbox
directory for files. - The workManager will also allocate a thread to process a file (read, normalize and send to NMR). The workManager calls a scheduleWork() method which is non-blocking. Therefore, if multiple files need to be processed, FilePoller can continue making requests to the workManager to schedule work.
Summarizing, when the ServiceMix container instantiates an MBean it firsts sets the property values if there are any, then calls the init() method of the class and its' parent classes, if applicable. Then it calls the start() method of the class. When a Spring bean starts up, the properties are set and then the afterPropertiesSet() method is called.
...