[infinispan-dev] Atomic Objects on top of Infinispan

Pierre Sutra pierre.sutra at unine.ch
Mon Aug 19 13:11:16 EDT 2013


Hello,

As part of the LEADS project (http://www.leads-project.eu), I
implemented a factory of atomic objects on top of Infinispan. The code
is available in the classes AtomicObject*.java stored in the directory
https://github.com/otrack/Leads-infinispan/tree/master/core/src/main/java/org/infinispan/atomic
of my Github clone of infinispan. The tests are written in the class
AtomicObjectFactoryTest.java, available under
core/src/test/java/org/infinispan/atomic. Besides, you may find below a
simple code snippet:

AtomicObjectFactory factory = new AtomicObjectFactory(c1); // c1 is both
synchronous and transactional
Set set = (Set) factory.getOrCreateInstanceOf(HashSet.class, "k"); // k
is the key to store the variable set inside the cache c1
set.add("smthing"); // some call examples
System.out.println(set.toString())
set.addAll(set);
factory.disposeInstanceOf(HashSet.class, "set", true); // to store the
object in a persistent way

The pattern I followed to implement this facility is the state machine
replication approach. More precisely, the factory is built on top of the
transactional facility of Infinispan. When the factory creates an
object, it stores a local copy of the object and registers a proxy as a
cache listener. A call to some method of an object is serialized in a
transaction consisting of a single put operation. When the call is
de-serialized it is applied to the local copy, and in case the calling
process was local, the result of the call is returned (this mechanism is
implemented via a future object). Notice that this implies that all the
arguments of the methods of the object are serializable, as well as the
object itself.  The current implementation supports the retrieval of
persisted objects, an optimization mechanism for read operations, and is
elastic (an atomic object supports on the fly the addition/removal of
local and/or distant threads accessing it).

I hope that this work might interest you.

Best,
Pierre



More information about the infinispan-dev mailing list