In this tutorial you will use OpenSpaces to implement a simple Order Management System. The tutorial illustrates how JavaSpaces can be used for parallel processing – execution of business logic by a number of autonomous software instances.

To do this, you will use the master-worker pattern, in which a master creates a set of tasks, puts them in a shared space, and waits for the tasks to be picked up and completed by a number of workers. The main advantages of this pattern are that the master and workers operate independently of each other (saving the need for complex coordination), and that the load is automatically balanced between the workers sharing the tasks.

Using JavaSpaces with OpenSpaces

JavaSpaces is especially suitable for implementing a master-worker pattern: the space can serve as a shared work area for numerous masters and workers, which can work together without knowing each other and without requiring central coordination.

However, plain JavaSpaces, as demonstrated in the previous tutorial, is too limited for a real-world master-worker implementation. OpenSpaces offers a powerful yet simple-to-use framework that overcomes the practical limitations of JavaSpaces.

You will learn how to use OpenSpaces to find the space more easily; and to allow each component to work under a local transaction, without requiring a transaction coordinator.

In this tutorial you will construct your applications as simple OpenSpaces Processing Units, which enable the packaging and deployment of application services. In the next tutorials you will learn how to gain the full benefits of the Processing Unit concept implementing Space-Based Architecture (SBA).

The Processing Unit is configured using Spring with deploy/runtime context extensions, such as bean-level properties. This allows you to use the same Processing Unit deployment with no changes, and deploy it within different environments (pre-prod, prod, etc.).

Application Components

You will build a Master-Worker application, in which the Master is a client (or multiple clients) that submits orders to the space, and takes them back from the space after they are processed by the workers.

There are two types of workers:

  • A Validator, which takes orders from the space and either approves or rejects them.
  • A Processor, which takes approved orders and performs a simple mathematical operation on them.



Application Workflow

The basic workflow, as it is represented by Order objects in the space:

  1. One or more clients continuously write new Order objects to the space; each Order is tagged with a client ID.
  2. If one or more Validators are running, they take new orders from the space.
  3. The Validators check the orders, mark them either as approved or rejected, and write them back to the space.
  4. If one or more Processors are running, they take any approved orders (which have gone through a Validator).
  5. The Processors work on the orders, and write back Processed order objects to the space.
  6. Each of the Clients routinely checks to see if there are any Processed orders marked with its unique ID. If so, it takes the results from the space.
  7. Each of the Clients is also registered for notifications received whenever a Rejected order is written to the space, marked with its unique ID. If so, it takes the results from the space.

Notice that in this workflow, no component is dependent on any of the others. Clients write new orders to the space without caring how many Validators or Processors are running and which orders they have processed. They simply watch the space, and take processed orders using a polling mechanism or rejected orders using a notification mechanism when they appear. The same goes for the Validators and Processors – they simply watch the space for new orders to process or validate, and if they find any, perform the required operation and write the result back to the space.

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence