Skip to Main Content U.S. Department of Energy
 

MIF Hello Ingester

The following describes:

  • An overview of the helloIngester sample included with MIF.
  • How to run the helloIngester sample.
  • A walkthrough of the code used to construct this sample.

Prerequisites

Please refer to the getting started page and the installation page to prepare to use the following sample.

Also, if you would like to use this example outside of Eclipse, please refer to the development environment page.

Overview of helloIngester

All basic definitions in this overview should have been covered in the previous examples.

The helloIngester sample demonstrates our ingester processor which in essence intakes one message (usually containing parameters) and reroutes it as a stream of data to the next component in the pipeline. During the acceptance of the paramters, there may or may not be a call to an external file from the ingester module. The HelloHalProcessor, described in the hello world example, then appends its string to the end of the data. The pipeline completes when there are no more messages to be sent by the HelloIngesterProcessor to the HelloHallProcessor, in which case a “No more data. Returning null.” message is outputted to the console.

Hello Ingester

Running helloIngester

Note:$MIF_HOME refers to the home directory where MIF was installed.

  • Open a shell and navigate to $MIF_HOME
  • From there, run:
bin\run-mif.bat -c gov.pnnl.mif.samples.hello.ingester.HelloIngesterDriver
  • MIF will have started when you receive the message:
MIF has started
  • The console will then ask you to:
Hit enter to start.
  • After hitting enter, the resulting display should be something similar to what follows:
2009-08-28 15:30:28,560 INFO  [HelloIngesterProcessor] getNextMessage -- ed
2009-08-28 15:30:28,576 INFO  [VMMessageDispatcher] Connected: endpoint.outbound.vm://queue-1
HelloHalProcessor: ed, what are you doing?
2009-08-28 15:30:28,607 INFO  [HelloIngesterProcessor] getNextMessage -- joe
2009-08-28 15:30:28,607 INFO  [VMMessageDispatcher] Connected: endpoint.outbound.vm://queue-1
HelloHalProcessor: joe, what are you doing?
2009-08-28 15:30:28,607 INFO  [HelloIngesterProcessor] getNextMessage -- hal
2009-08-28 15:30:28,607 INFO  [VMMessageDispatcher] Connected: endpoint.outbound.vm://queue-1
HelloHalProcessor: hal, what are you doing?
2009-08-28 15:30:28,622 INFO  [StdioMessageDispatcher] Connected: endpoint.outbound.stdio://stdout
ed, what are you doing?2009-08-28 15:30:28,622 INFO  [HelloIngesterProcessor] getNextMessage -- steve
2009-08-28 15:30:28,622 INFO  [VMMessageDispatcher] Connected: endpoint.outbound.vm://queue-1
HelloHalProcessor: steve, what are you doing?
2009-08-28 15:30:28,622 INFO  [HelloIngesterProcessor] getNextMessage -- mark
2009-08-28 15:30:28,622 INFO  [VMMessageDispatcher] Connected: endpoint.outbound.vm://queue-1
HelloHalProcessor: mark, what are you doing?
2009-08-28 15:30:28,638 INFO  [StdioMessageDispatcher] Connected: endpoint.outbound.stdio://stdout
joe, what are you doing?2009-08-28 15:30:28,638 INFO  [HelloIngesterProcessor] No more data. Returning null.
2009-08-28 15:30:28,638 INFO  [StdioMessageDispatcher] Connected: endpoint.outbound.stdio://stdout
mark, what are you doing?2009-08-28 15:30:28,638 INFO  [StdioMessageDispatcher] Connected: endpoint.outbound.stdio://stdout
steve, what are you doing?2009-08-28 15:30:28,638 INFO  [StdioMessageDispatcher] Connected: endpoint.outbound.stdio://stdout
hal, what are you doing?
  • It will then prompt you to hit enter again, and the result should be:
2009-08-28 15:30:37,497 INFO  [HelloIngesterProcessor] No more data. Returning null.

Subsequent attempts to hit enter will result in the same output.

Creating the helloIngester pipeline

All the source files for this example can be found in $MIF_HOME/sources/mif-samples/src/gov/pnnl/mif/samples/hello/ingester. The following code snippets demonstrate the pertinent portions of the code. The code is presented in a “top-down” manner where we present the higher level code first and move progressively down to the implementation details.

Setting Up the Pipeline (main)

First, we need to create a pipeline which will be responsible for starting and stopping the processing pipelines. The pipeline is also used to create and register all the objects that run within the pipeline.

MifPipeline pipeline = new MifPipeline();

Next, we add the MifIngesterModule, passing it the name of the HelloIngesterProcessor, the input prompt and the endpoint of the MIF module.

pipeline.AddmIfIngesterModule(HelloIngesterProcessor.class.getName(),"stdio://stdin?promptMessage=Hit enter to start.", "vm://queue-1");

We then add a MifModule to the pipeline.

pipeline.addMifModule(HelloHalProcessor.class.getname(), "vm://queue-1", "stdio://stdout");

Finally, start the pipeline.

pipeline.start();

HelloIngesterProcessor

The HelloIngesterProcessor class implements the MifIngesterProcessor interface, which necessitates the usage of the getNextMessage method which returns a serializable object.

public class HelloIngesterProcessor implements MifINgesterProcessor {
 
public Serializable getNextMessage(Serializable pipelineData) {
  String msg;
 
  //while there is more data to ingest, return the next message
  if (counter < testNames.length) {
    msg = testNames[counter++];
    log.info("getNextMessage -- " + msg);
  }
 
  //when the data runs out, return a NULL to mark that hte data is done being ingested
  else {
    msg = null;
    log.info("No more data. Returning null.")
  }
 return msg;
 }
}

The code shows that the getNextMessage method will record the data stored in testNames[counter++] to the msg variable, which is forwarded to the HelloHalProcessor. The HelloHalProcessor then runs its process with each new msg variable until it returns null.

 
hello_ingester.txt · Last modified: 2009/09/03 16:20 by d3x072