OpenSpaces provides a simpler Map/JCache API using the GigaMap interface, by wrapping the IMap (and the JCache Cache), and simplifying both the API and its programming model. The interface allows for declarative transactions, coherent runtime exception hierarchy, and more.
Here is a very simple example of how to define it:
The GigaMap interface is a thin wrapper built on top of IMap. Within a single Processing Unit (or Spring application context), several GigaMap instances can be defined, each with different characteristics.
The IMap interface is not hidden, and can be used even when using the GigaMap interface. GigaMap simplifies most operations used with the space (compared to IMap), but some operations still require access to IMap, which can be accessed through the GigaMap API.
The GigaMap provides the exact semantic as the java.util.Map interface: clear, containsKey, put, putAll, get and remove methods. In addition it includes the lock , putAndUnlock , and the unlock methods.
The GigaMap support local cache configuration. This will provide a front end client cache that will be used with get operations. The local cache will be loaded on demand.
Here is an example for a GigaMap construct with a local cache:
There is no need to provide a Jini transaction object for the different map operations. GigaMap with the different OpenSpaces transaction managers and Spring allow simple declarative definition of transactions. This means that if there is an ongoing transaction running, most operations performed using the GigaMap interface join it, using Spring's rich transaction support.
It is highly recommended to read the transaction management chapter in the Spring reference documentation.
OpenSpaces provides a pluggable transaction provider using the following interface:
OpenSpaces comes with a default transaction provider implementation, which uses Spring and its transaction manager in order to obtain the currently running transactions, and automatically use them under transactional operations.
GigaMap allows access to current running transactions using the transaction provider. The following code example shows how the put operation can be performed using IMap (users normally won't be required to do so):
GigaSpaces supports three isolation levels: READ_UNCOMMITTED, READ_COMMITTED and REPEATABLE_READ (default). When using GigaMap, the default isolation level it is performed under can be defined in the following manner:
In addition, Spring allows you to define the isolation level on the transaction definition itself:
In the above example, any operation performed using GigaMap in the updateFoo method automatically works under the READ_COMMITTED isolation level.
OpenSpaces is built on top of the Spring consistent exception hierarchy by translating all of the different JavaSpaces exceptions and GigaSpaces exceptions into runtime exceptions, consistent with the Spring exception hierarchy. All the different exceptions exist in the org.openspaces.core package.
OpenSpaces provides a pluggable exception translator using the following interface:
A default implementation of the exception translator is automatically used, which translates most of the relevant exceptions into either Spring data access exceptions, or concrete OpenSpaces runtime exceptions (in the org.openspaces.code package).