Summary: A Map component allows you to create an
IMap (or
JCache
Cache) based on a Space component.
OverviewGigaSpaces 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.
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 APIExpand this... Clustered FlagWhen 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 CacheA 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 ComponentThe 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>
|
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |