[Java programming language only]

Getting started tutorial lesson 3.2: Running the [Version 8.6 and later]Java getting started sample client application

Use the following steps to run a [Version 8.6 and later]Java client to interact with the data grid. The catalog server, container server, and client all run on a single server in this example.

[Version 8.6.0.2 and later]

Before you begin

(Optional) 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=localhost
SET CATALOGSERVER_PORT=2809
SET GRID_NAME=Grid
SET MAP_NAME=Map1

You must update the CATALOGSERVER_HOST and CATALOGSERVER_PORT values if your catalog server is not running on the same host as your client application.

Procedure

  • [Version 8.6 and later] Run the client in interactive mode.
    From the command-line window, run one of the following commands:
    • [Linux][Unix]./runclient.sh
    • [Windows]runclient.bat
    1. 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
    2. Insert a value.
      > i key1 helloWorld
      SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
      itionId=6
    3. Retrieve a value that you inserted.
      > g key1
      Value is TestValue [value=helloWorld], partitionId=6
    4. Update a value.
      > u key1 goodbyeWorld
      SUCCESS: Updated key TestKey [key=key1] with value TestValue [value=goodbyeWorld
      ], partitionId=6
    5. Rollback the transaction.
      When you roll back the transaction, all operations that are associated with this transaction are canceled.
      > rollback
    6. To test the rollback operation, try getting the key again.
      Because you rolled back the transaction, the key does not exist:
      > g key1
    7. Insert a value.
      > i key1 helloWorld
      SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
      itionId=6
    8. Delete a value that you inserted.
      > d key1
      SUCCESS: Deleted value with key TestKey [key=key1], partitionId=6
    9. 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
  • [Version 8.6 and later] 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:
    • [Linux][Unix]
      ./runclient.sh i "key1" "helloWorld"
    • [Windows]
      runclient.bat i "key1" "helloWorld"

Lesson checkpoint

Lessons learned

In this lesson, you learned:
  • How to run the [Version 8.6 and later]Java sample client application to insert, get, update, and delete data from the data grid.