ClusteredHashTable classes

The IBM® Toolbox for Java™ ClusteredHashTable classes enable your Java programs to use highly available clustered hash tables to share and replicate data to nonpersistent storage among the nodes in a cluster.

To use the ClusteredHashTable classes, ensure that you can use nonpersistent storage for the data. Replicated data is not encrypted.

Note: The following information assumes that you understand the concepts and terminology common to IBM i cluster technology. See IBM i cluster technology for details.

Using the ClusteredHashTable class requires that you have defined and activated a cluster on the systems. You must also start a clustered has table server. For more information, see Configure clusters and Clustered Hash Table APIs.

Required parameters are the name of the clustered hash table server and the AS400 object, which represents the system that contains the clustered hash table server.

In order to store data in a clustered hash table server, you need a connection handle and a key:

  • When you open a connection, the clustered hash table server assigns the connection handle that you must specify on subsequent requests to the clustered hash table server. This connection handle is good only for the instantiated AS400 object, so you must open another connection if you use a different AS400 object.
  • You must specify the key to access and change data in the clustered hash table. Duplicate keys are not supported.

The ClusteredHashTable class provides methods that enable you to perform the following actions:

Some methods in the ClusteredHashTable class use the ClusteredHashTableEntry class to perform the following actions:

Example: Using ClusteredHashTable

The following example operates on clustered hash table server named CHTSVR01. It assumes a cluster and a clustered hash table server is already active. It opens a connection, generates a key, puts an entry using the new key in the clustered hash table, gets an entry from the clustered hash table, and closes the connection.

     ClusteredHashTableEntry myEntry = null;

     String myData = new String("This is my data.");
     System.out.println("Data to be stored: " + myData);

     AS400 system = new AS400();
     
     ClusteredHashTable cht = new ClusteredHashTable(system,"CHTSVR01");

     // Open a connection.
     cht.open();

     // Get a key to the hash table.
     byte[] key = null;
     key = cht.generateKey();

     // Prepare some data that you want to store into the hash table.
     // ENTRY_AUTHORITY_ANY_USER means that any user can access the
     // entry in the clustered hash table.
     // DUPLICATE_KEY_FAIL means that if the specified key already exists,
     // the ClusteredHashTable.put() request will not succeed.
     int timeToLive = 500;
     myEntry = new ClusteredHashTableEntry(key,myData.getBytes(),timeToLive,
          ClusteredHashTableEntry.ENTRY_AUTHORITY_ANY_USER,
          ClusteredHashTableEntry.DUPLICATE_KEY_FAIL);

     // Store (or put) the entry into the hash table.
     cht.put(myEntry);

     // Get an entry from the hash table.
     ClusteredHashTableEntry output = cht.get(key);

     // Close the connection.
     cht.close();

Using the ClusteredHashTable class causes the AS400 object to connect to the server. For more information, see Managing connections.