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 space-instance.{sh,bat}
script to launch a data-grid.
From the ${XAP_HOME}/bin directory, run:
-name
myDataGridImport 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-name
argument passed tospace-instance.{sh.bat}
Connected to remote data-grid: myDataGrid
write - 'Hello'
write - 'World!'
read - ['Hello', 'World!']
Each partition instance is loaded separately, as follows:
total_members=2
for two partitionsid=1
or id=2
for each partition instanceFrom the ${XAP_HOME}/bin directory, run:
-name
myDataGrid -cluster
schema=partitioned total_members=2 id=1-name
myDataGrid -cluster
schema=partitioned total_members=2 id=2This 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:
total_members=2,1
for two partitions, each with a single backup.backup_id=1
to load the backup instance of partition id=1 or id=2First partition:
-name
myDataGrid -cluster
schema=partitioned total_members=2,1 id=1-name
myDataGrid -cluster
schema=partitioned total_members=2,1 id=1 backup_id=1Second partition:
-name
myDataGrid -cluster
schema=partitioned total_members=2,1 id=2-name
myDataGrid -cluster
schema=partitioned total_members=2,1 id=2 backup_id=1The 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!']