Jump to: navigation, search

Difference between revisions of "SMILA/Documentation/HowTo/How to write a Pipelet"

(General review on content and style)
(Add link to main integration page)
Line 1: Line 1:
This page describes how to implement and configure your own [[SMILA/Glossary#P|pipelet]] in case you wish to add functionality to SMILA.
+
This page describes how to implement and configure your own [[SMILA/Glossary#P|pipelet]] in case you wish to [[SMILA/Howto_integrate_a_component_in_SMILA|add functionality]] to SMILA.
  
 
== What are pipelets? ==
 
== What are pipelets? ==

Revision as of 13:00, 29 September 2008

This page describes how to implement and configure your own pipelet in case you wish to add functionality to SMILA.

What are pipelets?

Pipelets are not standalone services, but their lifecycle and configuration is managed by the workflow engine. In contrast to processing services they are not shared by multiple workflows, that is, each occurrence of a pipelet in a workflow uses a different pipelet instance.

Implementation

Follow these instructions to implement a pipelet in SMILA:

  • Create a class that implements the interface org.eclipse.smila.processing.SimplePipelet and make sure that the class has a public no-argument constructor.
  • Implement void configure(PipeletConfiguration configuration). This method is called prior to process. Here you can read the PipeletConfiguration provided for the pipelet in the pipeline. To share those properties either store the whole PipeletConfiguration in a member variable or better check the PipeletConfiguration for validity and completeness and store the settings in separate member variables.
  • Implement Id[] process(BlackboardService blackboard, Id[] recordIds). Here you have to place the "business logic" of your pipelet. In most cases the result is the same as the input recordIDs, so just return it. But it is possible to return another list of IDs as result.
  • Register your class in META-INF/MANIFEST.MF of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the SimplePipeletTracker service. If you would like to register multiple classes, separate them with commas.
  • Consider thread-safeness. As pipelets may be accessed by multiple threads make sure that the access to the member variables (e.g. the configuration) is read-only. For best practices use local variables instead of member variables if possible.

Configuration

This step is optional if your pipelet does not need a configuration.

  • Add a <PipeletConfiguration> to the <extensionActivity> of your pipelet in the BPEL pipeline.

Example

This is a template for MyPipelet.java:

package org.eclipse.smila.mypackage

import org.eclipse.smila.blackboard.BlackboardService;
import org.eclipse.smila.datamodel.id.Id;
import org.eclipse.smila.processing.ProcessingException;
import org.eclipse.smila.processing.SimplePipelet;
import org.eclipse.smila.processing.configuration.PipeletConfiguration;
 
public class MyPipelet implements SimplePipelet {
 
  public MyPipelet(){
  }
 
  public void configure(PipeletConfiguration configuration) throws ProcessingException {
    // read the configuration properties
  }
 
  public Id[] process(BlackboardService blackboard, Id[] recordIds) throws ProcessingException {
    // process the recordIds and create a result
  }
}

And this is how to register the pipelet class in the bundle's manifest MANIFEST.MF:

...
SMILA-Pipelets: org.eclipse.smila.mypackage.MyPipelet
...

And finally, this is a sample showing how a pipelet is invoked in the BPEL pipeline using an <extensionActivity>. It also shows how the pipelet is configured using a <PipeletConfiguration>.

...
<extensionActivity name="invokeMyPipelet">
    <proc:invokePipelet>
        <proc:pipelet class="org.eclipse.smila.mypackage.MyPipelet" />
        <proc:variables input="request" output="result" />
        <proc:PipeletConfiguration>
            <proc:Property name="aStringParam">
                <proc:Value>some value</proc:Value>
            </proc:Property>
            <proc:Property name="aDateParam" type="java.util.Date">
                <proc:Value>2008-06-11 16:08:00</proc:Value>
            </proc:Property>
        </proc:PipeletConfiguration>       
    </proc:invokePipelet>
</extensionActivity>
...