Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

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

m (Implementation)
m (Implementation)
Line 14: Line 14:
 
* Register your class in <tt>META-INF/MANIFEST.MF</tt> of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the <tt>SimplePipeletTracker</tt> service. If you would like to register multiple classes, separate them with commas.
 
* Register your class in <tt>META-INF/MANIFEST.MF</tt> of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the <tt>SimplePipeletTracker</tt> service. If you would like to register multiple classes, separate them with commas.
  
* Consider thread-safeness. Because pipelets may be accessed by multiple threads, make sure that access to member variables (e.g. the configuration) is read-only. For best practices: use local variables instead of member variables if possible.
+
* Consider thread-safe-ness. Because pipelets may be accessed by multiple threads, make sure that access to member variables (e.g. the configuration) is read-only. For best practices: use local variables instead of member variables if possible.
  
 
== Configuration ==
 
== Configuration ==

Revision as of 16:09, 19 September 2009

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. For more information take a look at Pipelets and ProcessingServices.

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(Blackboard 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-safe-ness. Because pipelets may be accessed by multiple threads, make sure that access to member variables (e.g. the configuration) is read-only. For best practices: use local variables instead of member variables if possible.

Configuration

If your pipelet requires a configuration:

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

Examples

Simple Piplet Usage

This is a template for MyPipelet.java:

package org.eclipse.smila.mypackage

import org.eclipse.smila.blackboard.Blackboard;
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(Blackboard 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>
...

PipletConfiguration Usage

The following example shows the usage of multiple values for properties:

...
 
 
		<extensionActivity name="setRootAnnotations">
			<proc:invokePipelet>
				<proc:pipelet class="org.eclipse.smila.processing.pipelets.SetAnnotationPipelet" />
				<proc:variables input="request" />
				<proc:PipeletConfiguration>
					<proc:Property name="Name">
						<proc:Value>annotation</proc:Value>
					</proc:Property>
					<proc:Property name="AnonValue" type="java.lang.String">
						<proc:Value>anonvalue1</proc:Value>
						<proc:Value>anonvalue2</proc:Value>
					</proc:Property>
					<proc:Property name="NamedValue:name1" type="java.lang.Integer">
						<proc:Value>1</proc:Value>
					</proc:Property>
					<proc:Property name="NamedValue:name2" type="java.lang.Integer">
						<proc:Value>2</proc:Value>
					</proc:Property>
				</proc:PipeletConfiguration>
			</proc:invokePipelet>
		</extensionActivity>
 
...
...
  public void configure(PipeletConfiguration configuration) throws ProcessingException {
    final List<Property> properties = configuration.getProperties();
    for (Property property : properties) {
      final String name = property.getName();
      if (new String("AnonValue").equals(name)) {
        final List<Object> list = property.getValues();
        for (Object value : list) {
          final String stringValue = (String) value;
          ... use this Value ...
      }
...

Back to the top