You can connect to catalog server, obtain ObjectGrid instance, and use ObjectMap API.
The catalog server to specify is displayed on the user interface page for the simple data grid that you created. Click Catalog services field.
and use the values that are in theTo connect to the catalog server, use the connect method of ObjectGridManager API. The connect method that is used requires only the catalog server endpoint in the format of hostname:port. You can indicate multiple catalog server endpoints by separating the list of hostname:port values with commas. The following code snippet demonstrates how to connect to a catalog server and obtain a ClientClusterContext instance:
ClientClusterContext ccc = ObjectGridManagerFactory.getObjectGridManager().connect("myXC10.myhost.com:2809", null, null);
The connect method attempts to connect to each appliance in the list until it makes a successful connection. Automatic failover is provided if one of the other appliances does not respond.
If the connections to the catalog servers succeed, the connect method returns a ClientClusterContext instance. The ClientClusterContext instance is required to obtain the ObjectGrid from ObjectGridManager API.To obtain ObjectGrid instance, use the getObjectGrid method of the ObjectGridManager API. The getObjectGrid method requires both the ClientClusterContext instance and the name of the data grid instance. The ClientClusterContext instance is obtained during the connection to catalog server. The name of the data grid instance is the name of the simple data grid that you created in the user interface. The following code snippet demonstrates how to obtain the data grid by calling the getObjectGrid method of the ObjectGridManager API.
ObjectGrid grid = ObjectGridManagerFactory.getObjectGridManager().getObjectGrid(ccc, “my_simple_data_grid”);
// Creates a ClientSecurityConfiguration object using the specified file
ClientSecurityConfiguration clientSC = ClientSecurityConfigurationFactory.getClientSecurityConfiguration();
clientSC.setSecurityEnabled(true);
// Creates a CredentialGenerator using the passed-in user and password.
CredentialGenerator credGen = new UserPasswordCredentialGenerator(username,password);
clientSC.setCredentialGenerator(credGen);
return clientSC;
You can get a Session from the obtained ObjectGrid instance. A Session instance is required to get the ObjectMap instance, and perform transaction demarcation. The following code snippet demonstrates how to get a Session instance by calling the getSession method of the ObjectGrid API.
Session sess = grid.getSession();
After getting a Session, you can get an ObjectMap instance from a Session instance by calling getMap method of the Session API. The map instance name that you pass to the getMap method has the same name as the data grid that you created in the user interface. The following code snippet demonstrates how to obtain ObjectMap by calling the getMap method of the Session API.
ObjectMap map1 = sess.getMap("my_simple_data_grid");
ObjectMap map2 = sess.getMap("my_simple_data_grid.CT.P");
ObjectMap map3 = sess.getMap("my_new_map.NONE");
The my_simple_data_grid.CT.P map
is a map that uses creation time eviction and pessimistic locking.
The my_new_map.NONE map does not have any eviction
or locking settings. See Dynamic map configuration options for
more information.After an ObjectMap instance is obtained, you can use the ObjectMap API. Remember that the ObjectMap interface is a transactional map and requires transaction demarcation by using the begin and commit methods of the Session API. If there is no explicit transaction demarcation in the application, the ObjectMap operations run with auto-commit transactions.
The following code snippet demonstrates how to use the ObjectMap API with an auto-commit transaction.
map1.insert(key1, value1);
The keys that you use can be of an existing Java type, such as java.lang.String or Integer. Values can consist of any serializable object type.
The following code snippet demonstrates how to use the ObjectMap API with explicit transaction demarcation.
sess.begin();
map1.insert(key1, value1);
sess.commit();