Skip to Main Content U.S. Department of Energy

Hello World in the MIF Component Builder

This example will consist of a single MIF component containing two MIF modules. The first module will receive data from standard input, echo the received input, and concatenate it with another string before passing it on to the next module, which concatenates another string onto it and outputs the resulting string to the console.

Note that all screen shots and other images in this document have been reduced in size to save space. They all may be enlarged to actual size by clicking them.


Before using the component builder you must:

Create and Run the Hello World Project

Create a new project

First, Create a MIF Project in Eclipse and name it “hello-component-builder.” Then create a new MIF Diagram file and place it in the config directory by following these steps:

  • Right click on the config directory and choose New → Other. This brings up the “Select a wizard” dialog box.
  • Enter “mif” into the filter field, select “MIF3 Diagram,” as pictured below, and then click the “Next” button

Creating a MIF3 Diagram File

  • This brings up the “New MIF3 Diagram” dialog. Confirm that the project's config directory is selected as the parent folder and change the file name to “hello.mifd.” Make sure the dialog looks like the following, then click “Next.”

Configuring a MIF3 Diagram File

  • This brings up a dialog to name the MIF model file. Make sure is has the name “hello.mif.” Then click “Finish.”

Note on model files: The above steps create 2 model files and places them in the config directory. The reason for the two separate files is that the .mif file will contain the serialized XMI model of the MIF pipeline from the diagram, while the .mifd file will contain XML which describes where the entities specified in the MIF model are placed on the canvas. After completing the steps above, the resulting empty project should look like the following:

Blank MIF3 Diagram

Note the properties window at the bottom of the tool. If the properties window does is not visible by default, open it by choosing it from the menu:

Window -> Other -> General -> Properties

Create the MIF component

Create the first component by clicking the “MifComponent” object under the Components section. Then click in the canvas where you want to place the object. Ensure that the component you just created is selected and take note of the properties that can be set on a component. In the case of components, most of the settable properties represent meta-data about how and when the component was created. For now, modify the name property to read “helloCbComponent.” When you have done this, your screen should look similar to the following:

Creating the helloCbComponent

Create the first module

To demonstrate the round-trip development capabilities of the CB, we will create one module, then generate stub code, and run the code before creating the second module.

To create the first module, select MifModule from the Palette and place it inside the component. If necessary, note that you can resize the component and other objects by selecting them, then dragging the edges. For the Name property enter “nameModule” and for the “implementationClass” property enter:


The implementation class is the stub that will be created when we generate code for the pipeline.

Next, add a MifInboundEndpoint to the module by selecting this object in the Palette and then clicking the nameModule to place it there. Select the MifInboundEndpoint and edit the URI property to read:


This means that this module will be “listening” for text to be entered on standard input. Now, save the diagram and confirm that it looks similar to the following image:

helloCbComponent with one module

Generate stub code for the first module

To generate the stub code, right click on the model file (hello.mif) and select from the menu:

Mif Tasks -> Generate MIF Stubs

Check the console to ensure that there were no errors in the code generation. The output in the console should similar to the following:

2010-09-25 15:58:03,802 INFO  [ProgrammaticStubGen] Begin code generation
INFO [Stub Generation] Working on stub for Driver: org.example.MifDriver
INFO [Stub Generation] Working on stub for org.example.NameProcessor
2010-09-25 15:58:04,274 INFO  [ProgrammaticStubGen] ---------------------------
2010-09-25 15:58:04,274 INFO  [ProgrammaticStubGen] Code generation succeeded!!
2010-09-25 15:58:04,274 INFO  [ProgrammaticStubGen] ---------------------------

Now, look at the Package Explorer window and expand the “src-gen” directory. You should see a new package (org.example) in addition to two new class files:

  • the driver class used to test the pipeline
  • NameProcessor: the stub that implements the nameModule we created in the diagram

The package explorer should now look similar to the following image:

Now, open the source file and note that it implements the MifObjectProcessor interface including some default implementation for the listen() method. Change this method to have the following contents:

public class NameProcessor implements MifObjectProcessor {
	public Object listen(Object input) {
		String newStr = "Hello, " + ((String)input) + ".  ";
		System.out.println(getClass().getName() + newStr);
		return newStr;

Next, change one line in the source file so that it specifies the correct pipeline model file. Change the value of the DEFAULT_MODEL as specified below:

public static final String DEFAULT_MODEL = "hello.mif";

Start the pipeline

The pipeline can now be started by running the MifDriver class just as one would for any other Java class. I.e., by selecting the file and choosing:

Run -> Run as -> Java Application

This should produce console output that starts the pipeline, pauses for 2 seconds, then prompts you to “Enter Something,” at which time you should enter a name and press return. The full console output will look like:

2010-09-25 16:21:31,462 INFO  [MifManagerImpl]  -- MIF has started --

Enter something:Dave
org.example.NameProcessor  Hello, Dave. 

Create the Second Module

Now that we have successfully tested the first module, we can move on to creating the second module by following these steps:

  • Add a MifOutboundEndpoint to nameModule and set the uri property to: “vm://hal”
  • Add a second module as described above and name it “halModule.”
  • Set the implementationClass property to “org.example.HalProcessor”
  • Add a MifInboundEndpoint to the new module and set the uri property to: “vm://hal”
  • Connect the outbound endpoint on nameModule to the inbound endpoint on halModule by clicking the EndpointLink object in the Palette, then clicking the outbound endpoint and dragging it over to the inbound endpoint.
  • Finally, add an OutboundEndpoint to halModule and set the uri to: “stdio://out”

The MIF diagram should now look similar to the following screen shot:

Full Hello CB Pipeline

Generate code for the second module

Next, generate stub code for the halModule as described for the nameModule, above. Note that any changes made to files in the src-gen directory will not be overwritten. So, after generating code for the second time, you should notice that a new class file called was created. The Package Explorer should look similar to the following:

Package explorer after 2nd code generation

Modify Stub Code and Run Pipeline

Modify the stub code in to something witty and brilliant, for example:

package org.example;
import gov.pnnl.mif.user.MifObjectProcessor;
public class halProcessor implements MifObjectProcessor {
	public Object listen(Object input) {
		String newStr = "What are you doing, " + (String)input + "?";
		System.out.println(getClass().getName() + "  " + newStr);
		return newStr;

Finally, run the MifDriver class again and watch for console output similar to the following:

2010-09-25 16:57:24,107 INFO  [MifManagerImpl]  -- MIF has started --

Enter something:Dave
org.example.NameProcessor  Hello, Dave.  
org.example.halProcessor  What are you doing, Dave?
What are you doing, Dave?
hello_world_in_component_builder.txt · Last modified: 2010/09/25 16:57 by adamw