Section Summary: GigaSpaces provides a Map/JCache interface, which allows applications to write to a space/cache using the Map APIs – put(), get(), remove(), transaction() – or the richer JCache specification.
Overview
GigaSpaces allows applications to interact with the space using the Map API (JCache). Accessing the space via the Map API can be done using the com.j_spaces.javax.cache.Cache or via the com.j_spaces.map.IMap interfaces.
The com.j_spaces.map.IMap is extension of the com.j_spaces.javax.cache.Cache interface and includes enhanced options such as transaction support, timeout operations (blocking read) and versioning.
Map API vs. JavaSpaces API
Expand this...
Feature
Space API
Map API
Batch Operations
Limited.
Master-Worker Pattern
Continuous Query
Custom Query Pattern
Externalizable Support
– The value object should implement Externalizable.
FIFO Support
Indexing
Inheritance Support
Iterator
Unicast Notifications
– Limited.
Multicast Notifications
Tokenized Notifications
POJO Support
Jini Distributed Transaction Support
Local Transaction Support
XA Transaction Support
UID Support
Lease
Partial Update
Simple Matching
Complex Entry Attribute Query Support
Regular Expression Query Support
SQL Query Support
Administration API
Exclusive Read Lock
*
Optimistic Locking
Pessimistic Locking
Timeout operations (read/take with timeout > 0)
Spring Support
– Via the declarative cache
Local Cache
Local View
Replicated Space
Partitioned Space
Service Grid Support
** – No injection of IMap.
IWorker Support
**
ISpaceFilter Support
**
* via IMap.getMasterSpace()
** via CacheFinder.find(String url, IJSpace space)
The com.j_spaces.map.CacheFinder is a factory class that generates space/cache proxies or start a space within the application process (embedded mode). It includes static methods that return the desired space/cache proxy. When running the space within the application process you can determine the space cluster topology (replicated , partitioned) using the Space URL that is provided as an argument to CacheFinder methods.
CacheFinder Methods
Expand this...
Return Value
Method
Static Object
find(String url)
The general format for the URL is as follows: Protocol://<host>:<port>/<container_name>/<space_name>?<arguments>
Static Object
find(String[] urls)
This method accepts multiple URLs, allowing you to define a space/cache search order.
static Object
find(String url, IJSpace space)
Finds a space/cache using the space object provided.
static Object
Find(String url,Properties customProps)
Finds a space/cache using the custom properties provided, which overwrite the space and cluster configurations.
com.j_spaces.map.IMap: the Map Interface
The IMap interface (com.j_spaces.map.IMap; see Javadoc) is the returned object from the CacheFinder.find() method. Based on the URL provided and the configuration, the returned IMap object can encapsulate access to a remote space/cache, embedded space/cache, replicated cache, or partitioned cache.
The IMap interface exposes the familiar Map APIs put(), get(), and remove(); the setTransaction() method is used to encapsulate Map operations in a transaction (see Map Transactions).
com.j_spaces.javax.cache.Cache: JCache Interface
Expand this...
The Cache interface (com.j_spaces.javax.cache.Cache; see Javadoc) includes all the basic JCache methods.
The com.j_spaces.javax.cache.Cache interface provides access to the data via a key associated with a value object. The key can be any class type that uniquely implements the toString() method. The key and the value objects must implement the serializable interface.
RDBMS Read-Through and Write-Through
Expand this...
When the cache stores database data, you may want to load objects from the database to the cache implicitly. The CacheLoader interface allows you to instruct the cache to load data when the desired key is not found in the cache. CacheLoader.load() is called when the IMap.get() method is called and the specified key cannot be found in the cache – when implementing the former method, you can specify how to retrieve the data from the database. The CacheStore interface works in a similar manner, allows you to implicitly write objects to a database when they are written to the cache.
Evicting objects from the cache can be done explicitly using a time-to-live parameter, or implicitly via an LRU eviction mechanism, which evicts objects from the cache based on the percentage of available free memory and an upper threshold of total cache objects.
Section Contents
Map Exceptions — The two main exceptions thrown for cache problems: EntryVersionConflictException and CacheTimeoutException.
Map Iterator — Used to get objects matching multiple templates in one call.
Map Notifications — How to register to be notified when objects are put to or removed from the space/cache.
Map Optimistic Locking — How to you write applications under the assumption that put operations may fail, if the updated object is changed by someone else since it was read.
Map Pessimistic Locking — How to explicitly prevent multiple users from from performing get, put or remove operations with the same key under a transaction.
Map Transactions — Performing distributed and 'local' transactions on space/cache instances.
We need your help to improve this wiki site. If you have any suggestions or corrections, write to us at techw@gigaspaces.com. Please provide a link to the wiki page you are referring to.
Add Comment