Search code examples
gridgain

Gridgain: Get an object value from GridCache


With reference to the example CachePutGetExample.java, https://github.com/gridgain/gridgain-advanced-examples/blob/master/src/main/java/org/gridgain/examples/datagrid/putget/CachePutGetExample.java

Test1: With the putx part in the code, getx works fine for (int i = 0; i < keyCnt; i++) cache.putx(i, Integer.toString(i));

Test2: With the putx part commented, getx works fine for (int i = 0; i < keyCnt; i++) cache.putx(i, Integer.toString(i));

When I try to get the values, I'm able to retrieve them

But when I changed the GridCache to:

final GridCache<Integer, Person> cache = g.cache(CACHE_NAME);

and run the same tests,

Test1: with putx part in the code, getx works fine for (int i = 0; i < keyCnt; i++) cache.putx(i, person1);

Test2: without putx part in the code, getx returns null for (int i = 0; i < keyCnt; i++) cache.putx(i, person1);

Am I going wrong somewhere? Or is it like that in GridGain, when we use object as the value.


Solution

  • I think the code gets automatically undeployed (which means that caches get cleared) whenever you shutdown the main node. You can change this behavior in 2 ways:

    1. Change configuration setting for deployment mode to CONTINUOUS (it is set to SHARED by default). In this case, the classes will not be automatically undeployed whenever the master node leaves.

    2. Build examples.jar (you can do it with maven) and copy the Jar file into libs folder on every node. This way the classes will be locally deployed on every node and, therefore, will not be undeployed whenever any node leaves.