Summary: A Map component allows you to create an IMap (or JCache Cache) based on a Space component.

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 Cache or IMap interfaces. The com.j_spaces.map.IMap is an extension of the com.j_spaces.javax.cache.Cache interface, and includes enhanced options such as transaction support, timeout operations (blocking read), and versioning.


OpenSpaces provides a simplified option to create an IMap or Cache implementation based on the Space component. Here is an example of how it can be configured:

Namespace
<os-core:space id="space" url="/./space" />

<os-core:map id="map" space="space"/>

Plain XML
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
</bean>

<bean id="map" class="org.openspaces.core.map.MapFactoryBean">
	<property name="space" ref="space" />
</bean>

Code
IJSpace space = // get Space either by injection or code creation

IMap map = new MapConfigurer(space).createMap();

Map/JCache API vs. Space API

Here is a simple comparison between the Map/JCache API vs. Space API:

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
Local Cache
Local View
Replicated Space
Partitioned Space
Service Grid Support
IWorker Support
ISpaceFilter Support

* via IMap.getMasterSpace()

Clustered Flag

When configuring a Space, an IJSpace instance is registered with Spring application context. When starting an embedded space with a cluster topology, or when looking up a remote space started with a cluster topology, a clustered proxy is returned. A clustered proxy is a smart proxy that performs operations against the whole cluster.

Many times, especially when working with a Processing Unit that starts an embedded space, operations against the space should be performed directly on the cluster member. This is a core concept of SBA and Processing Unit, where most if not all operations should be performed in-memory without leaving the Processing Unit boundaries, when a Processing Unit starts an embedded space.

The decision of working directly with a cluster member or against the whole cluster is done in the Map component level. The MapFactoryBean provides a clustered flag with the following logic as the default value: If the space is started in embedded mode (for example, /./space), the clustered flag is set to false. When the space is looked up in a remote protocol (Jini or RMI), the clustered flag is set to true. Naturally, the flag can be set explicitly. Here is an example of how the clustered flag can be configured:

Namespace
<os-core:space id="space" url="/./space" />

<!-- By default, since we are starting in embedded mode, clustered=false -->
<os-core:map id="directMap" space="space"/>

<os-core:map id="clusteredMap" space="space" clustered="true"/>

Plain XML
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
</bean>

<!-- By default, since we are starting in embedded mode, clustered=false -->
<bean id="directMap" class="org.openspaces.core.MapFactoryBean">
	<property name="space" ref="space" />
</bean>

<bean id="clusteredMap" class="org.openspaces.core.map.MapFactoryBean">
	<property name="space" ref="space" />
	<property name="clustered" value="true" />
</bean>

Code
IJSpace space = // get Space either by injection or code creation (using /./space url)

IMap directMap = new MapConfigurer(space).createMap();

IMap clusteredMap = new MapConfigurer(space).clustered(true).createMap();

The above example shows a typical scenario where the clustered flag is used. Within a Processing Unit, an application might need to access both the cluster member and the whole cluster directly.

Local Cache

A Map implementation can be constructed with Local Cache support.

Here is an example of how it can be configured:

Namespace
<os-core:space id="space" url="/./space" />

<bean id="evictionStrategy" class="com.j_spaces.map.eviction.FIFOEvictionStrategy">
    <property name="batchSize" value="1000"/>
</bean>

<os-core:map id="map" space="space" compression="1">
    <os-core:local-cache-support eviction-strategy="evictionStrategy"
                    put-first="false" size-limit="1000" update-mode="PULL" versioned="true" />
</os-core:map>

Plain XML
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
</bean>

<bean id="evictionStrategy" class="com.j_spaces.map.eviction.FIFOEvictionStrategy">
    <property name="batchSize" value="1000"/>
</bean>

<bean id="map" class="org.openspaces.core.map.MapFactoryBean">
    <property name="space" ref="space" />
    <property name="localCacheSupport">
        <bean class="org.openspaces.core.map.LocalCacheSupport">
             <property name="evictionStrategy" ref="evictionStrategy" />
             <property name="putFirst" value="false" />
             <proeprty name="sizeLimit" value="1000" />
             <property name="updateModeName" value="PULL" />
             <property name="versioned" value="true" />
        </bean>
    </property>
</bean>

Code
IJSpace space = // get Space either by injection or code creation

FIFOEvictionStrategy evictionStrategy = new FIFOEvictionStrategy();
evictionStrategy.setBatchSize(1000);
IMap map = new MapConfigurer(space).localCacheEvictionStrategy(evictionStrategy)
                                   .localCachePutFirst(false);
                                   .localCacheSizeLimit(1000);
                                   .localCacheUpdateMode(UpdateMode.PULL);
                                   .localCacheVersioned(true);
                                   .createMap();

Once the local cache support element/bean is provided, a Map with local cache support is constructed.

Working with Map Component

The following bean uses an IMap component for simple put and get operations:

public class SimpleMapUsage {

    private IMap map;

    public void setMap(IMap map) {
        this.map = map;
    }
    
    public void performPutAndGet() {
        map.put("key1", "value1");
        String value1 = (String) map.get("key1");
    }
}

Here is how it can be configured:

Namespace
<os-core:space id="space" url="/./space" />

<os-core:map id="map" space="space"/>

<bean id="simpleMapUsage" class="eg.SimpleMapUsage">
    <property name="map" ref="map" />
</bean>

Plain XML
<bean id="space" class="org.openspaces.core.space.UrlSpaceFactoryBean">
    <property name="url" value="/./space" />
</bean>

<bean id="map" class="org.openspaces.core.map.MapFactoryBean">
	<property name="space" ref="space" />
</bean>

<bean id="simpleMapUsage" class="eg.SimpleMapUsage">
    <property name="map" ref="map" />
</bean>

The Map component has an extremely simple API. The GigaMap simplifies it even more by wrapping it and providing declarative transaction support and other features.

GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence