Summary: OpenSpaces allows you to easily configure and use the space local view feature using the
LocalViewSpaceFactoryBean component and local cache using
LocalCacheSpaceFactoryBean.
Local ViewOpenSpaces 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 ClientOnce 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). Local View ConsiderationsLocal View is a Read-Only FeatureThe following operations are not supported when using local view, and should be performed directly on the master space:
Local CacheOpenSpaces 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 ConsiderationsLocal Cache with External Data SourceWhen using the Master Local Space configuration with an External Data Source, it is important to make sure the following steps are accomplished: Local Cache Memory EvictionIn 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.
Local Cache Memory HandlingThere 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. 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 |