SGF-15
+ made pool-name attribute mandatory
+ added strategy for pool retrieval
This commit is contained in:
costin
2010-09-01 17:06:58 +03:00
parent d736c302dd
commit ac96680848
6 changed files with 32 additions and 10 deletions

View File

@@ -16,6 +16,9 @@
package org.springframework.data.gemfire.client;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.data.gemfire.RegionFactoryBean;
import org.springframework.util.Assert;
import org.springframework.util.ObjectUtils;
@@ -29,10 +32,11 @@ import com.gemstone.gemfire.cache.client.Pool;
*
* @author Costin Leau
*/
public class ClientRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
public class ClientRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> implements BeanFactoryAware {
private Interest<K>[] interests;
private String poolName;
private BeanFactory beanFactory;
@Override
protected void postProcess(Region<K, V> region) {
@@ -51,6 +55,14 @@ public class ClientRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
@Override
protected void postProcess(AttributesFactory<K, V> attrFactory) {
// try to eagerly initialize the pool name, if defined as a bean
if (beanFactory.isTypeMatch(poolName, Pool.class)) {
if (log.isDebugEnabled()) {
log.debug("Found bean definition for pool '" + poolName + "'. Eagerly initializing it...");
}
beanFactory.getBean(poolName, Pool.class);
}
attrFactory.setPoolName(poolName);
}
@@ -77,7 +89,11 @@ public class ClientRegionFactoryBean<K, V> extends RegionFactoryBean<K, V> {
super.destroy();
}
public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
this.beanFactory = beanFactory;
}
/**
* Set the interests for this client region. Both key and regex interest are supported.
*

View File

@@ -79,7 +79,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
private boolean threadLocalConnections = PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS;
public Class<?> getObjectType() {
return Pool.class;
return (pool != null ? pool.getClass() : Pool.class);
}
public boolean isSingleton() {

View File

@@ -57,6 +57,7 @@ class ClientRegionParser extends AbstractSingleBeanDefinitionParser {
ParsingUtils.setPropertyValue(element, builder, "data-policy", "dataPolicy");
ParsingUtils.setPropertyValue(element, builder, "name", "name");
ParsingUtils.setPropertyValue(element, builder, "pool-name", "poolName");
String attr = element.getAttribute("cache-ref");
// add cache reference (fallback to default if nothing is specified)

View File

@@ -413,7 +413,7 @@ cache to differ from other caches.
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="pool-name" use="optional" type="xsd:string">
<xsd:attribute name="pool-name" use="required" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the pool used by this client.
@@ -452,6 +452,8 @@ The port number of the connection (between 1 and 65535 inclusive).
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.client.PoolFactoryBean"><![CDATA[
Defines a pool for connections from a client to a set of GemFire Cache Servers.
Note that in order to instantiate a pool, a GemFire cache needs to be already started.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>

View File

@@ -61,7 +61,7 @@ public class ClientRegionNamespaceTest {
assertEquals(Scope.LOCAL, TestUtils.readField("scope", fb));
}
//@Test
public void testComplexClient() throws Exception {
assertTrue(context.containsBean("complex"));
ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class);

View File

@@ -4,29 +4,32 @@
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
default-lazy-init="true"
xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<gfe:cache />
<gfe:client-region id="simple" />
<gfe:client-region id="simple" pool-name="gemfire-pool"/>
<gfe:client-region id="empty" name="publisher" data-policy="EMPTY"/>
<gfe:client-region id="empty" pool-name="gemfire-pool" name="publisher" data-policy="EMPTY"/>
<gfe:client-region id="complex">
<gfe:client-region id="complex" pool-name="gemfire-pool">
<gfe:cache-listener>
<ref bean="c-listener"/>
<bean class="org.springframework.data.gemfire.SimpleCacheListener"/>
</gfe:cache-listener>
<!--
<gfe:key-interest durable="true" result-policy="KEYS">
<bean id="key" class="java.lang.Object"/>
<bean id="key" class="java.lang.String"/>
</gfe:key-interest>
<gfe:regex-interest pattern=".*"/>
-->
</gfe:client-region>
<bean id="c-listener" class="org.springframework.data.gemfire.SimpleCacheListener"/>
<gfe:pool id="gemfire-pool" subscription-enabled="false">
<gfe:locator host="localhost" port="40403"/>
</gfe:pool>
</beans>