Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "SMILA/Documentation/HowTo/How to write a Pipelet"
< SMILA | Documentation | HowTo
m |
|||
Line 5: | Line 5: | ||
== Implementation == | == Implementation == | ||
− | * Create a class that implements interface <tt>org.eclipse. | + | * Create a class that implements interface <tt>org.eclipse.smila.processing.SimplePipelet</tt>. |
* The class must have a public no-argument constructor. | * The class must have a public no-argument constructor. | ||
Line 13: | Line 13: | ||
* Implement <tt>Id[] process(BlackboardService blackboard, Id[] 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. | * Implement <tt>Id[] process(BlackboardService blackboard, Id[] 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. | ||
− | * The class name must be registered in META-INF/MANIFEST.MF of the providing bundle using the header name "* | + | * The class name must be registered in META-INF/MANIFEST.MF of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the SimplePipeletTracker service. Multiple classes can be registered separeted by comma. |
* Thread-safe: as Pipelets may be accessed by multiple threads make sure that access to member variables (e.g. the configuration) is read only. | * Thread-safe: as Pipelets may be accessed by multiple threads make sure that access to member variables (e.g. the configuration) is read only. | ||
Line 32: | Line 32: | ||
<source lang="java"> | <source lang="java"> | ||
− | package org.eclipse. | + | package org.eclipse.smila.mypackage |
− | import org.eclipse. | + | import org.eclipse.smila.blackboard.BlackboardService; |
− | import org.eclipse. | + | import org.eclipse.smila.datamodel.id.Id; |
− | import org.eclipse. | + | import org.eclipse.smila.processing.ProcessingException; |
− | import org.eclipse. | + | import org.eclipse.smila.processing.SimplePipelet; |
− | import org.eclipse. | + | import org.eclipse.smila.processing.configuration.PipeletConfiguration; |
public class MyPipelet implements SimplePipelet { | public class MyPipelet implements SimplePipelet { | ||
Line 59: | Line 59: | ||
<pre> | <pre> | ||
... | ... | ||
− | + | SMILA-Pipelets: org.eclipse.smila.mypackage.MyPipelet | |
... | ... | ||
</pre> | </pre> | ||
Line 70: | Line 70: | ||
<extensionActivity name="invokeMyPipelet"> | <extensionActivity name="invokeMyPipelet"> | ||
<proc:invokePipelet> | <proc:invokePipelet> | ||
− | <proc:pipelet class="org.eclipse. | + | <proc:pipelet class="org.eclipse.smila.mypackage.MyPipelet" /> |
<proc:variables input="request" output="result" /> | <proc:variables input="request" output="result" /> | ||
<proc:PipeletConfiguration> | <proc:PipeletConfiguration> |
Revision as of 05:38, 26 September 2008
What are Pipelets
Pipelets are not standalone services, but their lifecycle and configuration is managed by the workflow engine. They are not shared by multiple workflows, each occurrence of a pipelet in a workflow uses a different pipelet instance.
Implementation
- Create a class that implements interface org.eclipse.smila.processing.SimplePipelet.
- The class must have 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 completness and store the settings in seperate memeber 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.
- The class name must be registered in META-INF/MANIFEST.MF of the providing bundle using the header name "*SMILA-Pipelets*". Then they can be detected by the SimplePipeletTracker service. Multiple classes can be registered separeted by comma.
- Thread-safe: as Pipelets may be accessed by multiple threads make sure that access to member variables (e.g. the configuration) is read only.
- Best Practice: use local variables instead of memeber 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 manifest MANIFEST.MF:
... SMILA-Pipelets: org.eclipse.smila.mypackage.MyPipelet ...
This is a sample how a Pipelet is invoked in a 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> ...