Space
In GigaSpaces, Space can be used as In-Memory Data Grid(IMDG) and Message Bus.
Such Space IMDG can be located in front of DBMS to avoid such single point of failure and bottleneck.
We have seen in Messaging Grid with JMS that Space has an JMS implementation with which the messages can be transported through spaces.
In the next example, we will see that the message is delivered with JavaSpaces for which GigaSpaces has improved some functionality.
Next example, called OMS is originated from XAP Tutorial.
To run for my intention, some codes of it has been modified. Please, download oms.zip for more details.
OMS Overview
- Space is used as IMDG and Message Bus using JavaSpaces.
- Account Data Loader Service loads all the account data into IMDG in Space.
- After finishing the jobs by Accoutn Data Loader Service, Order Event Feeder will feed the order event with status of 'New' into the space.
- From Order Event Validator Service, all the order event with the status of 'New' will be catched and validated. The validated order event will have new status of 'Pending', and it will be written into the space.
- Order Event Processor Service will catch all the order event with the status of 'Pending' and process it. After processing the order event, Order Event Processor Service will write the order event with the new status of 'Processed' into the space.
- While being done the above processes, Output Account Data Service will monitor the update of account data, and Output Order Event Count will also monitor the count of the order event for the individual status.
@SpaceDataEvent
Annotation @SpaceDataEvent can be used to get the notification of the data event from the space.
In our example, OrderEvent POJO is used as such data event object.
Let's see some code example as follows:
package com.ktf.khub.samples.grid.messaging.oms.service; import org.openspaces.events.adapter.SpaceDataEvent; import com.ktf.khub.samples.grid.messaging.oms.dao.AccountDataDao; import com.ktf.khub.samples.grid.messaging.oms.domain.OrderEvent; import com.ktf.khub.samples.grid.messaging.oms.logic.OmsFacade; public class OrderEventValidatorService { ... @SpaceDataEvent public void validatesOrderEvent(OrderEvent orderEvent) { System.out.println("---[Validator: Validating orderEvent:"+orderEvent+" ]---"); OrderEvent newOrderEvent = this.omsFacade.takeOrderEvent(orderEvent); boolean isAccountFound = this.omsFacade.isAccountFound(newOrderEvent.getUserName()); if (isAccountFound == true){ newOrderEvent.setStatus("Pending"); System.out.println("---[Validator: OrderEvent approved, status set to PENDING]---"); } else { newOrderEvent.setStatus("AccountNotFound"); System.out.println("---[Validator: OrderEvent rejected, ACCOUNT NOT FOUND]---"); } newOrderEvent.setOrderID(null); this.omsFacade.writeOrderEvent(newOrderEvent); } ... }
In the above example, it is Order Event Validator Service POJO Component. Matched OrderEvent with the status of 'New' will be validated there.
GigaSpaces supports NotifyContainer to notify such matched data with Template in the spaces.
Here is the example of spring xml configuration for the above Order Event Validator Service:
... <!-- ============================================================ Order Event Validator Service ============================================================ --> <bean id="orderEventValidatorService" class="com.ktf.khub.samples.grid.messaging.oms.service.OrderEventValidatorService"> <property name="omsFacade" ref="omsFacade" /> </bean> <os-events:notify-container id="orderEventValidatorServiceNotifyContainer" giga-space="gigaSpace"> <os-events:tx-support tx-manager="transactionManager" /> <os-core:template> <bean class="com.ktf.khub.samples.grid.messaging.oms.domain.OrderEvent"> <property name="status" value="New" /> </bean> </os-core:template> <os-events:listener> <os-events:annotation-adapter> <os-events:delegate ref="orderEventValidatorService" /> </os-events:annotation-adapter> </os-events:listener> </os-events:notify-container> ...
orderEventValidatorServiceNotifyContainer will catch the com.ktf.khub.samples.grid.messaging.oms.domain.OrderEvent with the property status of 'New' in the template defined, and it will delegate to the orderEventValidatorService which validates the matched OrderEvent.
As we have seen, in our POJO OrderEventValidatorService, there is no codes of such connector, for instance, JavaSpaces to find. Connectivity and Component is clearly seperated from each other.
In contrast to the example of Messaging Grid with JMS in which Mule is used as a core of routing mechanism, here Space based Architecture(SBA) routing is used.
Required Softwares
Required Softwares to run the example OMS are listed below:
Run example OMS
To run the example OMS, please download oms.zip, and unzip it.
Make sure that all the required libraries of GigaSpaces XAP 6.0 and Spring 2.5.x are copied into <oms>/lib.
Open <oms>/bin/set-env.bat, modify the following lines:
rem ===================================================
rem set the GigaSpaces home.
rem ===================================================
@set JSHOMEDIR="D:\project\action-khub-samples\apps\3rd-parties\giga-spaces\GigaSpacesXAP6.5M8"
set the correct GigaSpaces installation directory.
Please, follow the next steps:
- change the command to <oms>, and type 'ant' to build our example.
- change the directory to <oms>/bin, and run run start-part-backup-*.bat to run the partitioned spaces.
- run start-jini-tx.bat to run the jini transaction manager.
- run run-app.bat to start example.
- run gs-ui-mykidong.bat to browse the entries in the spaces.
Conclusion
We have seen that messsages can be delivered with JavaSpaces through spaces.
We have also experienced Space based Architecture similar to Pipes and Filters Architecture in EIP.
In POJO component, there is no such codes about connectivity and the template used to match the data object in the spaces.
Just with some change of Spring XML, such match template can be configured declaratively.
Attachment
- OMS Source Codes: oms.zip





