+ add subscription support
+ add namespace support + integration tests
This commit is contained in:
Costin Leau
2011-05-16 20:08:22 +03:00
parent d0fcdf8219
commit 25db19c191
10 changed files with 1142 additions and 11 deletions

View File

@@ -32,6 +32,7 @@ import org.w3c.dom.Element;
*/
class CacheParser extends AbstractSingleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return CacheFactoryBean.class;
}

View File

@@ -0,0 +1,86 @@
/*
* Copyright 2011 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.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.data.gemfire.server.CacheServerFactoryBean;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
/**
* Namespace parser for "cache-server" element.
*
* @author Costin Leau
*/
class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return CacheServerFactoryBean.class;
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
String name = super.resolveId(element, definition, parserContext);
if (!StringUtils.hasText(name)) {
name = "gemfire-server";
}
return name;
}
@Override
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
return super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName())
&& !"cache-ref".equals(attribute.getName());
}
@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
String attr = element.getAttribute("cache-ref");
// add cache reference (fallback to default if nothing is specified)
builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache"));
attr = element.getAttribute("groups");
if (StringUtils.hasText(attr)) {
builder.addPropertyValue("serverGroups", StringUtils.commaDelimitedListToStringArray(attr));
}
parseSubscription(builder, element);
}
private void parseSubscription(BeanDefinitionBuilder builder, Element element) {
Element subConfig = DomUtils.getChildElementByTagName(element, "subscription-config");
if (subConfig == null) {
return;
}
ParsingUtils.setPropertyValue(subConfig, builder, "capacity", "subscriptionCapacity");
ParsingUtils.setPropertyValue(subConfig, builder, "disk-store", "subscriptionDiskStore");
String attr = element.getAttribute("eviction-type");
if (StringUtils.hasText(attr)) {
builder.addPropertyValue("subscriptionEvictionPolicy", attr.toUpperCase());
}
}
}

View File

@@ -32,6 +32,7 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport {
registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser());
registerBeanDefinitionParser("client-region", new ClientRegionParser());
registerBeanDefinitionParser("pool", new PoolParser());
registerBeanDefinitionParser("cache-server", new CacheServerParser());
registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser());
}

View File

@@ -24,11 +24,13 @@ import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.SmartLifecycle;
import org.springframework.core.io.Resource;
import org.springframework.util.Assert;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.InterestRegistrationListener;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
import com.gemstone.gemfire.cache.server.ServerLoadProbe;
/**
@@ -36,8 +38,8 @@ import com.gemstone.gemfire.cache.server.ServerLoadProbe;
*
* @author Costin Leau
*/
public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
InitializingBean, DisposableBean, SmartLifecycle {
public class CacheServerFactoryBean implements FactoryBean<CacheServer>, InitializingBean, DisposableBean,
SmartLifecycle {
private boolean autoStartup = true;
@@ -55,10 +57,15 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
private String bindAddress = CacheServer.DEFAULT_BIND_ADDRESS;
private String hostNameForClients = CacheServer.DEFAULT_HOSTNAME_FOR_CLIENTS;
private Set<InterestRegistrationListener> listeners = Collections.emptySet();
private SubscriptionEvictionPolicy evictionPolicy = SubscriptionEvictionPolicy.valueOf(ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY.toUpperCase());
private int subscriptionCapacity = ClientSubscriptionConfig.DEFAULT_CAPACITY;
private Resource subscriptionDiskStore;
private Cache cache;
private CacheServer cacheServer;
public CacheServer getObject() {
return cacheServer;
}
@@ -71,9 +78,9 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
return true;
}
public void afterPropertiesSet() {
public void afterPropertiesSet() throws IOException {
Assert.notNull(cache, "cache is required");
cacheServer = cache.addCacheServer();
cacheServer.setBindAddress(bindAddress);
cacheServer.setGroups(serverGroups);
@@ -88,11 +95,17 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
cacheServer.setNotifyBySubscription(notifyBySubscription);
cacheServer.setPort(port);
cacheServer.setSocketBufferSize(socketBufferSize);
for (InterestRegistrationListener listener : listeners) {
cacheServer.registerInterestRegistrationListener(listener);
}
}
// client config
ClientSubscriptionConfig config = cacheServer.getClientSubscriptionConfig();
config.setCapacity(subscriptionCapacity);
config.setEvictionPolicy(evictionPolicy.name().toLowerCase());
config.setDiskStoreName(subscriptionDiskStore.getFile().getCanonicalPath());
start();
}
@@ -128,7 +141,7 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
}
public void stop() {
if (cacheServer != null){
if (cacheServer != null) {
cacheServer.stop();
}
}
@@ -196,4 +209,22 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>,
public void setCache(Cache cache) {
this.cache = cache;
}
/**
* @param evictionPolicy the evictionPolicy to set
*/
public void setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy evictionPolicy) {
this.evictionPolicy = evictionPolicy;
}
/**
* @param subscriptionCapacity the subscriptionCapacity to set
*/
public void setSubscriptionCapacity(int subscriptionCapacity) {
this.subscriptionCapacity = subscriptionCapacity;
}
public void setSubscriptionDiskStore(Resource resource) {
this.subscriptionDiskStore = resource;
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2011 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.server;
import com.gemstone.gemfire.cache.server.CacheServer;
/**
* Enumeration of the various client subscription policies for {@link CacheServer}.
*
* @author Costin Leau
*/
public enum SubscriptionEvictionPolicy {
NONE, MEM, ENTRY
}

View File

@@ -1,2 +1,3 @@
http\://www.springframework.org/schema/gemfire/spring-gemfire-1.0.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd
http\://www.springframework.org/schema/gemfire/spring-gemfire.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd
http\://www.springframework.org/schema/gemfire/spring-gemfire-1.1.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd
http\://www.springframework.org/schema/gemfire/spring-gemfire.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd

View File

@@ -0,0 +1,906 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xsd:schema xmlns="http://www.springframework.org/schema/gemfire"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:tool="http://www.springframework.org/schema/tool"
targetNamespace="http://www.springframework.org/schema/gemfire"
elementFormDefault="qualified"
attributeFormDefault="unqualified"
version="1.1">
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
<xsd:annotation>
<xsd:documentation><![CDATA[
Namespace support for the Spring GemFire project.
]]></xsd:documentation>
</xsd:annotation>
<xsd:element name="cache">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.CacheFactoryBean"><![CDATA[
Defines a GemFire Cache instance used for creating or retrieving 'regions'.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.Cache" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the cache definition (by default "gemfire-cache").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-xml-location" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation source="org.springframework.core.io.Resource"><![CDATA[
The location of the GemFire cache xml file, as a Spring resource location: a URL, a "classpath:" pseudo URL,
or a relative file path.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="properties-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation source="java.util.Properties"><![CDATA[
The bean name of a Java Properties object that will be used for property substitution. For loading properties
consider using a dedicated utility such as the <util:*/> namespace and its 'properties' element.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="transaction-manager">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.GemfireTransactionManager"><![CDATA[
Defines a GemFire Transaction Manager instance for a single GemFire cache.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the transaction manager definition (by default "gemfire-transaction-manager").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" default="gemfire-cache" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the bean defining the GemFire cache (by default 'gemfire-cache').
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="copy-on-read" type="xsd:string" default="true" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the cache returns direct references or copies of the objects (default) it manages.
While copies imply additional work for every fetch operation, direct references can cause dirty reads
across concurrent threads in the same VM, whether or not transactions are used.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<!-- nested bean definition -->
<xsd:complexType name="beanDeclarationType">
<xsd:sequence>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="1" processContents="skip">
<xsd:annotation>
<xsd:documentation><![CDATA[
Inner bean definition. The nested declaration serves as an alternative to bean references (using
both in the same definition) is illegal.
]]></xsd:documentation>
</xsd:annotation>
</xsd:any>
</xsd:sequence>
<xsd:attribute name="ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the bean referred by this declaration. If no reference exists, use an inner bean declaration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="basicRegionType">
<xsd:annotation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:attribute name="id" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The id of the region bean definition.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the region definition. If no specified, it will have the value of the id attribute (that is, the bean name).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" default="gemfire-cache" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the bean defining the GemFire cache (by default 'gemfire-cache').
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="readOnlyRegionType" abstract="true">
<xsd:complexContent>
<xsd:extension base="basicRegionType">
<xsd:sequence>
<xsd:element name="cache-listener" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation source="com.gemstone.gemfire.cache.CacheListener"><![CDATA[
A cache listener definition for this region. A cache listener handles region or entry related events (that occur after
various operations on the region). Multiple listeners can be declared in a nested manner.
Note: Avoid the risk of deadlock. Since the listener is invoked while holding a lock on the entry generating the event,
it is easy to generate a deadlock by interacting with the region. For this reason, it is highly recommended to use some
other thread for accessing the region and not waiting for it to complete its task.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.CacheListener"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence>
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="skip">
<xsd:annotation>
<xsd:documentation><![CDATA[
Inner bean definition of the cache listener.
]]></xsd:documentation>
</xsd:annotation>
</xsd:any>
</xsd:sequence>
<xsd:attribute name="ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the cache listener bean referred by this declaration. Used as a convenience method. If no reference exists,
use inner bean declarations.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="disk-store" type="diskStoreType" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Disk storage configuration for the defined region.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="persistent" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the defined region is persistent or not. GemFire ensures that all the data you put into a region that
is configured for persistence will be written to disk in a way that it can be recovered the next time you create the
region. This allows data to be recovered after a machine or process failure or after an orderly shutdown and restart
of GemFire.
Default is false, meaning the regions are not persisted.
Note: Persistence for partitioned regions is supported only from GemFire 6.5 onwards.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="destroy" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the defined region should be destroyed or not at shutdown. Destroy cascades to all entries and subregions.
After the destroy, this region object can not be used any more and any attempt to use this region object will get
RegionDestroyedException.
Default is false, meaning that regions are not destroyed.
Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="close" type="xsd:string" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the defined region should be closed or not at shutdown. Close performs a local destroy but leaves behind the region
disk files. Additionally it notifies the listeners and callbacks.
Default is true, meaning the regions are closed.
Note: Regions are automatically closed when cache closes.
Note: destroy and close are mutually exclusive. Enabling one will automatically disable the other.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="statistics" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether statistics are enabled or disabled for this region and its entries.
Default is false, meaning statistics are disabled.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="regionType">
<xsd:complexContent>
<xsd:extension base="readOnlyRegionType">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element name="cache-loader" minOccurs="0" maxOccurs="1" type="beanDeclarationType">
<xsd:annotation>
<xsd:documentation source="com.gemstone.gemfire.cache.CacheLoader"><![CDATA[
The cache loader definition for this region. A cache loader allows data to be placed into a region.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.CacheLoader"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="cache-writer" minOccurs="0" maxOccurs="1" type="beanDeclarationType">
<xsd:annotation>
<xsd:documentation source="com.gemstone.gemfire.cache.CacheWriter"><![CDATA[
The cache writer definition for this region. A cache writer acts as a dedicated synchronous listener that is notified
before a region or an entry is modified. A typical example would be a writer that updates the database.
Note: Only one CacheWriter is invoked. GemFire will always prefer the local one (if it exists) otherwise it will
arbitrarily pick one.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.CacheWriter"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="lookup-region" type="basicRegionType">
<xsd:annotation>
<xsd:documentation><![CDATA[[
Looks up an existing, working, GemFire region. Typically regions are defined through GemFire own configuration, the
cache.xml. If the region does not exist, an exception will be thrown.
For defining regions, consider the region elements.
]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="replicated-region">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.RegionFactoryBean"><![CDATA[
Defines a GemFire replicated region instance. Each replicated region contains a complete copy of the data.
As well as high availability, replication provides excellent performance as each region contains a complete,
up to date copy of the data.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="regionType">
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="eviction" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Eviction policy for the partitioned region.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="evictionType">
<xsd:attribute name="action" type="evictionActionType" fixed="OVERFLOW_TO_DISK">
<xsd:annotation>
<xsd:documentation><![CDATA[
The action to take when performing eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="partitioned-region">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.RegionFactoryBean"><![CDATA[
Defines a GemFire partitioned region instance. Through partitioning, the data is split across regions.
Partitioning is useful when the amount of data to store is too large for one member to hold and work
with as if it were a single entity. One can configure the partitioned region to store redundant copies
in different members, for high availability in case of an application failure.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="regionType">
<xsd:sequence>
<xsd:element name="partition-resolver" minOccurs="0" maxOccurs="1" type="beanDeclarationType">
<xsd:annotation>
<xsd:documentation source="com.gemstone.gemfire.cache.PartitionResolver"><![CDATA[
The partition resolver definition for this region, allowing for custom partitioning. GemFire uses the resolver to
colocate data based on custom criterias (such as colocating trades by month and year).
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.PartitionResolver"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element name="eviction" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Eviction policy for the partitioned region.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="evictionType">
<xsd:attribute name="action" type="evictionActionType" default="LOCAL_DESTROY">
<xsd:annotation>
<xsd:documentation><![CDATA[
The action to take when performing eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="copies" default="0" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The number of copies for each partition for high-availability. By default, no copies are created meaning there is no
redundancy. Each copy provides extra backup at the expense of extra storages.
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:byte">
<xsd:minInclusive value="0"/>
<xsd:maxInclusive value="3"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="colocated-with" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the partitioned region with which this newly created partitioned region is colocated.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="local-max-memory" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The maximum amount of memory, in megabytes, to be used by the region in this process. If not set, a default of 90%
of available heap is used.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="total-max-memory" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The maximum amount of memory, in megabytes, to be used by the region in all process.
Note: This setting must be the same in all processes using the region.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="total-buckets" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The total number of hash buckets to be used by the region in all processes.
A bucket is the smallest unit of data management in a partitioned region. Entries are stored in buckets and buckets may
move from one VM to another. Buckets may also have copies, depending on redundancy to provide high availability in the
face of VM failure.
The number of buckets should be prime and as a rough guide at the least four times the number of partition VMs. However
, there is significant overhead to managing a bucket, particularly for higher values of redundancy.
Note: This setting must be the same in all processes using the region.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="recovery-delay" type="xsd:string" default="-1" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The delay in milliseconds that existing members will wait before satisfying redundancy after another member crashes.
-1 (the default) indicates that redundancy will not be recovered after a failure.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="startup-recovery-delay" type="xsd:string" default="-1" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The delay in milliseconds that new members will wait before satisfying redundancy. -1 indicates that adding new members
will not trigger redundancy recovery. The default is to recover redundancy immediately when a new member is added.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="evictionType">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element name="object-sizer" type="beanDeclarationType">
<xsd:annotation>
<xsd:documentation><![CDATA[
Entity computing sizes for objects stored into the grid.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.util.ObjectSizer" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="type" default="ENTRY_COUNT">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="ENTRY_COUNT">
<xsd:annotation>
<xsd:documentation><![CDATA[
Considers the number of entries in the region before performing an eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="MEMORY_SIZE">
<xsd:annotation>
<xsd:documentation><![CDATA[
Considers the amount of memory consumed by the region before performing an eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="HEAP_PERCENTAGE">
<xsd:annotation>
<xsd:documentation><![CDATA[
Considers the amount of heap used (through the GemFire resource manager) before performing an eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="threshold" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
The threshold (or limit) against which the eviction algorithm runs. Once the threashold is reached, eviction is
performed.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:simpleType name="evictionActionType">
<xsd:restriction base="xsd:string">
<xsd:enumeration value="LOCAL_DESTROY">
<xsd:annotation>
<xsd:documentation><![CDATA[
The LRU (least-recently-used) region entries is locally destroyed.
Note: this option is not compatible with replicated regions (as it render the replica region incomplete).
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
<xsd:enumeration value="OVERFLOW_TO_DISK">
<xsd:annotation>
<xsd:documentation><![CDATA[
The LRU (least-recently-used) region entry values are written to disk and nulled-out in the member to
reclaim memory.
]]></xsd:documentation>
</xsd:annotation>
</xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
<xsd:complexType name="diskStoreType">
<xsd:sequence>
<xsd:element name="disk-dir" minOccurs="0" maxOccurs="unbounded">
<xsd:complexType>
<xsd:attribute name="location" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
Directory on the file system for storing data.
Note: the directory must already exist.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="max-size" type="xsd:string" default="10240">
<xsd:annotation>
<xsd:documentation><![CDATA[
The maximum size (in megabytes) of data stored in each directory. Default is 10240 MB (10 gigabytes).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="synchronous-write" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether the writing to the disk si synchronous or not. Default is false, meaning asynchronous writing.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-compact" type="xsd:string" default="true">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether or not the operation logs are automatically compacted or not. Default is true.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<!--
<xsd:attribute name="compaction-threshold" default="50">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the threshold at which an oplog will become compactable. Until it reaches this threshold the oplog will not be
compacted. The threshold is a percentage in the range 0..100. When the amount of garbage in an oplog exceeds this
percentage then when a compaction is done this garbage will be cleaned up freeing up disk space. Garbage is created
by entry destroys, entry updates, and region destroys.
]]>
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:short">
<xsd:minExclusive value="0"/>
<xsd:maxExclusive value="100"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
-->
<xsd:attribute name="max-oplog-size" type="xsd:string" default="1024">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the maximum size in megabytes a single oplog (operation log) is allowed to be. When an oplog is created this
amount of file space will be immediately reserved.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="time-interval" type="xsd:string" default="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Sets the number of milliseconds that can elapse before unwritten data is written to disk.
It is considered only for asynchronous writing.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="queue-size" type="xsd:string" default="0">
<xsd:annotation>
<xsd:documentation><![CDATA[
The maximum number of operations that can be asynchronously queued. Once this many pending async operations have been
queued async ops will begin blocking until some of the queued ops have been flushed to disk.
Considered only for asynchronous writing.
]]>
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="client-region">
<xsd:annotation>
<xsd:documentation source="org.springframework.data.gemfire.client.ClientRegionFactoryBean"><![CDATA[
Defines a GemFire client region instance. A client region is connected to a (long-lived) farm of GemFire servers from
which it receives its data. The client can hold some data locally or forward all requests to the server.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.Region" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="readOnlyRegionType">
<xsd:sequence>
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element name="key-interest">
<xsd:annotation>
<xsd:documentation><![CDATA[
Key based interest. If the key is a List, then all the keys in the List will be registered. The key can also be the
special token 'ALL_KEYS', which will register interest in all keys in the region. In effect, this will cause an update
to any key in this region in the CacheServer to be pushed to the client.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="interestType">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:any namespace="##other" minOccurs="0" maxOccurs="unbounded" processContents="skip">
<xsd:annotation>
<xsd:documentation><![CDATA[
Inner bean definition of the client key interest.
]]></xsd:documentation>
</xsd:annotation>
</xsd:any>
</xsd:sequence>
<xsd:attribute name="key-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the client key interest bean referred by this declaration. Used as a convenience method. If no reference exists,
use the inner bean declaration.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="regex-interest">
<xsd:annotation>
<xsd:documentation><![CDATA[
Regular expression based interest. If the pattern is '.*' then all keys of any type will be pushed to the client.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="interestType">
<xsd:attribute name="pattern" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:choice>
<xsd:element name="eviction" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
Eviction policy for the partitioned region.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="evictionType">
<xsd:attribute name="action" type="evictionActionType" default="LOCAL_DESTROY">
<xsd:annotation>
<xsd:documentation><![CDATA[
The action to take when performing eviction.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="data-policy" use="optional" default="NORMAL">
<xsd:annotation>
<xsd:documentation><![CDATA[
The data policy for this client. Can be either 'EMPTY' or 'NORMAL' (the default). In case persistence or overflow are
configured for this region, this parameter will be ignored.
EMPTY - causes data to never be stored in local memory. The region will always appear empty. It can be used to for zero
footprint producers that only want to distribute their data to others and for zero footprint consumers that only want
to see events.
NORMAL - causes data that this region is interested in to be stored in local memory. It allows the contents in this
cache to differ from other caches.
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="EMPTY"/>
<xsd:enumeration value="NORMAL"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="pool-name" use="required" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the pool used by this client.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="connectionType">
<xsd:attribute name="host" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[
The host name or ip address of the connection.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="port">
<xsd:annotation>
<xsd:documentation><![CDATA[
The port number of the connection (between 1 and 65535 inclusive).
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string"/>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="interestType" abstract="true">
<xsd:attribute name="durable" type="xsd:string" default="false" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates whether or not the registered interest is durable or not. Default is false.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="result-policy" default="KEYS_VALUES" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The result policy for this interest. Can be one of 'KEYS' or 'KEYS_VALUES' (the default) or 'NONE'.
KEYS - Initializes the local cache with the keys satisfying the request.
KEYS-VALUES - initializes the local cache with the keys and current values satisfying the request.
NONE - Does not initialize the local cache.
]]></xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="KEYS"/>
<xsd:enumeration value="KEYS_VALUES"/>
<xsd:enumeration value="NONE"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="pool">
<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>
<tool:exports type="com.gemstone.gemfire.cache.client.Pool" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:element name="locator" type="connectionType" minOccurs="1" maxOccurs="unbounded"/>
<xsd:element name="server" type="connectionType" minOccurs="1" maxOccurs="unbounded"/>
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the pool definition (by default "gemfire-pool").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="free-connection-timeout" use="optional" type="xsd:string"/>
<xsd:attribute name="idle-timeout" use="optional" type="xsd:string"/>
<xsd:attribute name="load-conditioning-interval" use="optional" type="xsd:string"/>
<xsd:attribute name="max-connections" use="optional" type="xsd:string"/>
<xsd:attribute name="min-connections" use="optional" type="xsd:string"/>
<xsd:attribute name="ping-interval" use="optional" type="xsd:string"/>
<xsd:attribute name="read-timeout" use="optional" type="xsd:string"/>
<xsd:attribute name="retry-attempts" use="optional" type="xsd:string"/>
<xsd:attribute name="server-group" use="optional" type="xsd:string"/>
<xsd:attribute name="socket-buffer-size" use="optional" type="xsd:string"/>
<xsd:attribute name="statistic-interval" use="optional" type="xsd:string"/>
<xsd:attribute name="subscription-ack-interval" use="optional" type="xsd:string"/>
<xsd:attribute name="subscription-enabled" use="optional" type="xsd:string"/>
<xsd:attribute name="subscription-message-tracking-timeout" use="optional" type="xsd:string"/>
<xsd:attribute name="subscription-redundancy" use="optional" type="xsd:string"/>
<xsd:attribute name="thread-local-connections" use="optional" type="xsd:string"/>
</xsd:complexType>
</xsd:element>
<xsd:element name="cache-server">
<xsd:annotation>
<xsd:documentation
source="org.springframework.data.gemfire.server.CacheServerFactoryBean"><![CDATA[
Defines a Cache Server for feeding data to remote gemfire clients to a server GemFire Cache Servers.
Note: In order to instantiate a cacheserver, a GemFire cache needs to be avaialble in the VM.
]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:exports type="com.gemstone.gemfire.cache.server.CacheServer" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
<xsd:complexType>
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element name="subscription-config" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation><![CDATA[
The client subscription configuration that is used to control a clients use of server resources towards notification queues.
]]></xsd:documentation>
</xsd:annotation>
<xsd:complexType>
<xsd:attribute name="eviction-type" use="optional" default="NONE">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="NONE"/>
<xsd:enumeration value="MEM"/>
<xsd:enumeration value="ENTRY"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="capacity" use="optional" default="1" type="xsd:string"/>
<xsd:attribute name="disk-store" use="optional" default="." type="xsd:string"/>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:ID" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[The name of the cache server definition (by default "gemfire-server").]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="auto-startup" use="optional" type="xsd:string" default="true" />
<xsd:attribute name="bind-address" use="optional" type="xsd:string" />
<xsd:attribute name="port" use="optional" type="xsd:string" default="40404">
<xsd:annotation>
<xsd:documentation><![CDATA[The port number of the server.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="host-name-for-clients" use="optional" type="xsd:string" />
<xsd:attribute name="load-poll-interval" use="optional" type="xsd:string" default="5000" />
<xsd:attribute name="max-connections" use="optional" type="xsd:string" default="800" />
<xsd:attribute name="max-threads" use="optional" type="xsd:string" default="0" />
<xsd:attribute name="max-message-count" use="optional" type="xsd:string" default="230000" />
<xsd:attribute name="max-time-between-pings" use="optional" type="xsd:string" default="60000" />
<xsd:attribute name="message-time-to-live" use="optional" type="xsd:string" default="180" />
<xsd:attribute name="socket-buffer-size" use="optional" type="xsd:string" default="32768" />
<xsd:attribute name="notify-by-subscription" use="optional" type="xsd:boolean" default="true" />
<xsd:attribute name="groups" use="optional" type="xsd:string" default="">
<xsd:annotation>
<xsd:documentation><![CDATA[
The server groups that this server will be a member of given as a comma separated values list.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="load-probe-ref" use="optional" type="xsd:string">
<xsd:annotation>
<xsd:documentation><![CDATA[The name of the bean defining the CacheServer Load Probe.]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" default="gemfire-cache" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[The name of the bean defining the GemFire cache (by default 'gemfire-cache').]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
</xsd:schema>

View File

@@ -0,0 +1,47 @@
/*
* Copyright 2011 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.data.gemfire.RecreatingContextTest;
import com.gemstone.gemfire.cache.server.CacheServer;
/**
*
* @author Costin Leau
*/
public class CacheServerNamespaceTest extends RecreatingContextTest {
@Override
protected String location() {
return "org/springframework/data/gemfire/config/server-ns.xml";
}
@Test
public void testBasicCacheServer() throws Exception {
CacheServer cacheServer = ctx.getBean("advanced-config", CacheServer.class);
assertTrue(cacheServer.isRunning());
assertEquals(1, cacheServer.getGroups().length);
assertEquals("test-server", cacheServer.getGroups()[0]);
assertEquals(22, cacheServer.getMaxConnections());
}
}

View File

@@ -0,0 +1,29 @@
<?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:gfe="http://www.springframework.org/schema/gemfire"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
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/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
<gfe:cache />
<!-- Advanced example depicting various cache server configuration options -->
<gfe:cache-server id="advanced-config" auto-startup="true"
bind-address="localhost" port="${gfe.port.6}" host-name-for-clients="localhost"
load-poll-interval="2000" max-connections="22" max-threads="16"
max-message-count="1000" max-time-between-pings="30000"
groups="test-server">
<gfe:subscription-config eviction-type="ENTRY" capacity="1000" disk-store="file://${java.io.tmpdir}"/>
</gfe:cache-server>
<context:property-placeholder location="classpath:port.properties" />
</beans>

View File

@@ -1,2 +1,3 @@
gfe.port=40403
gfe.port.4=40404
gfe.port.4=40404
gfe.port.6=40406