[.net programming language only]

Getting started tutorial lesson 3.3: Running the .NET sample client application

[Version 8.6 and later]Use the following steps to run a WebSphere® eXtreme Scale Client for .NET application to interact with the data grid. The catalog server, container server, and client all run on a single server in this example.

About this task

WebSphere eXtreme Scale Client for .NET supports one-phase commits only. Therefore, if you try to insert multiple values in the same transaction, an exception might result because the values are going to different partitions. To prevent these exceptions from occurring when you run the sample, you can change your deployment policy descriptor XML file to use one partition. For more information about updating the number of partitions, see Getting started tutorial lesson 1.1: Defining data grids with configuration files.

You can run the sample application in interactive or command-line mode. In interactive mode, the application runs manual data grid transactions with the IGridMapPessimisticTx API. Command-line mode runs automatic data grid transactions with the IGridMapPessimisticAutoTx API.

Procedure

You can run the sample in interactive mode or command-line mode:

  • Run the sample client application in interactive mode.
    1. Run the simple client application. The file is in the net_client_home\gettingstarted\bin\ directory.
      To run the sample in interactive mode, run the following command.
      SimpleClient.exe -i [-h <hostname:port>] [Version 8.6.0.2 and later] [-g <gridname>] [-m <mapname>] 
      [Version 8.6.0.2 and later]
      -h <hostname:port>
      Specifies the host name and port for the catalog server to which you want to connect. The application connects to the localhost:2809 host by default.
      -g <gridname>
      Specifies the name of the data grid to use. You must use a map with a pessimistic locking strategy. If you do not specify a value, the Grid data grid is used.
      -m <mapname>
      Specifies the name of the map to use. If you do not specify a value, the Map1 map is used.
      If you run the application with no parameters, the application help displays.
    2. Display a list of commands that are available.
      Enter a command: help
      This program executes simple CRUD operations on a map.
              a - Adds a value with the specified key. If the key already exists, 
              DuplicateKeyException is thrown
              p - Adds a value with the specified key, replacing the entry if it 
              already exists
              r - Replaces the value of the specified key. If the key does not exist,
              a CacheKeyNotFound exception is thrown
              g - Retrieve and display the value of the specified key
              d - Deletes the key
              gp - Gets the partition id for the key
              ck - Checks if the map contains the key
              h - Display help
              begin - Begin manual transaction
              commit - Commit transactions
              rollback - Rollback transactions
              exit - Exit program
    3. Start the transaction.
      You must start a transaction to run commands on the data grid. If you do not start the transaction, a NoActiveTransacationException exception occurs.
      Enter a command: begin
    4. Add data to the data grid.
      Enter a command: a key1 value1
      SUCCESS: Added 'TestKey [key=key1]' with value 'TestValue [value=value1]', 
      partitionId=6
    5. Search and display the value.
      Enter a command: g key1
      SUCCESS: Value is 'TestValue [value=value1]', partitionId=6
      In this example, value1 is returned.
    6. Update the key. Use the put command, which adds a value with the specified key, replacing the existing value if it exists.
      Enter a command: p key1 value2
      SUCCESS: Put key 'TestKey [key=key1]' with value 'TestValue [value=value2]',
       partitionId=6
      Enter a command: g key1
      SUCCESS: Value is 'TestValue [value=value2]', partitionId=6
    7. Replace the key. The replace command replaces the value with the specified key. If the key does not exist, a CacheKeyException exception results.
      Enter a command: r key1 value3
      SUCCESS: Replaced key 'TestKey [key=key1]' with value 'TestValue [value=value3]'
      , partitionId=6
    8. Roll back the transaction and try to display the value key again.
      You can roll back the transaction any time before you commit.
      Enter a command: rollback
      Enter a command: begin
      Enter a command: g key1
      FAILED: Key not found
      When you run the get command, you get an error that indicates that key was not found.
    9. Commit a key and value to the data grid.
      Enter a command: begin
      Enter a command: a key2 value2
      SUCCESS: Added 'TestKey [key=key2]' with value 'TestValue [value=value2]', 
      partitionId=7
      Enter a command: commit
    10. Get the partition ID for a key.
      Enter a command: begin
      Enter a command: gp key2
      SUCCESS: partitionId=7
    11. Check the map for keys.
      Enter a command: ck key2
      SUCCESS: The map contains key 'TestKey [key=key2]'
      Enter a command: ck key3
      SUCCESS: The map does NOT contain key 'TestKey [key=key3]'
    12. Delete the key and exit.
      Enter a command: begin
      Enter a command: d key2
      SUCCESS: Deleted value with key 'TestKey [key=key2]', partitionId=7
      Enter a command: commit
      Enter a command: exit
  • Run the client in command-line mode. Command-line mode runs automatic data grid transactions with the IGridMapPessimisticAutoTx API. To use this mode, pass the action on the command line. 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:
    SimpleClient [-h <host:port>] [Version 8.6.0.2 and later][-g <grid_name>] [-m <mapname>] <a | p | r | g | d> 
    <key> [<value>] 
Related tasks[Version 8.6 and later][.net programming language only]Developing data grid applications with .NET APIsYou can develop Microsoft .NET applications that use the same data grid as your Java applications.Accessing WebSphere eXtreme Scale Client for .NET API documentation[Version 8.6 and later]You can access the WebSphere eXtreme Scale Client for .NET API documentation within a .chm file or by viewing the API documentation in the information center.

Lesson checkpoint

In this lesson, you learned:
  • How to run the .NET sample client application to insert, get, update, and delete objects from the data grid.