Use the following steps to run a Java client
to interact with the data grid.
Edit
the
wxs_install_root/ObjectGrid/gettingstarted/env.bat|sh file.
This file is invoked by the client automatically. The file contains
the following information:
SET CATALOGSERVER_HOST=<xc10_hostname>
SET CATALOGSERVER_PORT=2809
SET GRID_NAME=my_simple_data_grid
SET MAP_NAME=my_map.P
To connect to a data grid on
the appliance, you must update the CATALOGSERVER_HOST and CATALOGSERVER_PORT variables.
The catalog server to specify is displayed on the user interface page
for the simple data grid that you created. Click and use the values that are in the Catalog
services field. The value of the GRID_NAME property
must match the name of the data grid that you created. The MAP_NAME property
creates a map with no time to live (TTL) setting and pessimistic locking.
For more information about naming dynamic maps, see Dynamic map configuration options.
- Run the client in interactive mode. From the command-line window, run one of the following commands:
![[Unix]](./images/ngunix.gif)
./runclient.sh
runclient.bat
- Start a transaction. You can use a one-phase
commit or a two-phase commit operation for your transaction. With
a one-phase commit, the transaction must write to a single partition. If
you insert several keys during your transaction that are placed in
different partitions, the transaction fails when you commit. You can
use a two-phase commit to write to multiple partitions in a single
transaction.
- Begin a one-phase commit transaction.
begin
- Begin a two-phase commit transaction.
begin2pc
- Insert a value.
> i key1 helloWorld
SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
itionId=6
- Retrieve a value that you inserted.
> g key1
Value is TestValue [value=helloWorld], partitionId=6
- Update a value.
> u key1 goodbyeWorld
SUCCESS: Updated key TestKey [key=key1] with value TestValue [value=goodbyeWorld
], partitionId=6
- Rollback the transaction. When you roll
back the transaction, all operations that are associated with this
transaction are canceled.
> rollback
- To test the rollback operation, try getting the key
again. Because you rolled back the transaction, the key
does not exist:
> g key1
- Insert a value.
> i key1 helloWorld
SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
itionId=6
- Commit the value. After you commit the transaction,
you cannot roll back changes.
> commit
- Delete a value that you inserted.
> d key1
SUCCESS: Deleted value with key TestKey [key=key1], partitionId=6
- Insert a number of test entries. For example,
to insert 1000 keys and values that are numbered from 0 to 999, use
the following command:
> n 1000
- Run the client in command-line mode. Using command-line mode can be useful if you want to write a
script to run the client application. You can run the same commands
that you run in interactive mode. An example of the syntax for command-line
mode follows: