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/2011.Simplification/How to write a Pipelet"

(Pipelet Usage)
(For SMILA 1.0: Simplification pages are obsolete, redirect to SMILA/Development_Guidelines/How_to_write_a_Pipelet)
 
Line 1: Line 1:
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.
+
#REDIRECT [[SMILA/Development_Guidelines/How_to_write_a_Pipelet]]
 
+
== What are pipelets? ==
+
Pipelets are not standalone services, but their lifecycle and configuration is managed by the workflow engine. Each occurrence of a pipelet in a workflow uses a different pipelet instance. For more information  take a look at [[SMILA/Documentation/Pipelets|Pipelets]].
+
 
+
'''Before writing your own pipelet we recommend you to take a look at the''' [http://dev.eclipse.org/svnroot/rt/org.eclipse.smila/trunk/org.eclipse.smila.integration.helloworld/ HelloWorldPipelet]. This pipelet is an example of a very simple processing pipelet and can be used as a template for your pipelets.
+
 
+
== Implementation ==
+
Follow these instructions to implement a pipelet in SMILA:
+
* Create a class that implements the interface <tt>org.eclipse.smila.processing.Pipelet</tt> and make sure that the class has a public no-argument constructor.
+
 
+
* Implement <tt>void configure(AnyMap configuration)</tt>. This method is called prior to process. Here you can read the configuration provided for the pipelet in the [[SMILA/Glossary#P|pipeline]]. To share those properties either store the whole configuration in a member variable or better check the configuration for validity and completeness and store the settings in separate member variables.
+
 
+
* Implement <tt>String[] process(Blackboard blackboard, String[] recordIds)</tt>. 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 <tt>META-INF/MANIFEST.MF</tt> of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the <tt>PipeletTracker</tt> 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 <tt>&lt;configuration&gt;</tt> element to the <tt>&lt;extensionActivity&gt;</tt> section of your pipelet in the BPEL pipeline.
+
 
+
== Examples ==
+
=== Pipelet Usage ===
+
This is a template for <tt>MyPipelet.java</tt>:
+
 
+
<source lang="java">
+
package org.eclipse.smila.mypackage
+
 
+
import org.eclipse.smila.blackboard.Blackboard;
+
import org.eclipse.smila.processing.ProcessingException;
+
import org.eclipse.smila.processing.Pipelet;
+
import org.eclipse.smila.processing.configuration.PipeletConfiguration;
+
 
+
public class MyPipelet implements Pipelet {
+
 
+
  public MyPipelet() {
+
  }
+
 
+
  public void configure(AnyMap configuration) throws ProcessingException {
+
    // read the configuration properties
+
  }
+
 
+
  public String[] process(Blackboard blackboard, String[] recordIds) throws ProcessingException {
+
    // process the records and create a result
+
  }
+
}
+
</source>
+
 
+
And this is how to register the pipelet class in the bundle's manifest <tt>MANIFEST.MF</tt>:
+
 
+
<pre>
+
...
+
SMILA-Pipelets: org.eclipse.smila.mypackage.MyPipelet
+
...
+
</pre>
+
 
+
And finally, this is a sample showing how a pipelet is invoked in the BPEL pipeline using an <tt>&lt;extensionActivity&gt;</tt>. It also shows how the pipelet is configured using a <tt>&lt;configuration&gt;</tt>.
+
 
+
<source lang="xml">
+
...
+
<extensionActivity name="invokeMyPipelet">
+
    <proc:invokePipelet>
+
        <proc:pipelet class="org.eclipse.smila.mypackage.MyPipelet" />
+
        <proc:variables input="request" output="result" />
+
        <proc:configuration>
+
            <rec:Val name="aStringParam">some value</rec:Val>
+
            <rec:Val name="aDateParam" type="datetime">2008-06-11 16:08:00</rec:Val>
+
        </proc:configuration>     
+
    </proc:invokePipelet>
+
</extensionActivity>
+
...
+
</source>
+
 
+
=== Piplet configuration usage ===
+
 
+
The following example shows the usage of multiple values for properties:
+
 
+
<source lang="xml">
+
...
+
<extensionActivity>
+
  <proc:invokePipelet name="addValuesToNonExistingAttribute">
+
    <proc:pipelet class="org.eclipse.smila.processing.pipelets.AddValuesPipelet" />
+
    <proc:variables input="request" />
+
    <proc:configuration>
+
      <rec:Val key="outputAttribute">out</rec:Val>
+
      <rec:Seq key="valuesToAdd">
+
        <rec:Val>value1</rec:Val>
+
        <rec:Val>value2</rec:Val>
+
      </rec:Seq>
+
    </proc:configuration>
+
  </proc:invokePipelet>
+
</extensionActivity>
+
...
+
</source>
+
 
+
<source lang="java">
+
  public void configure(final AnyMap configuration) throws ProcessingException {
+
    _outputAttribute = configuration.getStringValue(PARAM_ATTRIBUTE);
+
    _values = configuration.get(PARAM_VALUES);
+
  }
+
 
+
  public String[] process(Blackboard blackboard, String[] recordIds) throws ProcessingException {
+
    if (_outputAttribute != null && _values != null) {
+
      try {
+
        for (final String id : recordIds) {
+
          for (final Any value : _values) {
+
            blackboard.getMetadata(id).add(_outputAttribute, value);
+
          }
+
        }
+
      } catch (final Exception ex) {
+
        throw new ProcessingException(ex);
+
      }
+
    }
+
    return recordIds;
+
  }
+
</source>
+
 
+
[[Category:SMILA]]
+

Latest revision as of 06:21, 19 January 2012

Back to the top