Versions Compared

Key

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

...

Viewing the Java source code is recommended for understanding the information in this section.

filePoller Details

  1. The ServiceMix container reads the servicemix.xml file and instantiates the components specified through SpringJBIContainer.
  2. SpringJBIContainer registers the components and the activationSpecs in its afterPropertiesSet method. In this case, httpReceiver and stockQuote are registered as activationSpecs.
  3. SpringJBIContainer uses ActivationSpec class as the container for component specific properties such as routing information.

Some of its methods are:
setId - takes the spring:id=jbi and sets the id of the container
to "jbi"

setcomponentName = sets componentName to httpReceiver
on one invocation and "stockQuote" when the other
component is instantiated.

setEndpoint - sets the endpoint properties from the
servicemix.xml file

setService - sets the service properties from xml file setDestinationService = sets the destinationService for
each component

  1. The container determines that FilePoller is an MBean and, therefore, calls the start() method of FilePoller, which it inherits from its parent PollingComponentSupport.
  2. 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 the servicemix.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
titlePollingComponentSupport.java
borderStylesolid

  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:

...

HttpConnector Details
stockQuote Details

Related Documentation

For more information on the following topics please see:

...