+ finished up docs on bootstrapping
+ added small improvement to RegionFactoryBean
This commit is contained in:
@@ -65,13 +65,88 @@
|
||||
</property>
|
||||
</bean>
|
||||
</beans>]]></programlisting>
|
||||
|
||||
|
||||
<para>It is worth pointing out again, that the cache settings apply only if the cache needs to be created, there is no opened cache in existence otherwise the existing cache
|
||||
will be used (and the configuration will simply be discarded).</para>
|
||||
</section>
|
||||
|
||||
<section id="bootstrap:region">
|
||||
<title>Configuring a GemFire <interfacename>Region</interfacename></title>
|
||||
|
||||
<para>Once the <interfacename>Cache</interfacename> is configured, one needs to configure one or more <interfacename>Region</interfacename>s for interacting with the distributed fabric.</para>
|
||||
<para>Once the <interfacename>Cache</interfacename> is configured, one needs to configure one or more <interfacename>Region</interfacename>s for interacting with the data
|
||||
fabric. In a similar manner to the <classname>CacheFactoryBean</classname>, the <classname>RegionFactoryBean</classname> allows existing <interfacename>Region</interfacename>s
|
||||
to retrieved or, in case they don't exist, created using various settings. One can specify the <interfacename>Region</interfacename> name, whether it will be destroyed on shutdown
|
||||
(acting as a temporary cache), the associated <interfacename>CacheLoader</interfacename>s, <interfacename>CacheListener</interfacename>s and <interfacename>CacheWriter</interfacename>s
|
||||
and if needed, the <interfacename>RegionAttributes</interfacename> for full customization.
|
||||
</para>
|
||||
|
||||
<para>Let us start with a simple region declaration, named <emphasis>basic</emphasis> using a nested cache declaration:</para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[<bean id="basic" class="org.springframework.data.gemfire.RegionFactoryBean">
|
||||
<property name="cache">
|
||||
<bean class="org.springframework.data.gemfire.CacheFactoryBean"/>
|
||||
</property>
|
||||
<property name="name" value="basic"/>
|
||||
</bean>]]></programlisting>
|
||||
|
||||
<para>Since the region bean definition name is usually the same with that of the cache, the <literal>name</literal> property can be omitted (the bean name will be used automatically).
|
||||
Additionally by using the name the <literal><ulink url="http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-p-namespace">p</ulink></literal> namespace,
|
||||
the configuration can be simplified even more:</para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:p="http://www.springframework.org/schema/p"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||
|
||||
<!-- shared cache across regions -->
|
||||
<bean id="cache" class="org.springframework.data.gemfire.CacheFactoryBean"/>
|
||||
|
||||
<!-- region named 'basic' -->
|
||||
<bean id="basic" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache"/>
|
||||
|
||||
<!-- region with a name different then the bean definition -->
|
||||
<bean id="root-region" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache" p:name="default-region"/>
|
||||
</beans>]]></programlisting>
|
||||
|
||||
<para>It is worth pointing out, that for the vast majority of cases configuring the cache loader, listener and writer through the Spring container is preferred since the same instances
|
||||
can be reused across multiple regions and additionally, the instances themselves can benefit from the container rich feature set:</para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[<bean id="cacheLogger" class="org.some.pkg.CacheLogger"/>
|
||||
<bean id="customized-region" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache">
|
||||
<property name="cacheListeners">
|
||||
<array>
|
||||
<ref name="cacheLogger"/>
|
||||
<bean class="org.some.other.pkg.SysoutLogger"/>
|
||||
</array>
|
||||
</property>
|
||||
<property name="cacheLoader"><bean class="org.some.pkg.CacheLoad"/></property>
|
||||
<property name="cacheWriter"><bean class="org.some.pkg.CacheWrite"/></property>
|
||||
</bean>
|
||||
|
||||
<bean id="local-region" class="org.springframework.data.gemfire.RegionFactoryBean" p:cache-ref="cache">
|
||||
<property name="cacheListeners" ref="cacheLogger"/>
|
||||
</bean>]]></programlisting>
|
||||
|
||||
<section id="bootstrap:region:client">
|
||||
<title>Configuring a <emphasis>client</emphasis> <interfacename>Region</interfacename> </title>
|
||||
|
||||
<para>For scenarios where a <emphasis>CacheServer</emphasis> is used and <emphasis>clients</emphasis> need to be configured, SGI offers a dedicated configuration class named:
|
||||
<classname>ClientRegionFactoryBean</classname>. This allows client <emphasis>interests</emphasis> to be registered in both key and regex form through <classname>Interest</classname>
|
||||
and <classname>RegexInterest</classname> classes in the <literal>org.springframework.data.gemfire</literal> package:</para>
|
||||
|
||||
<programlisting language="xml"><![CDATA[<bean id="interested-client" class="org.springframework.data.gemfire.ClientRegionFactoryBean" p:cache-ref="cache" p:name="client-region">
|
||||
<property name="interests">
|
||||
<array>
|
||||
<!-- key-based interest -->
|
||||
<bean class="org.springframework.data.gemfire.Interest" p:key="Vlaicu" p:policy="NONE"/>
|
||||
<!-- regex-based interest -->
|
||||
<bean class="org.springframework.data.gemfire.RegexInterest" p:key=".*" p:policy="KEYS" p:durable="true"/>
|
||||
</array>
|
||||
</property>
|
||||
</bean>]]></programlisting>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
</chapter>
|
||||
Reference in New Issue
Block a user