Current changes for region subscriptions.
This commit is contained in:
@@ -119,6 +119,7 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser {
|
||||
}
|
||||
|
||||
ParsingUtils.parseExpiration(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseSubscription(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseEviction(parserContext, element, attrBuilder);
|
||||
ParsingUtils.parseMembershipAttributes(parserContext, element, attrBuilder);
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ import com.gemstone.gemfire.cache.Scope;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author David Turanski
|
||||
* @author Lyndon Adams
|
||||
*/
|
||||
abstract class ParsingUtils {
|
||||
|
||||
@@ -256,6 +257,36 @@ abstract class ParsingUtils {
|
||||
attrBuilder.addPropertyValue("evictionAttributes", evictionDefBuilder.getBeanDefinition());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses the subscription sub-element. Populates the given attribute factory
|
||||
* with the proper attributes.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @param parserContext
|
||||
* @param element
|
||||
* @param attrBuilder
|
||||
* @return true if parsing actually occured, false otherwise
|
||||
*/
|
||||
static boolean parseSubscription(ParserContext parserContext, Element element, BeanDefinitionBuilder attrBuilder) {
|
||||
Element subscriptionElement = DomUtils.getChildElementByTagName(element, "subscription");
|
||||
|
||||
if (subscriptionElement == null)
|
||||
return false;
|
||||
|
||||
BeanDefinitionBuilder subscriptionDefBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(SubscriptionAttributesFactoryBean.class);
|
||||
|
||||
// do manual conversion since the enum is not public
|
||||
String attr = subscriptionElement.getAttribute("type");
|
||||
if (StringUtils.hasText(attr)) {
|
||||
subscriptionDefBuilder.addPropertyValue("type", SubscriptionType.valueOf(attr.toUpperCase()));
|
||||
}
|
||||
|
||||
attrBuilder.addPropertyValue("subscriptionAttributes", subscriptionDefBuilder.getBeanDefinition());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static void parseTransportFilters(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
Element transportFilterElement = DomUtils.getChildElementByTagName(element, "transport-filter");
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.SubscriptionAttributes;
|
||||
|
||||
/**
|
||||
* Simple utility class used for defining nested factory-method like definitions w/o polluting the container with useless beans.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
* @since 12 March 2013
|
||||
*/
|
||||
public class SubscriptionAttributesFactoryBean implements FactoryBean<SubscriptionAttributes>, InitializingBean {
|
||||
|
||||
SubscriptionAttributes subscriptionAttri;
|
||||
InterestPolicy policy;
|
||||
SubscriptionType type = SubscriptionType.ALL;
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet()
|
||||
*/
|
||||
@Override
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
if( policy == null ){
|
||||
policy = InterestPolicy.DEFAULT;
|
||||
}
|
||||
subscriptionAttri = createAttributes();
|
||||
}
|
||||
|
||||
private SubscriptionAttributes createAttributes(){
|
||||
switch( type ){
|
||||
case ALL :
|
||||
policy = InterestPolicy.ALL;
|
||||
break;
|
||||
case CACHE_CONTENT :
|
||||
policy = InterestPolicy.CACHE_CONTENT;
|
||||
break;
|
||||
default :
|
||||
policy = InterestPolicy.DEFAULT;
|
||||
}
|
||||
return new SubscriptionAttributes( policy );
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObject()
|
||||
*/
|
||||
@Override
|
||||
public SubscriptionAttributes getObject() throws Exception {
|
||||
return subscriptionAttri;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#getObjectType()
|
||||
*/
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return ( subscriptionAttri != null ) ? subscriptionAttri.getClass() : SubscriptionAttributes.class;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.beans.factory.FactoryBean#isSingleton()
|
||||
*/
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public InterestPolicy getPolicy() {
|
||||
return policy;
|
||||
}
|
||||
|
||||
public SubscriptionType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setPolicy(InterestPolicy policy) {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
public void setType(SubscriptionType type) {
|
||||
this.type = type;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
/**
|
||||
* Simple enumeration for the various GemFire subscription types.
|
||||
*
|
||||
* @author Lyndon Adams
|
||||
*
|
||||
*/
|
||||
enum SubscriptionType {
|
||||
ALL, CACHE_CONTENT;
|
||||
}
|
||||
@@ -974,6 +974,24 @@ up to date copy of the data.
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="baseRegionType">
|
||||
<xsd:sequence minOccurs="1" maxOccurs="1">
|
||||
<xsd:element name="subscription" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Subscription policy for the replicated region.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="type"
|
||||
type="subscriptionPolicyType" fixed="ALL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The action to take when performing subscription.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="eviction" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
@@ -1075,6 +1093,24 @@ Defines a GemFire local region instance. Each local region is scoped only to the
|
||||
<xsd:complexContent>
|
||||
<xsd:extension base="baseRegionType">
|
||||
<xsd:sequence minOccurs="1" maxOccurs="1">
|
||||
<xsd:element name="subscription" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Subscription policy for the replicated region.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="type"
|
||||
type="subscriptionPolicyType" fixed="ALL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The action to take when performing subscription.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="eviction" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
@@ -1226,6 +1262,24 @@ Specifies the number of buckets to allocate to the fixed partition
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="subscription" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Subscription policy for the replicated region.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="type"
|
||||
type="subscriptionPolicyType" fixed="ALL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The action to take when performing subscription.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="eviction" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
@@ -1249,7 +1303,25 @@ The action to take when performing eviction.
|
||||
</xsd:extension>
|
||||
</xsd:complexContent>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:element>
|
||||
<xsd:element name="subscription" minOccurs="0"
|
||||
maxOccurs="1">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Subscription policy for the replicated region.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="type"
|
||||
type="subscriptionPolicyType" fixed="ALL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
The action to take when performing subscription.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:sequence>
|
||||
<xsd:attributeGroup ref="distributedRegionAttributes" />
|
||||
<xsd:attribute name="copies" use="optional"
|
||||
@@ -1503,6 +1575,38 @@ reclaim memory.
|
||||
</xsd:enumeration>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
|
||||
<xsd:simpleType name="subscriptionPolicyType">
|
||||
<xsd:restriction base="xsd:string">
|
||||
<xsd:enumeration value="ALL">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This subscriber is interested in all data. More specifically operations done in this cache and distributed operations done in remote caches.
|
||||
When combined with DataPolicy.EMPTY this region will receive events for every distributed operation but will not store the data.
|
||||
|
||||
When combined with DataPolicy.NORMAL or DataPolicy.PRELOADED this region will accept Region.create(Object, Object) operations done remotely. Without the ALL interest policy, NORMAL and PRELOADED ignore creates that the region does not have an existing entry for.
|
||||
|
||||
When combined with the replication policies this interest has no effect.
|
||||
|
||||
When combined with DataPolicy.PARTITION this interest policy causes cache listeners to be notified of changes regardless of the physical location of the data affected. That is, a listener in a VM using this policy will receive notification of all changes to the partitioned region.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:enumeration>
|
||||
<xsd:enumeration value="CACHE_CONTENT">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
This subscriber is interested in data that is already in its cache. More specifically operations done in this cache and distributed operations done in remote caches.
|
||||
When combined with DataPolicy.EMPTY this region will never receive events for distributed operations since its content is always empty. It will continue to get events for operations done locally.
|
||||
|
||||
When combined with DataPolicy.NORMAL or DataPolicy.PRELOADED this region will accept remote operations done to entries it already has in its cache.
|
||||
|
||||
When combined with the replication policies * this interest has no effect.
|
||||
|
||||
When combined with DataPolicy.PARTITION this interest policy causes cache listeners to be notified in the VM holding the affected data. That is, listeners are only notified if the affected* key-value pair is in the same process as the listener. ]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:enumeration>
|
||||
</xsd:restriction>
|
||||
</xsd:simpleType>
|
||||
<!-- -->
|
||||
<xsd:complexType name="baseDiskStoreType">
|
||||
<xsd:sequence>
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2010-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.data.gemfire.config;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.gemfire.test.GemfireTestRunner;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* @author Lyndon Adams
|
||||
*/
|
||||
@RunWith(GemfireTestRunner.class)
|
||||
@ContextConfiguration("/org/springframework/data/gemfire/config/subscription-ns.xml")
|
||||
public class CacheSubscriptionTest{
|
||||
@Autowired ApplicationContext ctx;
|
||||
|
||||
@Test
|
||||
public void testRRSubscription() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPRSubscription() throws Exception {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@
|
||||
<property name="cache" ref="gemfireCache"/>
|
||||
<property name="dataPolicy" value="REPLICATE_PERSISTENT"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
<gfe:client-region data-policy="NORMAL" name="ChallengeQuestions" id="challengeQuestionsRegion"/>
|
||||
<gfe:pool>
|
||||
<gfe:locator host="localhost" port="1234"/>
|
||||
</gfe:pool>
|
||||
</gfe:pool>
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?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"
|
||||
default-lazy-init="false"
|
||||
xmlns:gfe="http://www.springframework.org/schema/gemfire"
|
||||
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">
|
||||
|
||||
<gfe:cache/>
|
||||
<gfe:replicated-region id="rr">
|
||||
<gfe:subscription type="ALL"/>
|
||||
</gfe:replicated-region>
|
||||
|
||||
<gfe:partitioned-region id="pp">
|
||||
<gfe:subscription type="ALL"/>
|
||||
</gfe:partitioned-region>
|
||||
|
||||
<gfe:client-region id="cc">
|
||||
<gfe:subscription type="ALL"/>
|
||||
</gfe:client-region>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user