SGF-289 - Enumeration restrictions (xsd:enumeration) should be avoided in the XML schema.
Removed the XSD enumeration restriction on the 'eviction-type' attribute of the 'subscription-config' sub-element of the 'cache-server' element inside the SDG XML namespace (XSD) allowing the use of property placeholders to specify the Eviction Policy for Client Subscription to GemFire Cache Servers.
This commit is contained in:
@@ -38,6 +38,8 @@ import org.springframework.core.io.Resource;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.support.PersistenceExceptionTranslator;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -927,6 +929,7 @@ public class CacheFactoryBean implements BeanClassLoaderAware, BeanFactoryAware,
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,11 @@ import org.w3c.dom.Element;
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.support.AbstractBeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.data.gemfire.server.CacheServerFactoryBean
|
||||
* @since 1.1.0
|
||||
*/
|
||||
class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@@ -42,18 +47,15 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
|
||||
throws BeanDefinitionStoreException {
|
||||
throws BeanDefinitionStoreException {
|
||||
String name = super.resolveId(element, definition, parserContext);
|
||||
if (!StringUtils.hasText(name)) {
|
||||
name = "gemfireServer";
|
||||
}
|
||||
return name;
|
||||
return (StringUtils.hasText(name) ? name : "gemfireServer");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) {
|
||||
return super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName())
|
||||
&& !"cache-ref".equals(attribute.getName());
|
||||
return (super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName())
|
||||
&& !"cache-ref".equals(attribute.getName()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -69,10 +71,10 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
builder.addPropertyValue("serverGroups", StringUtils.commaDelimitedListToStringArray(groupsAttribute));
|
||||
}
|
||||
|
||||
parseSubscription(builder, element);
|
||||
parseSubscription(element, builder);
|
||||
}
|
||||
|
||||
private void parseSubscription(BeanDefinitionBuilder builder, Element element) {
|
||||
private void parseSubscription(Element element, BeanDefinitionBuilder builder) {
|
||||
Element subscriptionConfigElement = DomUtils.getChildElementByTagName(element, "subscription-config");
|
||||
|
||||
if (subscriptionConfigElement != null) {
|
||||
@@ -82,7 +84,7 @@ class CacheServerParser extends AbstractSimpleBeanDefinitionParser {
|
||||
String evictionTypeAttribute = subscriptionConfigElement.getAttribute("eviction-type");
|
||||
|
||||
if (StringUtils.hasText(evictionTypeAttribute)) {
|
||||
builder.addPropertyValue("subscriptionEvictionPolicy", evictionTypeAttribute.toUpperCase());
|
||||
builder.addPropertyValue("subscriptionEvictionPolicy", evictionTypeAttribute);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,8 +71,7 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
|
||||
private String[] serverGroups = {};
|
||||
|
||||
private SubscriptionEvictionPolicy subscriptionEvictionPolicy = SubscriptionEvictionPolicy.valueOf(
|
||||
ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY.toUpperCase());
|
||||
private SubscriptionEvictionPolicy subscriptionEvictionPolicy = SubscriptionEvictionPolicy.DEFAULT;
|
||||
|
||||
public CacheServer getObject() {
|
||||
return cacheServer;
|
||||
@@ -112,42 +111,43 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
ClientSubscriptionConfig config = cacheServer.getClientSubscriptionConfig();
|
||||
|
||||
config.setCapacity(subscriptionCapacity);
|
||||
config.setEvictionPolicy(subscriptionEvictionPolicy.name().toLowerCase());
|
||||
getSubscriptionEvictionPolicy().setEvictionPolicy(config);
|
||||
|
||||
if (StringUtils.hasText(subscriptionDiskStore)) {
|
||||
config.setDiskStoreName(subscriptionDiskStore);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return (cacheServer != null && cacheServer.isRunning());
|
||||
}
|
||||
|
||||
public int getPhase() {
|
||||
// start at the latest possible moment
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
stop();
|
||||
cacheServer = null;
|
||||
}
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
return autoStartup;
|
||||
}
|
||||
|
||||
public void stop(Runnable callback) {
|
||||
stop();
|
||||
callback.run();
|
||||
}
|
||||
|
||||
public int getPhase() {
|
||||
// start the latest
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return (cacheServer != null && cacheServer.isRunning());
|
||||
}
|
||||
|
||||
public void start() {
|
||||
try {
|
||||
cacheServer.start();
|
||||
} catch (IOException ex) {
|
||||
throw new BeanInitializationException("Cannot start cache server", ex);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new BeanInitializationException("Cannot start cache server", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop(final Runnable callback) {
|
||||
stop();
|
||||
callback.run();
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
@@ -160,54 +160,22 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setMaxConnections(int maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
public void setMaxThreads(int maxThreads) {
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
public void setNotifyBySubscription(boolean notifyBySubscription) {
|
||||
this.notifyBySubscription = notifyBySubscription;
|
||||
}
|
||||
|
||||
public void setSocketBufferSize(int socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
}
|
||||
|
||||
public void setMaxTimeBetweenPings(int maxTimeBetweenPings) {
|
||||
this.maxTimeBetweenPings = maxTimeBetweenPings;
|
||||
}
|
||||
|
||||
public void setMaxMessageCount(int maxMessageCount) {
|
||||
this.maxMessageCount = maxMessageCount;
|
||||
}
|
||||
|
||||
public void setMessageTimeToLive(int messageTimeToLive) {
|
||||
this.messageTimeToLive = messageTimeToLive;
|
||||
}
|
||||
|
||||
public void setServerGroups(String[] serverGroups) {
|
||||
this.serverGroups = serverGroups;
|
||||
}
|
||||
|
||||
public void setServerLoadProbe(ServerLoadProbe serverLoadProbe) {
|
||||
this.serverLoadProbe = serverLoadProbe;
|
||||
}
|
||||
|
||||
public void setLoadPollInterval(long loadPollInterval) {
|
||||
this.loadPollInterval = loadPollInterval;
|
||||
}
|
||||
|
||||
public void setBindAddress(String bindAddress) {
|
||||
this.bindAddress = bindAddress;
|
||||
}
|
||||
|
||||
public void setCache(final Cache cache) {
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* For testing purposes only!
|
||||
*/
|
||||
void setCacheServer(final CacheServer cacheServer) {
|
||||
this.cacheServer = cacheServer;
|
||||
}
|
||||
|
||||
public void setHostNameForClients(String hostNameForClients) {
|
||||
this.hostNameForClients = hostNameForClients;
|
||||
}
|
||||
@@ -216,20 +184,50 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public void setCache(Cache cache) {
|
||||
this.cache = cache;
|
||||
public void setLoadPollInterval(long loadPollInterval) {
|
||||
this.loadPollInterval = loadPollInterval;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param evictionPolicy the subscriptionEvictionPolicy to set
|
||||
*/
|
||||
public void setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy evictionPolicy) {
|
||||
this.subscriptionEvictionPolicy = evictionPolicy;
|
||||
public void setMaxConnections(int maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
public void setMaxMessageCount(int maxMessageCount) {
|
||||
this.maxMessageCount = maxMessageCount;
|
||||
}
|
||||
|
||||
public void setMaxThreads(int maxThreads) {
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
public void setMaxTimeBetweenPings(int maxTimeBetweenPings) {
|
||||
this.maxTimeBetweenPings = maxTimeBetweenPings;
|
||||
}
|
||||
|
||||
public void setMessageTimeToLive(int messageTimeToLive) {
|
||||
this.messageTimeToLive = messageTimeToLive;
|
||||
}
|
||||
|
||||
public void setNotifyBySubscription(boolean notifyBySubscription) {
|
||||
this.notifyBySubscription = notifyBySubscription;
|
||||
}
|
||||
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public void setServerGroups(String[] serverGroups) {
|
||||
this.serverGroups = serverGroups;
|
||||
}
|
||||
|
||||
public void setServerLoadProbe(ServerLoadProbe serverLoadProbe) {
|
||||
this.serverLoadProbe = serverLoadProbe;
|
||||
}
|
||||
|
||||
public void setSocketBufferSize(int socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param subscriptionCapacity the subscriptionCapacity to set
|
||||
*/
|
||||
public void setSubscriptionCapacity(int subscriptionCapacity) {
|
||||
this.subscriptionCapacity = subscriptionCapacity;
|
||||
}
|
||||
@@ -238,4 +236,12 @@ public class CacheServerFactoryBean implements FactoryBean<CacheServer>, Initial
|
||||
this.subscriptionDiskStore = diskStoreName;
|
||||
}
|
||||
|
||||
SubscriptionEvictionPolicy getSubscriptionEvictionPolicy() {
|
||||
return (subscriptionEvictionPolicy != null ? subscriptionEvictionPolicy : SubscriptionEvictionPolicy.DEFAULT);
|
||||
}
|
||||
|
||||
public void setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy evictionPolicy) {
|
||||
this.subscriptionEvictionPolicy = evictionPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,12 +17,59 @@
|
||||
package org.springframework.data.gemfire.server;
|
||||
|
||||
import com.gemstone.gemfire.cache.server.CacheServer;
|
||||
import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig;
|
||||
|
||||
/**
|
||||
* Enumeration of the various client subscription policies for {@link CacheServer}.
|
||||
*
|
||||
* @author Costin Leau
|
||||
* @author John Blum
|
||||
* @since 1.1.0
|
||||
*/
|
||||
public enum SubscriptionEvictionPolicy {
|
||||
NONE, MEM, ENTRY
|
||||
ENTRY,
|
||||
MEM,
|
||||
NONE;
|
||||
|
||||
public static final SubscriptionEvictionPolicy DEFAULT = SubscriptionEvictionPolicy.valueOfIgnoreCase(
|
||||
ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY);
|
||||
|
||||
/**
|
||||
* Returns the value of the given String name as a SubscriptionEvictionPolicy enum using a case-insensitive,
|
||||
* equality comparison.
|
||||
*
|
||||
* @param name the String name of a SubscriptionEvictionPolicy enumerated value.
|
||||
* @return a SubscriptionEvictionPolicy enumerated value given a String name or null if no enum value
|
||||
* with name was found.
|
||||
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
|
||||
* @see java.lang.String#equalsIgnoreCase(String)
|
||||
* @see #values()
|
||||
* @see #name()
|
||||
*/
|
||||
public static SubscriptionEvictionPolicy valueOfIgnoreCase(final String name) {
|
||||
for (SubscriptionEvictionPolicy subscriptionEvictionPolicy : values()) {
|
||||
if (subscriptionEvictionPolicy.name().equalsIgnoreCase(name)) {
|
||||
return subscriptionEvictionPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe utility method for setting the client's subscription eviction policy on the configuration meta-data.
|
||||
*
|
||||
* @param config a GemFire ClientSubscriptionConfig object holding the configuration setting and meta-data
|
||||
* about the client's subscription configuration.
|
||||
* @return the ClientSubscriptionConfig object.
|
||||
* @see com.gemstone.gemfire.cache.server.ClientSubscriptionConfig#setEvictionPolicy(String)
|
||||
*/
|
||||
public ClientSubscriptionConfig setEvictionPolicy(final ClientSubscriptionConfig config) {
|
||||
if (config != null) {
|
||||
config.setEvictionPolicy(name().toLowerCase());
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* 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.server;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
|
||||
/**
|
||||
* The SubscriptionEvictionPolicyConverter class is a Spring Converter and JavaBeans PropertyEditor for converting
|
||||
* Strings into a SubscriptionEvictionPolicy enumerated value.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class SubscriptionEvictionPolicyConverter extends AbstractPropertyEditorConverterSupport<SubscriptionEvictionPolicy> {
|
||||
|
||||
/**
|
||||
* Converts the given String into a SubscriptionEvictionPolicy enumerated value.
|
||||
*
|
||||
* @param source the String to convert into a SubscriptionEvictionPolicy enum.
|
||||
* @return a SubscriptionEvictionPolicy enumerated value for the given String.
|
||||
* @throws java.lang.IllegalArgumentException if the String is a valid SubscriptionEvictionPolicy
|
||||
* enumerated value.
|
||||
* @see org.springframework.data.gemfire.server.SubscriptionEvictionPolicy#valueOfIgnoreCase(String)
|
||||
* @see #assertConverted(String, Object, Class)
|
||||
*/
|
||||
@Override
|
||||
public SubscriptionEvictionPolicy convert(final String source) {
|
||||
return assertConverted(source, SubscriptionEvictionPolicy.valueOfIgnoreCase(source),
|
||||
SubscriptionEvictionPolicy.class);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user