|
Summary: Demonstrates a simple application which uses a Space Based Architecture (SBA), to process a workflow.
Workflow ExampleThis example demonstrates a simple application which uses a Space Based Architecture (SBA), to process a workflow. The workflow is determined by setting states in an Entry. The workflow itself is based on an enumerated Java class, with states of NEW, OPEN, PENDING and CLOSED. Generic worker instances are configured to process Entry types that match a specific template corresponding to a workflow state. This document is organized as follows: This example will provide an introduction to the semantics possible with a SBA, and can be extended as needed. Example OverviewThe example described in this section can be found in the <GigaSpaces ROOT>\ServiceGrid\examples\workflow folder. The Workflow example architecture is depicted below: +--------+ +-----------+ | |-- writes --> | | +--------+ | | OrderWorkFlow.NEW | | -- take OrderWorkFlow.NEW --> | New | | | | | <-- write OrderWorkFlow.PENDING -- | Worker | | | | | +--------+ | | | | +--------+ | Master | | GigaSpace | -- take OrderWorkFlow.PENDING --> | Pending| | | | | <-- write OrderWorkFlow.OPEN -- | Worker | | | | | +--------+ | | | | +--------+ | | | | -- take OrderWorkFlow.OPEN --> | Open | | | | | <-- write OrderWorkFlow.CLOSED -- | Worker | | |<-- takes | | +--------+ | | OrderWorkFlow.CLOSED | | +--------+ +-----------+ The Master is contained in the source file example.OrderMaster, and uses the example.OrderEntry to write and take Entries to or from the space.
New Worker: <Configuration> <Component Name="com.gigaspaces.grid.worker"> <Parameter Name="temmplateClass" Value="new example.OrderEntry(example.OrderWorkFlow.NEW)"/> </Component> </Configuration> Pending Checked Worker: <Configuration> <Component Name="com.gigaspaces.grid.worker"> <Parameter Name="temmplateClass" Value="new example.OrderEntry(example.OrderWorkFlow.PENDING)"/> </Component> </Configuration> Each worker additionally has an association to the gigaspaces.xml deployment descriptor that is obtained from the global Association declaration. Example Source FilesSource code is located in the <product-install-root>/ServiceGrid/examples/workflow directory.
Building the ExampleBuilding the example is straight forward, you must have Ant and JDK 1.5. If these requirements are met, do the following: $ cd <product-install-root>/ServiceGrid/examples/workflow $ ant
Running the Example
How to run the example:
Custom WorkerYou might want to build a custom worker that consumes the tasks and executes these.
Custom Worker - Worker Codepackage example; import net.jini.space.*; import com.j_spaces.core.*; public class MyOrderWorkFlow { static IJSpace space = null; public MyOrderWorkFlow (){} public void setSpace(IJSpace space) { this.space = space; System.out.println("space:" + space.getName()); new Thread (new myWorker()).start(); } public static class myWorker implements Runnable { public void run() { while (true) { try{ System.out.println(" ------ >> Got " + space.count(null ,null) + " entries in the space"); System.out.println(" ------ >> Calling Take...."); OrderEntry order = (OrderEntry)space.take (new OrderEntry() , null , 10000); if (order!= null) { System.out.println("Got" + order); space.write(order.execute(null), null , 10000); } } catch (Exception e) { e.printStackTrace(); } } } } } Custom Worker - Deployment Descriptor<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?> <!DOCTYPE gs-deployment SYSTEM "java://gs-deploy-desc.dtd" > <gs-deployment Name="Workflow Example"> <!-- Declare global attributes for the Deployment Descriptor --> <Codebase Adaptive="yes">$[com.gigaspaces.system.codeserver]</Codebase> <Groups> <Group>${com.gs.jini_lus.groups}</Group> </Groups> <!-- Parameters that are applicable for all workers --> <Parameters> <Parameter Name="useWeakHashMap" Value="no"/> <Parameter Name="useTransactions" Value="no"/> <Parameter Name="timeout" Value="5000"/> </Parameters> <Association Type="requires" Name="GigaSpace" refid="space.desc"/> <ServiceBean Name="MyWorker"> <Interfaces> <Interface>org.jini.rio.resources.servicecore.Service</Interface> <Resources> <JAR>gs-dl.jar</JAR> </Resources> </Interfaces> <ImplementationClass>example.MyOrderWorkFlow <Resources> <SharedComponent> <ClassName>example.OrderEntry</ClassName> <JAR>examples/workflow/lib/workflow.jar</JAR> </SharedComponent> </Resources> </ImplementationClass> <Association Type="requires" Property="space" Name="GigaSpace" refid="space.desc"/> <Maintain>1</Maintain> </ServiceBean> <Include id="space.desc"> ${com.gigaspaces.grid.home}config/deployment/gigaspace.xml</Include> </gs-deployment> |
Wiki Content Tree
Your Feedback Needed!
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.






Add Comment