Summary: OpenSpaces allows you to easily configure and use the space local view feature using the LocalViewSpaceFactoryBean component and local cache using LocalCacheSpaceFactoryBean.
Use Native Serialization mode
When running a local cache/view you should use Native Serialization mode with the master space. Running in any other serialization mode might impact the speed of reading objects from the local cache/view and the client Memory utilization behavior.

Local View

OpenSpaces allows you to easily configure and use the space local view using the LocalViewSpaceFactoryBean component. The factory exposes the same IJSpace implementation that a regular space component exposes, with the additional feature of having a local view.

The space local view proxy maintains a subset of the master space's data, allowing the client to read distributed data without any remote operations. Data is streamed into the client view in an implicit manner - as opposed to local cache data, that is loaded into the client on-demand, and later updated or evicted. The local view is defined via a filter - regular template or SQLQuery - as opposed to the local cache that caches data at the client side only after the data has been read.

The following is an example of how a local view can be configured:

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

<os-core:local-view id="viewSpace" space="space">
    <os-core:view-query where="processed = true" class="eg.Message"/>
</os-core:local-view>

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

<bean id="viewSpace" class="org.openspaces.core.space.cache.LocalViewSpaceFactoryBean">
    <property name="space" ref="space" />
    <property name="localViews">
        <list>
          <bean class="com.j_spaces.core.client.view.View">
                <constructor-arg index="0" value="eg.Message" />
                <constructor-arg index="1" value="processed = true" />
            </bean>
        </list>
    </property>
</bean>

Code
IJSpace space = // get Space either by injection or code creation
IJSpace localViewProxy = new LocalViewSpaceConfigurer(space).addView("eg.Message", "processed = true")
                                                       .localView();
GigaSpace gigaspace = new GigaSpaceConfigurer(localViewProxy).gigaSpace();

Streaming Space Subset Data into Client

Once the local view is constructed, data is pre-loaded into the client based on the view filter criteria (as opposed to the local cache that does not have a pre-load phase).

The local view is continuously updated by the master space in an asynchronous mode (using notifications). Both write and update operations are delivered into the client based on the view filter criteria (as opposed to the local cache that delivers only update operations to the client).
All read operations (including readMultiple) use the local view proxy only (as opposed to the local cache that might read data from a remote master space).
Data is not evicted from the local view.

Local View Considerations

Local View is a Read-Only Feature

The following operations are not supported when using local view, and should be performed directly on the master space:

  • write
  • writeMultiple
  • update
  • updateMultiple
  • replace
  • clear
  • Any operation under a transaction
  • take

Local Cache

OpenSpaces also allows you to configure a master-local space, simply by using the LocalCacheSpaceFactoryBean component. The factory exposes the same IJSpace implementation that a regular space component exposes, with the additional feature of having a local cache.

The following is an example of how a local cache can be configured:

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

<os-core:local-cache id="localCacheSpace" space="space" update-mode="PULL" >
    <os-core:properties>
        <props>
            <prop key="space-config.engine.cache_size">50000</prop>
            <prop key="space-config.engine.memory_usage.high_watermark_percentage">65</prop>
            <prop key="space-config.engine.memory_usage.write_only_block_percentage">63</prop>
            <prop key="space-config.engine.memory_usage.write_only_check_percentage">60</prop>
            <prop key="space-config.engine.memory_usage.low_watermark_percentage">55</prop>
        </props>
    </os-core:properties>
</os-core:local-cache>

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

<bean id="localCacheSpace" class="org.openspaces.core.space.cache.LocalCacheSpaceFactoryBean">
    <property name="space" ref="space" />
    <property name="updateMode" value="PULL" />
</bean>

Code
IJSpace space = // get Space either by injection or code creation
IJSpace localSpaceProxy = new LocalCacheSpaceConfigurer(space).updateMode(UpdateMode.PULL).localCache();
GigaSpace gigaspace = new GigaSpaceConfigurer(localSpaceProxy).gigaSpace();

Local Cache Considerations

Local Cache with External Data Source

When using the Master Local Space configuration with an External Data Source, it is important to make sure the following steps are accomplished:
1. Each POJO class should contain a SpaceVersion property.
2. In the database, you should add a column named VERSION_ID to the corresponding tables. If you are using Hibernate, add the versionId property to the HBM file.

Local Cache Memory Eviction

In order to configure the Local cache Eviction mechanism you should have the following tuned:

space-config.engine.cache_size
space-config.engine.memory_usage.high_watermark_percentage
space-config.engine.memory_usage.write_only_block_percentage
space-config.engine.memory_usage.write_only_check_percentage
space-config.engine.memory_usage.low_watermark_percentage
space-config.engine.memory_usage.eviction_batch_size
space-config.engine.memory_usage.retry_count
space-config.engine.memory_usage.explicit-gc
space-config.engine.memory_usage.retry_yield_time

See the Memory Management Facility for additional details how to configure the Memory Manager.

Having the space-config.engine.memory_usage.explicit-gc enabled is recommended only in special cases where there is high load on the system with large amount of concurrent users accessing the local cache where the amount of CPUs/Cores is relatively small.

Local Cache Memory Handling

There might be cases when the local cache would not be able to evict its data fast enough. This will result an Exception to be thrown at the client side. The reasons for this behavior might be very large objects stored within the local cache, large amount of concurrent access to the local cache or relatively small JVM heap. In such a case a RemoteException will be thrown.
You should catch this Exception and check its cause. If the cause is MemoryShortageException you should sleep for a while and let the client JVM to release the evicted memory and retry the operation. See below example:

GigaSpace gigaspace;
while(true)
{
	try
	{
		Object obj = gigaspace.read(template);
		break;
	}
	catch (Exception re) {
		if (re.getCause() instanceof MemoryShortageException)
		Thread.sleep(1000);
	}			
}
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence