Creating Custom Process Starters

TIBCO BW has a vast quantity of process starters that allow you to comunicate with the main protocols you should use to get your integrations done, but some times may not be enough. When the process starters and TIBCO adapters not fit for your requirements of the budget of your project is not enought to afford these extensions, so you can implement your custom starters.

You can create your custom starters with a little Java Programming and using as a process starter the ‘Java Event Source’ activity. As you can read in the official TIBCO BW documentation:

“The Java Event Source resource provides an abstract class that you must extend to create a process starter. The abstract class describes the methods that interact with the process engine. Your code must provide an implementation for the following methods:

  • init() — this method is called when the process engine starts. This method can initialize any resource connections. Alternatively, you could specify a Java Global Instance on the Advanced tab that initializes resource connections. Java Global Instances are loaded and initalized during process engine start up. You can call this.getJavaGlobalInstance() to obtain the Java Global Instance resource in your process starter code.
  • onStart() — this method is called by the process engine to activate the process starter. This method must activate any event notifier or resource observer code. The notifier or observer code can then call the onEvent() method to start a process instance.
  • onStop() — this method is called by the process engine to deactivate the process starter. This method must deactivate any event notifier or resource observer code.
  • onShutdown() — this method is called by the process engine when the engine shuts down. This method should release any resources and resource connections and perform any required clean up operations.”

Using the TIBCO Designer you can to provide the code to complete this class inside your Process Definition. Now, we show a tiny example of a custom process starter:

package TEST1;
import java.util.*;
import java.io.*;
import com.tibco.plugin.java.JavaProcessStarter;
/**
* This class allows users to write custom process starters using the java programming
* language. It extends JavaProcessStarter abstract class that interfaces with the ActiveMatrix Business
* works engine. JavaProcessStarter class defines following four abstract methods:
* 1) init() – Allows users to initialize their resources.
* 2) onStart() – Allows users to activate their listeners or Observers or kick off a process
* by calling onEvent(object inputData).
* 3) onStop() – Allows user to de-activate their listeners or Observers.
* 4) onShutdown() – Allows users to release the resources. This method is somewhat similar to finalize()
*
* JavaProcessStarter also defines three non-abstract methods:
* 1) getGlobalInstance() – It returns an instance of Java Global Instance defined in the advanced tab.
* 2) onEvent(Object object) – It is the main entry point into the ActiveMartix Business Works engine. This
method must be called in onStart() or in the listener or observer interface
* to trigger the process.
* 3) onError(Throwable throwable) – It allows the user to throw an exception if the listener or observer fails
* to generate an notification event.
*/
public class TEST1JavaEventSource extends JavaProcessStarter {
public TEST1JavaEventSource() {

}

/**
* Initializes the Java Event Source component during ActiveMatrix Business Works engine
* start-up. It is highly recommended to initialize resource connections
* in this method. Resource connections can also be defined as Java Global Instance.
* To configure Java Global Instance use the advanced tab. It is a common practice to
* define resource connection as Java Global Instance. Users can get a handle to the Java
* Global Instance by calling this.getJavaGlobalInstance().
*/
public void init() throws Exception {
}
/**
* This method is called by ActiveMatrix Business Works engine to activate the Java Event Source. This is
* an ideal place for users to add notifier or resource observer. The notifier/observer
* can then call onEvent(Object inputData) method to kick off a process instance.
*/
public void onStart() throws Exception {
Test1 t1 = new Test1(this);
Thread t = new Thread(t1);
t.start();
}
/** This method is called by ActiveMatrix Business Works engine to de-activate the Event Source. User can
* add code to de-activate a notifier or resource observer.
*/
public void onStop() throws Exception {
}
/** This method is called at ActiveMatrix Business Works engine shutdown. User can add cleanup code in
* this method
*/
public void onShutdown() {
}

public static class Test1 implements Runnable {

private JavaProcessStarter javaProcessStarter;

public Test1(JavaProcessStarter javaProcessStarter) {
this.javaProcessStarter = javaProcessStarter;
}

public void run() {
try{
for(int i=0;i<10;i++){
HashMap<String,String> hash = new HashMap<String,String>();
javaProcessStarter.onEvent(hash);
}
}catch(Exception ex){

}
}
}
}

The output of the custom process starter is a Java Bean Object so you must to convert it to XML so you can use the fields of the object in the regular activities. You can also use the ‘Convert Java Object to XML’ option in the Advanced tab of the custom started activity.

 

TIP/HINT!

You must be aware if you check or uncheck the ‘Convert Output Object to XML’  because it will append another full Java class  code to the existent one, so you must clean up the code in the Code tab.

I hope you can use these information in your new developments! See you in the next post!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s