This example has two counter parts: client and server. The client, a simple main called HelloWorld.java updates a data-grid with "Hello" and "World!" data entities and then reads them back. The HelloWorld
main accepts the following arguments: -name
{data-grid name} -mode
{embedded,remote}
A Plain Old Java Object (POJO) is the entity behind the updates to the data-grid. It consists of getters and setters for the 'msg' field, and a @SpaceId
for uniqueness (similar to a Map key).
Additional annotations may be applied - here are a couple:
@SpaceRouting
annotation can be applied to any field to allow routing to partition instances. If not specified, @SpaceId
will act as the routing field.@SpaceIndex
annotation can be applied to any field to allow indexing. @SpaceId
is by default indexed.This main class acts as the client. It can either start a single data-grid instance (embedded) in it's JVM, or connect to an existing (remote) data-grid (by it's name).
Import Maven examples/hello-world/pom.xml
into your IDE of choice as a maven project. Launch the HelloWorld
main (arguments: -name
myDataGrid -mode
embedded)
This will start an embedded data-grid followed by write and read of Message entities.
Created embedded data-grid: myDataGrid
write - 'Hello'
write - 'World!'
read - ['Hello', 'World!']
To connect to a remote data-grid, first use the xap space run
script to launch a data-grid.
From the ${XAP_HOME}/bin directory, run:
Import Maven examples/hello-world/pom.xml
into your IDE of choice as a maven project. Launch the HelloWorld
main (arguments: -name
myDataGrid -mode
remote)
use
myDataGrid
same as the argument passed toxap space run
Connected to remote data-grid: myDataGrid
write - 'Hello'
write - 'World!'
read - ['Hello', 'World!']
Each partition instance is loaded separately, as follows:
--partitions=2
for two partitions--instances=1_1
or --instances=2_1
for each partition instanceFrom the ${XAP_HOME}/bin directory, run:
This will simulate a data-grid of 2 partitioned instances (without backups).
Import Maven examples/hello-world/pom.xml
into your IDE of choice as a maven project. Launch the HelloWorld
main (arguments: -name
myDataGrid -mode
remote)
Connected to remote data-grid: myDataGrid
write - 'Hello'
write - 'World!'
read - ['Hello', 'World!']
Each partition instance can be assigned a backup, as follows:
--partitions=2
for two partitions, --ha
for high availability meaning a single backup for each partition.--instances=1_1
to load primary of partition id=1, --instances=1_2
to load the backup instance of partition id=1First partition:
Second partition:
The Example should be run in the same manner as before - Launch the HelloWorld
(arguments: -name
myDataGrid -mode
remote).
Connected to remote data-grid: myDataGrid
write - 'Hello'
write - 'World!'
read - ['Hello', 'World!']