public class ClusteredHashTable
extends java.lang.Object
implements java.io.Serializable
For further details on a cluster, see the Cluster Resource Services APIs and the Clustering topic in the IBM i Information Center.
The purpose of this class is to provide interfaces to the Clustered Hash Table APIs.
An instance of this class can be used to put()
and get()
keyed entries from the Clustered Hash Table. The entries stored in the Clustered Hash Table
are replicated to cluster nodes defined in the Clustered Hash Table domain.
A connection to the Clustered Hash Table server is required to access the Clustered Hash Table.
Call open()
to obtain the connection. After the open() is complete, entries defined by the
ClusteredHashTableEntry
class can be put into the table or retrieved from the table, using the methods put() or get().
A key is required to put() an entry in the Clustered Hash Table.
Use generateKey()
to generate a universally unique key. The elements()
method will return a list of all that keys in the clustered hash table. It is recommended to close()
the active connection when done to release system resources
that are no longer needed.
This class uses the ClusteredHashTableEntry
class for the get(), elements() and put() methods.
Example Usage:
import com.ibm.as400.access.*;
import java.io.*;
import java.net.*;
import java.util.*;
public class MyFile extends Object
{
public static void main(String args[]) {
ClusteredHashTableEntry myEntry = null;
String myData = new String("This is my data");
try{
AS400 the400 = new AS400();
// CHTSVR01 is the clustered hash table server name
ClusteredHashTable cht = new ClusteredHashTable(the400,"CHTSVR01");
cht.open(); // make a connection
byte[] key = null;
key = cht.generateKey(); // get a key to access data with
// key is the key generated to access the data with
// myData is a byte array of data to be stored
// 2400 is the time to live in seconds
// ENTRY_AUTHORITY_ANY_USER indicates any user can access the data
// DUPLICATE_KEY_FAIL indicates if the key already exists in the hash table to not allow the request to succeed.
myEntry = new ClusteredHashTableEntry(key,myData.getBytes(),2400,ClusteredHashTableEntry.ENTRY_AUTHORITY_ANY_USER,ClusteredHashTableEntry.DUPLICATE_KEY_FAIL);
cht.put(myEntry); // store the entry in the hash table
ClusteredHashTableEntry output = cht.get(key); // retrieve the data
cht.close();
}
catch(Exception e){}
}
}
Note: This class uses APIs that are available only when connecting to systems running OS/400 V5R2M0 or later.
Modifier and Type | Field and Description |
---|---|
static int |
ALL_ENTRIES
Entry status value to retrieve all entries on a node.
|
static int |
CONSISTENT_ENTRIES
Entry status value to limit retrieved entries to only those which are consistent between nodes.
|
static int |
INCONSISTENT_ENTRIES
Entry status value to limit retrieved entries to only those which are inconsistent between nodes.
|
Constructor and Description |
---|
ClusteredHashTable()
Constructs a default ClusteredHashTable object.
|
ClusteredHashTable(AS400 system,
java.lang.String name)
Constructs a ClusteredHashTable object that represents the IBM i clustered hash table server.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to be notified when the value of any bound property is changed.
|
void |
close()
Closes a connection to the Clustered Hash Table server.
|
boolean |
containsKey(byte[] key)
Indicates if the specified key is in the clustered hash table.
|
ClusteredHashTableEntry[] |
elements()
Retrieves a list of entries that exist in the clustered hash table for the specified user profile.
|
ClusteredHashTableEntry[] |
elements(java.lang.String userProfile,
java.lang.String lastModifiedProfile,
int status)
Retrieves a list of entries that exist in the clustered hash table for the specified user profile.
|
byte[] |
generateKey()
Generates a 16-byte universally unique key.
|
ClusteredHashTableEntry |
get(byte[] key)
Returns information from the clustered hash table for the specified key.
|
java.lang.String |
getHandle()
Returns the name of the clustered hash table connection handle.
|
java.lang.String |
getName()
Returns the name of the clustered hash table server.
|
AS400 |
getSystem()
Returns the system object for the clustered hash table.
|
boolean |
isEmpty()
Indicates if the clustered hash table contains any keys.
|
void |
open()
Opens a connection to the Clustered Hash Table server.
|
void |
put(ClusteredHashTableEntry entry)
Put an entry in the clustered hash table identified by the connection handle.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes the listener from being notified when a bound property changes.
|
void |
setName(java.lang.String name)
Sets the name for the clustered hash table server.
|
void |
setSystem(AS400 system)
Sets the node of the clustered hash table.
|
int |
size()
Return the number of entries in the clustered hash table.
|
public static final int CONSISTENT_ENTRIES
public static final int INCONSISTENT_ENTRIES
public static final int ALL_ENTRIES
public ClusteredHashTable()
public ClusteredHashTable(AS400 system, java.lang.String name)
system
- The system that contains the clustered hash table server.name
- The name of an clustered hash table server.
This is a 10-byte string that identifies the Clustered Hash Table server to use.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener.removePropertyChangeListener(java.beans.PropertyChangeListener)
public void close() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
open()
to establish a connection
to a new Clustered Hash Table server.AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist on the system.public boolean containsKey(byte[] key) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
key
- The possible key.AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public ClusteredHashTableEntry[] elements() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public ClusteredHashTableEntry[] elements(java.lang.String userProfile, java.lang.String lastModifiedProfile, int status) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
userProfile
- The owner of the entries to be returned.
If null is specified, *ALL will be used and the results will depend upon the lastModifiedProfile.
If both the userProfile and the lastModifiedProfile profiles are null, all the entries in the clustered hash table that meet the criteria specified for the other parameters will be returned.lastModifiedProfile
- The most recent modifier of the entries to be returned.
If null is specified, *ALL will be used and the returned entries will depend on the value passed in for
the userProfile.status
- The type of entries to return. Possible values are:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public byte[] generateKey() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public ClusteredHashTableEntry get(byte[] key) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
For information on the authority considerations, see the Clustered Hash Table APIs.
key
- The key to use to return information.AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public java.lang.String getHandle()
public java.lang.String getName()
public AS400 getSystem()
public boolean isEmpty() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public void open() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
close()
to close
the connection from the Clustered Hash Table server.
Restrictions:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public void put(ClusteredHashTableEntry entry) throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
This request to store an entry is replicated to other nodes in the clustered hash table domain. Control will not be returned until the entry is stored in the clustered hash table on all active nodes in the clustered hash table domain.
There is no encrypting of the information that is replicated and stored in the clustered hash table.
When an entry is stored, a time to live value is specified. The entry can become expired, when the time to live value has expired. Expired entries will be removed when processing various functions.
The user that originally stores the entry will be the owner of the entry. The owning user profile will be used in determining authorization to an entry.
Information stored in the clustered hash table is associated with a key. The key can be generated using the generateKey() method or the user can generate their own.
Duplicate keys are not supported. An entry associated with an existing key can be updated if the requesting user is the owner of the entry or is authorized to the entry.
This method implicitly opens the connection to the clustered hash table server.
entry
- This object describes the information to put in the clustered hash table.AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The PropertyChangeListener.addPropertyChangeListener(java.beans.PropertyChangeListener)
public void setName(java.lang.String name)
name
- The name of the clustered hash table server.ExtendedIllegalArgumentException
- If the user specifies a name longer than 10public void setSystem(AS400 system)
system
- The system.public int size() throws AS400Exception, AS400SecurityException, ErrorCompletingRequestException, java.io.IOException, java.lang.InterruptedException, ObjectDoesNotExistException
Restrictions:
AS400Exception
- If the system returns an error message.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.io.IOException
- If an error occurs while communicating with the system.java.lang.InterruptedException
- If this thread is interrupted.ObjectDoesNotExistException
- If the object does not exist.