+ add support for region interest receive-values property
This commit is contained in:
Costin Leau
2011-09-22 10:28:40 +03:00
parent ac138654b6
commit 87506ef775
7 changed files with 84 additions and 10 deletions

View File

@@ -45,6 +45,7 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
private String beanName;
private String name, expression, from, imports;
private IndexType type = IndexType.FUNCTIONAL;
private boolean override = true;
public void afterPropertiesSet() throws Exception {
if (queryService == null) {
@@ -72,8 +73,23 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
private Index createIndex(QueryService queryService, String indexName) throws Exception {
Collection<Index> indexes = queryService.getIndexes();
Index old = null;
for (Index index : indexes) {
if (indexName.equals(index.getName())) {
if (!override) {
return index;
}
old = index;
break;
}
}
if (old != null) {
// compare indices
if (from.equals(old.getFromClause()) && expression.equals(old.getIndexedExpression())
&& type.equals(old.getType())) {
return index;
}
}
@@ -167,4 +183,11 @@ public class IndexFactoryBean implements InitializingBean, BeanNameAware, Factor
public void setType(IndexType type) {
this.type = type;
}
/**
* @param override the override to set
*/
public void setOverride(boolean override) {
this.override = override;
}
}

View File

@@ -153,10 +153,12 @@ public class ClientRegionFactoryBean<K, V> extends RegionLookupFactoryBean<K, V>
for (Interest<K> interest : interests) {
if (interest instanceof RegexInterest) {
// do the cast since it's safe
region.registerInterestRegex((String) interest.getKey(), interest.getPolicy(), interest.isDurable());
region.registerInterestRegex((String) interest.getKey(), interest.getPolicy(),
interest.isDurable(), interest.isReceiveValues());
}
else {
region.registerInterest(interest.getKey(), interest.getPolicy(), interest.isDurable());
region.registerInterest(interest.getKey(), interest.getPolicy(), interest.isDurable(),
interest.isReceiveValues());
}
}
}

View File

@@ -35,6 +35,7 @@ public class Interest<K> implements InitializingBean {
private K key;
private InterestResultPolicy policy = InterestResultPolicy.DEFAULT;
private boolean durable = false;
private boolean receiveValues = true;
public Interest() {
}
@@ -52,20 +53,25 @@ public class Interest<K> implements InitializingBean {
}
public Interest(K key, String policy, boolean durable) {
this.key = key;
this.policy = (InterestResultPolicy) constants.asObject(policy);
this.durable = durable;
afterPropertiesSet();
this(key, policy, false, true);
}
public Interest(K key, String policy, boolean durable, boolean receiveValues) {
this(key, (InterestResultPolicy) constants.asObject(policy), durable, receiveValues);
}
public Interest(K key, InterestResultPolicy policy, boolean durable) {
this(key, policy, durable, true);
}
public Interest(K key, InterestResultPolicy policy, boolean durable, boolean receiveValues) {
this.key = key;
this.policy = policy;
this.durable = durable;
this.receiveValues = receiveValues;
afterPropertiesSet();
}
public void afterPropertiesSet() {
Assert.notNull(key, "a non-null key is required");
}
@@ -135,4 +141,22 @@ public class Interest<K> implements InitializingBean {
public void setDurable(boolean durable) {
this.durable = durable;
}
/**
* Returns the type of values received by the listener.
*
* @return the receiveValues
*/
protected boolean isReceiveValues() {
return receiveValues;
}
/**
* Switches between the different entities received by the listener.
*
* @param receiveValues the receiveValues to set
*/
public void setReceiveValues(boolean receiveValues) {
this.receiveValues = receiveValues;
}
}

View File

@@ -145,5 +145,6 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser {
private void parseCommonInterestAttr(Element element, BeanDefinitionBuilder builder) {
ParsingUtils.setPropertyValue(element, builder, "durable", "durable");
ParsingUtils.setPropertyValue(element, builder, "result-policy", "policy");
ParsingUtils.setPropertyValue(element, builder, "receive-values", "receiveValues");
}
}

View File

@@ -911,6 +911,15 @@ NONE - Does not initialize the local cache.
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="receive-values" type="xsd:string" default="true" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether values are received with create and update events on keys of interest (true)
or only invalidations are received and the value will be received on the next get instead (false).
Default is true.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="pool">
@@ -1174,6 +1183,12 @@ The name of the index.]]></xsd:documentation>
<xsd:attribute name="expression" use="required" type="xsd:string"/>
<xsd:attribute name="from" use="required" type="xsd:string"/>
<xsd:attribute name="imports" use="optional" type="xsd:string"/>
<xsd:attribute name="override" use="optional" type="xsd:string" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the index is created even if there is an index with the same name (default) or not.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" default="gemfire-cache" use="optional">
<xsd:annotation>

View File

@@ -36,7 +36,7 @@
<property name="interests">
<array>
<bean class="org.springframework.data.gemfire.client.Interest" p:key="Vlaicu" p:policy="NONE"/>
<bean class="org.springframework.data.gemfire.client.RegexInterest" p:key=".*" p:policy="KEYS" p:durable="true"/>
<bean class="org.springframework.data.gemfire.client.RegexInterest" p:key=".*" p:policy="KEYS" p:durable="true" p:receive-values="false"/>
</array>
</property>
</bean>