Persistence for Hashtables

#
Persistence

## Using Persistence

- The package is meant for users who need to maintain the state of their Serializable name-value pair sets for better fault tolerance. Using this package will improve usability but will affect performance depending on the usage of the persist API.
- The current package will support only 2 known implementations, the DB storage way (which is vendor independant) and an ad-hoc (or some open source) implementation.
- The Persistence package assumes that the user will provide appropriate properties to initialize and use the storage mechanism.

## Code Example

Code examples make it easy to comprehend the package.

``
``

import org.jgroups.persistence.*;
// getting default factor
PersistenceFactory factory = PersistenceFactory();
//get reference to PersistenceManager (handle Exception as required by application)
// if user defines own properties
try
{
String filepath = "/home/user/userdefined.properties"
PersistenceManager manager = factory.createPersistenceManager(filepath);
//if user used existing properties by filling the values (default properties)
// PersistenceManager manager = factory.createPersistenceManager();
}catch (Exception e)
{
//handle Exception
}
//once the persistencemanager reference is obtained, use available
// to save a NV
HashMap map = new HashMap();
map.put("bela", "bela");
map.put("mandar", "mandar");
try
{
manager.saveAll(map); // will store all values from map into storage
}catch (CannotPersistException cpe)
{
//handle exception
}
//to update a value;
try
{
map.put("bela", "geek");
manager.save("bela", "geek"); // will update { {bela,bela}, {mandar,mandar})
// to { {bela,geek}, {mandar,mandar})
}catch (CannotPersistException cpe)
{
//handle exception
}
// to remove an entry
try
{
map.remove("mandar");
String value = (String) manager.remove("mandar");// will update {{bela,geek}, {mandar, mandar}}
//use value if required // to {bela,geek}
}catch (CannotRemoveException cre)
{
// handle exception
}
//**************************************************************************
// say, at start of application , need to get back stored state
//use above example to get back reference to "manager"
try
{
HashMap map = (HashMap) manager.retrieveAll(); // map will get {{bela,geek}}
}catch (CannotRetrieveException cree)
{
// handle exception
}

## Entering Properties (persist.properties)

Currently, the properties reflect only the DB related, as the FILE based implementation is not in place.

Name | Description | Typical Value
persist | Used to decide between DB or FILE. | DB/FILE (No default assumed)
jdbc.table | Lets the user dictate the schema used to storage purposes on the database. | create table replhashmap(key varchar(100), keybin blob, valbin blob)
jdbc.Driver | Classname for driver that needs to be loaded for DB storage. | oracle.jdbc.driver.OracleDriver
jdbc.Conn | Connection string required for user to connect to Db instance | jdbc:oracle:oci8:@instance
jdbc.User | User name required to connect to provided DB instance | user
jdbc.Pass | Password wrt to User provided | pass

## Using org.jgroups.blocks.DistributedHashtable with PersistenceManager

// Example of how to setup and use DistributedHashtable

- Create persist.properties (classpath or home dir)
- Start one instance with -persist
- Start another instance with -persist
- Add a couple of values
- Delete both instances
- Start first instance again: previous values should be available