SGF-376 - The GemFire WAN GatewayHub support needs refactoring and test coverage.
This commit is contained in:
@@ -32,12 +32,16 @@ import org.springframework.data.gemfire.ScopeConverter;
|
||||
import org.springframework.data.gemfire.client.InterestResultPolicyConverter;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicy;
|
||||
import org.springframework.data.gemfire.server.SubscriptionEvictionPolicyConverter;
|
||||
import org.springframework.data.gemfire.wan.OrderPolicyConverter;
|
||||
import org.springframework.data.gemfire.wan.StartupPolicyConverter;
|
||||
import org.springframework.data.gemfire.wan.StartupPolicyType;
|
||||
|
||||
import com.gemstone.gemfire.cache.EvictionAction;
|
||||
import com.gemstone.gemfire.cache.ExpirationAction;
|
||||
import com.gemstone.gemfire.cache.InterestPolicy;
|
||||
import com.gemstone.gemfire.cache.InterestResultPolicy;
|
||||
import com.gemstone.gemfire.cache.Scope;
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
|
||||
/**
|
||||
* The CustomEditorRegistrationBeanFactoryPostProcessor class is a Spring BeanFactoryPostProcessor used to register
|
||||
@@ -48,7 +52,7 @@ import com.gemstone.gemfire.cache.Scope;
|
||||
* @see org.springframework.beans.factory.config.BeanFactoryPostProcessor
|
||||
* @since 1.6.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class CustomEditorRegistrationBeanFactoryPostProcessor implements BeanFactoryPostProcessor {
|
||||
|
||||
@Override
|
||||
@@ -60,7 +64,9 @@ public class CustomEditorRegistrationBeanFactoryPostProcessor implements BeanFac
|
||||
beanFactory.registerCustomEditor(IndexType.class, IndexTypeConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestPolicy.class, InterestPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(InterestResultPolicy.class, InterestResultPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(Gateway.OrderPolicy.class, OrderPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(Scope.class, ScopeConverter.class);
|
||||
beanFactory.registerCustomEditor(StartupPolicyType.class, StartupPolicyConverter.class);
|
||||
beanFactory.registerCustomEditor(SubscriptionEvictionPolicy.class, SubscriptionEvictionPolicyConverter.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ package org.springframework.data.gemfire.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.ManagedList;
|
||||
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
|
||||
@@ -24,89 +25,143 @@ import org.springframework.beans.factory.xml.ParserContext;
|
||||
import org.springframework.data.gemfire.wan.GatewayHubFactoryBean;
|
||||
import org.springframework.data.gemfire.wan.GatewayProxy;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.xml.DomUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for the <gateway-hub> SDG XML namespace element used to create GemFire GatewayHubs.
|
||||
*
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.config.BeanDefinition
|
||||
* @see org.springframework.beans.factory.support.BeanDefinitionBuilder
|
||||
* @see org.springframework.beans.factory.support.ManagedList
|
||||
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
|
||||
* @see org.springframework.beans.factory.xml.ParserContext
|
||||
* @see org.springframework.data.gemfire.wan.GatewayHubFactoryBean
|
||||
* @see org.springframework.data.gemfire.wan.GatewayProxy
|
||||
*/
|
||||
class GatewayHubParser extends AbstractSimpleBeanDefinitionParser {
|
||||
|
||||
@Override
|
||||
protected Class<?> getBeanClass(Element element) {
|
||||
return GatewayHubFactoryBean.class;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
/*
|
||||
<xsd:attribute name="max-connections" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the maximum number of Gateway connections allowed.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
<xsd:attribute name="max-time-between-pings" type="xsd:string" use="optional">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Sets the maximum amount of time between client pings.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
</xsd:attribute>
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
|
||||
builder.addConstructorArgReference(ParsingUtils.resolveCacheReference(element.getAttribute("cache-ref")));
|
||||
builder.setLazyInit(false);
|
||||
String cacheRef = element.getAttribute("cache-ref");
|
||||
// add cache reference (fallback to default if nothing is specified)
|
||||
builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef : "gemfireCache"));
|
||||
|
||||
ParsingUtils.setPropertyValue(element, builder, "bind-address");
|
||||
ParsingUtils.setPropertyValue(element, builder, "manual-start");
|
||||
//ParsingUtils.setPropertyValue(element, builder, "max-connections");
|
||||
//ParsingUtils.setPropertyValue(element, builder, "max-time-between-pings", "maximumTimeBetweenPings");
|
||||
ParsingUtils.setPropertyValue(element, builder, "port");
|
||||
ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size");
|
||||
ParsingUtils.setPropertyValue(element, builder, "startup-policy");
|
||||
ParsingUtils.setPropertyValue(element, builder, "port");
|
||||
|
||||
|
||||
parseGateways(element, parserContext, builder);
|
||||
}
|
||||
|
||||
private void parseGateways(Element element, ParserContext parserContext, BeanDefinitionBuilder gatewayHubBuilder) {
|
||||
List<Element> gatewayElements = DomUtils.getChildElementsByTagName(element, "gateway");
|
||||
|
||||
if (!CollectionUtils.isEmpty(gatewayElements)) {
|
||||
ManagedList gateways = new ManagedList();
|
||||
ManagedList<BeanDefinition> gateways = new ManagedList<BeanDefinition>();
|
||||
|
||||
for (Element gatewayElement : gatewayElements) {
|
||||
BeanDefinitionBuilder gatewayBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayProxy.class);
|
||||
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "gateway-id", "id");
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "concurrency-level");
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "socket-read-timeout");
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "socket-buffer-size");
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "order-policy");
|
||||
List<Element> endpointElements = DomUtils.getChildElementsByTagName(gatewayElement, "gateway-endpoint");
|
||||
if (!CollectionUtils.isEmpty(endpointElements)) {
|
||||
ManagedList endpoints = new ManagedList();
|
||||
for (Element endpointElement : endpointElements) {
|
||||
BeanDefinitionBuilder endpointBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(GatewayProxy.GatewayEndpoint.class);
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "host");
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "port");
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "endpoint-id", "id");
|
||||
endpoints.add(endpointBuilder.getBeanDefinition());
|
||||
}
|
||||
gatewayBuilder.addPropertyValue("endpoints", endpoints);
|
||||
}
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "socket-buffer-size");
|
||||
ParsingUtils.setPropertyValue(gatewayElement, gatewayBuilder, "socket-read-timeout");
|
||||
|
||||
Element gatewayListenerElement = DomUtils.getChildElementByTagName(gatewayElement, "gateway-listener");
|
||||
if (gatewayListenerElement != null) {
|
||||
Object obj = ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, gatewayListenerElement,
|
||||
gatewayBuilder);
|
||||
gatewayBuilder.addPropertyValue("listeners", obj);
|
||||
}
|
||||
parseGatewayEndpoints(gatewayElement, gatewayBuilder);
|
||||
parseGatewayListeners(gatewayElement, parserContext, gatewayBuilder);
|
||||
parseGatewayQueue(gatewayElement, gatewayBuilder);
|
||||
|
||||
Element gatewayQueueElement = DomUtils.getChildElementByTagName(gatewayElement, "gateway-queue");
|
||||
if (gatewayQueueElement != null) {
|
||||
BeanDefinitionBuilder queueBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(GatewayProxy.GatewayQueue.class);
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "alert-threshold");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "batch-size");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "batch-time-interval");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "maximum-queue-memory");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "persistent");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "disk-store-ref");
|
||||
/*
|
||||
* Make sure any disk store is created first
|
||||
*/
|
||||
if (gatewayQueueElement.hasAttribute("disk-store-ref")) {
|
||||
gatewayBuilder.getBeanDefinition().setDependsOn(
|
||||
new String[] {gatewayQueueElement.getAttribute("disk-store-ref")});
|
||||
}
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "enable-batch-conflation");
|
||||
gatewayBuilder.addPropertyValue("queue", queueBuilder.getBeanDefinition());
|
||||
|
||||
|
||||
}
|
||||
gateways.add(gatewayBuilder.getBeanDefinition());
|
||||
}
|
||||
builder.addPropertyValue("gateways", gateways);
|
||||
|
||||
gatewayHubBuilder.addPropertyValue("gateways", gateways);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseGatewayEndpoints(Element gatewayElement, BeanDefinitionBuilder gatewayBuilder) {
|
||||
List<Element> endpointElements = DomUtils.getChildElementsByTagName(gatewayElement, "gateway-endpoint");
|
||||
|
||||
if (!CollectionUtils.isEmpty(endpointElements)) {
|
||||
ManagedList<BeanDefinition> endpoints = new ManagedList<BeanDefinition>();
|
||||
|
||||
for (Element endpointElement : endpointElements) {
|
||||
BeanDefinitionBuilder endpointBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
GatewayProxy.GatewayEndpoint.class);
|
||||
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "endpoint-id", "id");
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "host");
|
||||
ParsingUtils.setPropertyValue(endpointElement, endpointBuilder, "port");
|
||||
|
||||
endpoints.add(endpointBuilder.getBeanDefinition());
|
||||
}
|
||||
|
||||
gatewayBuilder.addPropertyValue("endpoints", endpoints);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseGatewayListeners(Element gatewayElement, ParserContext parserContext,
|
||||
BeanDefinitionBuilder gatewayBuilder) {
|
||||
|
||||
Element gatewayListenerElement = DomUtils.getChildElementByTagName(gatewayElement, "gateway-listener");
|
||||
|
||||
if (gatewayListenerElement != null) {
|
||||
gatewayBuilder.addPropertyValue("listeners", ParsingUtils.parseRefOrNestedBeanDeclaration(
|
||||
parserContext, gatewayListenerElement, gatewayBuilder));
|
||||
}
|
||||
}
|
||||
|
||||
private void parseGatewayQueue(Element gatewayElement, BeanDefinitionBuilder gatewayBuilder) {
|
||||
Element gatewayQueueElement = DomUtils.getChildElementByTagName(gatewayElement, "gateway-queue");
|
||||
|
||||
if (gatewayQueueElement != null) {
|
||||
BeanDefinitionBuilder queueBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
GatewayProxy.GatewayQueue.class);
|
||||
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "alert-threshold");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "batch-size");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "batch-time-interval");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "disk-store-ref");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "enable-batch-conflation");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "maximum-queue-memory");
|
||||
ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "persistent");
|
||||
|
||||
/* Make sure any disk store is created first */
|
||||
if (gatewayQueueElement.hasAttribute("disk-store-ref")) {
|
||||
gatewayBuilder.getBeanDefinition().setDependsOn(new String[] {
|
||||
gatewayQueueElement.getAttribute("disk-store-ref") });
|
||||
}
|
||||
|
||||
gatewayBuilder.addPropertyValue("queue", queueBuilder.getBeanDefinition());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,9 +34,13 @@ import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
|
||||
*
|
||||
* @author David Turanski
|
||||
* @author John Blum
|
||||
* @see org.springframework.beans.factory.BeanNameAware
|
||||
* @see org.springframework.beans.factory.DisposableBean
|
||||
* @see org.springframework.beans.factory.FactoryBean
|
||||
* @see org.springframework.beans.factory.InitializingBean
|
||||
*/
|
||||
public abstract class AbstractWANComponentFactoryBean<T> implements BeanNameAware, FactoryBean<T>, InitializingBean,
|
||||
DisposableBean {
|
||||
public abstract class AbstractWANComponentFactoryBean<T> implements BeanNameAware, FactoryBean<T>,
|
||||
InitializingBean, DisposableBean {
|
||||
|
||||
protected static final List<String> VALID_ORDER_POLICIES = Arrays.asList("KEY", "PARTITION", "THREAD");
|
||||
|
||||
@@ -67,7 +71,7 @@ public abstract class AbstractWANComponentFactoryBean<T> implements BeanNameAwar
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return (StringUtils.hasText(name) ? name: beanName);
|
||||
return (StringUtils.hasText(name) ? name : beanName);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,8 +87,8 @@ public abstract class AbstractWANComponentFactoryBean<T> implements BeanNameAwar
|
||||
|
||||
@Override
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
Assert.notNull(getName(), "Name must not be null.");
|
||||
Assert.notNull(cache, "Cache must not be null.");
|
||||
Assert.notNull(getName(), "Name must not be null.");
|
||||
doInit();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,51 +16,57 @@
|
||||
package org.springframework.data.gemfire.wan;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.gemfire.wan.GatewayProxy.GatewayQueue;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import com.gemstone.gemfire.cache.Cache;
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy;
|
||||
import com.gemstone.gemfire.cache.util.GatewayEventListener;
|
||||
import com.gemstone.gemfire.cache.util.GatewayHub;
|
||||
import com.gemstone.gemfire.cache.util.GatewayQueueAttributes;
|
||||
import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
|
||||
|
||||
/**
|
||||
* FactoryBean for creating a GemFire {@link GatewayHub} (deprecated in Gemfire
|
||||
* 7)
|
||||
* FactoryBean for creating a GemFire {@link GatewayHub} (deprecated in Gemfire 7).
|
||||
*
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.wan.AbstractWANComponentFactoryBean
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayHub
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayEventListener
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayQueueAttributes
|
||||
*/
|
||||
@SuppressWarnings({"deprecation", "unused" })
|
||||
public class GatewayHubFactoryBean extends AbstractWANComponentFactoryBean<GatewayHub> {
|
||||
private static List<String> validStartupPolicyValues = Arrays.asList("none", "primary", "secondary");
|
||||
|
||||
private static List<String> validOrderPolicyValues = Arrays.asList("KEY,PARTITION,THREAD");
|
||||
|
||||
private GatewayHub gatewayHub;
|
||||
|
||||
private Integer port;
|
||||
|
||||
private String bindAddress;
|
||||
|
||||
private Integer maximumTimeBetweenPings;
|
||||
|
||||
private Integer socketBufferSize;
|
||||
|
||||
private String startupPolicy;
|
||||
|
||||
private Boolean manualStart;
|
||||
|
||||
private GatewayHub gatewayHub;
|
||||
|
||||
private Integer maxConnections;
|
||||
private Integer maximumTimeBetweenPings;
|
||||
private Integer port;
|
||||
private Integer socketBufferSize;
|
||||
|
||||
private List<GatewayProxy> gateways;
|
||||
|
||||
private StartupPolicyType startupPolicy;
|
||||
|
||||
private String bindAddress;
|
||||
|
||||
/**
|
||||
* @param cache the Gemfire cache
|
||||
* Constructs an instance of the GatewayHubFactoryBean class used to create GemFire WAN GatewayHubs initialized
|
||||
* with the specified GemFire Cache.
|
||||
*
|
||||
* @param cache a reference to the Gemfire Cache.
|
||||
* @see com.gemstone.gemfire.cache.Cache
|
||||
*/
|
||||
public GatewayHubFactoryBean(Cache cache) {
|
||||
public GatewayHubFactoryBean(final Cache cache) {
|
||||
super(cache);
|
||||
}
|
||||
|
||||
@@ -71,134 +77,151 @@ public class GatewayHubFactoryBean extends AbstractWANComponentFactoryBean<Gatew
|
||||
|
||||
@Override
|
||||
public Class<?> getObjectType() {
|
||||
return GatewayHub.class;
|
||||
return (gatewayHub != null ? gatewayHub.getClass() : GatewayHub.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doInit() {
|
||||
String name = getName();
|
||||
gatewayHub = cache.addGatewayHub(name, port == null ? GatewayHub.DEFAULT_PORT : port);
|
||||
gatewayHub = cache.addGatewayHub(getName(), getPort());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("added gateway hub " + name);
|
||||
log.debug(String.format("Adding GemFire GatewayHub (%1$s)", getName()));
|
||||
}
|
||||
|
||||
Assert.notNull(cache.getGatewayHub(name));
|
||||
Assert.notNull(cache.getGatewayHub(getName()));
|
||||
|
||||
if (bindAddress != null) {
|
||||
gatewayHub.setBindAddress(bindAddress);
|
||||
}
|
||||
if (manualStart != null) {
|
||||
gatewayHub.setManualStart(manualStart);
|
||||
}
|
||||
if (socketBufferSize != null) {
|
||||
gatewayHub.setSocketBufferSize(socketBufferSize);
|
||||
}
|
||||
if (startupPolicy != null) {
|
||||
Assert.isTrue(validStartupPolicyValues.contains(startupPolicy), "The value of startup policy:'"
|
||||
+ startupPolicy + "' is invalid");
|
||||
gatewayHub.setStartupPolicy(startupPolicy);
|
||||
}
|
||||
if (maximumTimeBetweenPings != null) {
|
||||
gatewayHub.setMaximumTimeBetweenPings(maximumTimeBetweenPings);
|
||||
}
|
||||
|
||||
if (!CollectionUtils.isEmpty(gateways)) {
|
||||
configureGateways();
|
||||
}
|
||||
|
||||
if (gatewayHub.getManualStart() == false) {
|
||||
try {
|
||||
gatewayHub.start();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
gatewayHub.setBindAddress(getBindAddress());
|
||||
gatewayHub.setManualStart(isManualStart(GatewayHub.DEFAULT_MANUAL_START));
|
||||
//gatewayHub.setMaxConnections(getMaxConnections());
|
||||
gatewayHub.setMaximumTimeBetweenPings(getMaximumTimeBetweenPings());
|
||||
gatewayHub.setSocketBufferSize(getSocketBufferSize());
|
||||
gatewayHub.setStartupPolicy(getStartupPolicy().getName());
|
||||
|
||||
configureGateways();
|
||||
autoStart();
|
||||
}
|
||||
|
||||
private void configureGateways() {
|
||||
for (GatewayProxy gatewayProxy : getGateways()) {
|
||||
Gateway gateway = gatewayHub.addGateway(gatewayProxy.getId(), gatewayProxy.getConcurrencyLevel());
|
||||
|
||||
for (GatewayProxy.GatewayEndpoint endpoint : gatewayProxy.getEndpoints()) {
|
||||
gateway.addEndpoint(endpoint.getId(), endpoint.getHost(), endpoint.getPort());
|
||||
}
|
||||
|
||||
for (GatewayEventListener listener : gatewayProxy.getListeners()) {
|
||||
gateway.addListener(listener);
|
||||
}
|
||||
|
||||
gateway.setOrderPolicy(gatewayProxy.getOrderPolicy());
|
||||
gateway.setSocketBufferSize(gatewayProxy.getSocketBufferSize());
|
||||
//gateway.setSocketReadTimeout(gatewayProxy.getSocketReadTimeout());
|
||||
|
||||
if (gatewayProxy.getQueue() != null) {
|
||||
GatewayQueue queue = gatewayProxy.getQueue();
|
||||
GatewayQueueAttributes queueAttributes = gateway.getQueueAttributes();
|
||||
|
||||
queueAttributes.setAlertThreshold(queue.getAlertThreshold());
|
||||
queueAttributes.setBatchConflation(queue.getEnableBatchConflation());
|
||||
queueAttributes.setBatchSize(queue.getBatchSize());
|
||||
queueAttributes.setBatchTimeInterval(queue.getBatchTimeInterval());
|
||||
queueAttributes.setMaximumQueueMemory(queue.getMaximumQueueMemory());
|
||||
queueAttributes.setEnablePersistence(queue.getPersistent());
|
||||
|
||||
if (queue.getDiskStoreRef() != null) {
|
||||
// TODO what about "overflow"?
|
||||
boolean persistent = (queue.getPersistent() == null || queue.getPersistent());
|
||||
Assert.isTrue(persistent, "specifying a disk store requires persistent property to be true");
|
||||
queueAttributes.setDiskStoreName(queue.getDiskStoreRef());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
private void autoStart() {
|
||||
if (!gatewayHub.getManualStart()) {
|
||||
try {
|
||||
gatewayHub.start();
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setBindAddress(String bindAddress) {
|
||||
this.bindAddress = bindAddress;
|
||||
}
|
||||
|
||||
public void setMaximumTimeBetweenPings(Integer maximumTimeBetweenPings) {
|
||||
this.maximumTimeBetweenPings = maximumTimeBetweenPings;
|
||||
/* (non-Javadoc) */
|
||||
String getBindAddress() {
|
||||
return (StringUtils.hasText(bindAddress) ? bindAddress : GatewayHub.DEFAULT_BIND_ADDRESS);
|
||||
}
|
||||
|
||||
public void setSocketBufferSize(Integer socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
public void setGateways(List<GatewayProxy> gateways) {
|
||||
this.gateways = gateways;
|
||||
}
|
||||
|
||||
public void setStartupPolicy(String startupPolicy) {
|
||||
this.startupPolicy = startupPolicy;
|
||||
/* (non-Javadoc) */
|
||||
List<GatewayProxy> getGateways() {
|
||||
return (gateways != null ? gateways : Collections.<GatewayProxy>emptyList());
|
||||
}
|
||||
|
||||
public void setManualStart(Boolean manualStart) {
|
||||
this.manualStart = manualStart;
|
||||
}
|
||||
|
||||
public void setGateways(List<GatewayProxy> gateways) {
|
||||
this.gateways = gateways;
|
||||
/* (non-Javadoc) */
|
||||
boolean isManualStart(final boolean defaultManualStart) {
|
||||
return (manualStart != null ? manualStart : defaultManualStart);
|
||||
}
|
||||
|
||||
private void configureGateways() {
|
||||
for (GatewayProxy gateway : gateways) {
|
||||
Gateway gw = gatewayHub.addGateway(
|
||||
gateway.getId(),
|
||||
gateway.getConcurrencyLevel() == null ? Gateway.DEFAULT_CONCURRENCY_LEVEL : gateway
|
||||
.getConcurrencyLevel());
|
||||
if (!CollectionUtils.isEmpty(gateway.getEndpoints())) {
|
||||
for (GatewayProxy.GatewayEndpoint endpoint : gateway.getEndpoints()) {
|
||||
gw.addEndpoint(endpoint.getId(), endpoint.getHost(), endpoint.getPort());
|
||||
}
|
||||
}
|
||||
if (!CollectionUtils.isEmpty(gateway.getListeners())) {
|
||||
for (GatewayEventListener listener : gateway.getListeners()) {
|
||||
gw.addListener(listener);
|
||||
}
|
||||
}
|
||||
if (gateway.getOrderPolicy() != null) {
|
||||
Assert.isTrue(validOrderPolicyValues.contains(gateway.getOrderPolicy()),
|
||||
"The value of order policy:'" + gateway.getOrderPolicy() + "' is invalid");
|
||||
gw.setOrderPolicy(OrderPolicy.valueOf(gateway.getOrderPolicy()));
|
||||
}
|
||||
if (gateway.getSocketBufferSize() != null) {
|
||||
gw.setSocketBufferSize(gateway.getSocketBufferSize());
|
||||
}
|
||||
|
||||
if (gateway.getQueue() != null) {
|
||||
GatewayQueue queue = gateway.getQueue();
|
||||
GatewayQueueAttributes queueAttributes = gw.getQueueAttributes();
|
||||
if (queue.getAlertThreshold() != null) {
|
||||
queueAttributes.setAlertThreshold(queue.getAlertThreshold());
|
||||
}
|
||||
if (queue.getEnableBatchConflation() != null) {
|
||||
queueAttributes.setBatchConflation(queue.getEnableBatchConflation());
|
||||
}
|
||||
if (queue.getBatchSize() != null) {
|
||||
queueAttributes.setBatchSize(queue.getBatchSize());
|
||||
}
|
||||
if (queue.getBatchTimeInterval() != null) {
|
||||
queueAttributes.setBatchTimeInterval(queue.getBatchTimeInterval());
|
||||
}
|
||||
|
||||
if (queue.getDiskStoreRef() != null) {
|
||||
boolean persistent = (queue.getPersistent() == null) ? Boolean.TRUE : queue.getPersistent();
|
||||
Assert.isTrue(persistent, "specifying a disk store requires persistent property to be true");
|
||||
queueAttributes.setDiskStoreName(queue.getDiskStoreRef());
|
||||
}
|
||||
|
||||
if (queue.getPersistent() != null) {
|
||||
queueAttributes.setEnablePersistence(queue.getPersistent());
|
||||
}
|
||||
|
||||
if (queue.getMaximumQueueMemory() != null) {
|
||||
queueAttributes.setMaximumQueueMemory(queue.getMaximumQueueMemory());
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
public void setMaxConnections(Integer maxConnections) {
|
||||
this.maxConnections = maxConnections;
|
||||
}
|
||||
|
||||
// (non-Javadoc)
|
||||
Integer getMaxConnections() {
|
||||
return (maxConnections != null ? maxConnections : GatewayHub.DEFAULT_MAX_CONNECTIONS);
|
||||
}
|
||||
*/
|
||||
|
||||
public void setMaximumTimeBetweenPings(Integer maximumTimeBetweenPings) {
|
||||
this.maximumTimeBetweenPings = maximumTimeBetweenPings;
|
||||
}
|
||||
|
||||
// (non-Javadoc)
|
||||
Integer getMaximumTimeBetweenPings() {
|
||||
return (maximumTimeBetweenPings != null ? maximumTimeBetweenPings
|
||||
: GatewayHub.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS);
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Integer getPort() {
|
||||
return (port != null ? port : GatewayHub.DEFAULT_PORT);
|
||||
}
|
||||
|
||||
public void setSocketBufferSize(Integer socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
Integer getSocketBufferSize() {
|
||||
return (socketBufferSize != null ? socketBufferSize : GatewayHub.DEFAULT_SOCKET_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public void setStartupPolicy(StartupPolicyType startupPolicy) {
|
||||
this.startupPolicy = startupPolicy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc) */
|
||||
StartupPolicyType getStartupPolicy() {
|
||||
return (startupPolicy != null ? startupPolicy : StartupPolicyType.DEFAULT);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,42 +15,76 @@
|
||||
*/
|
||||
package org.springframework.data.gemfire.wan;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
import com.gemstone.gemfire.cache.util.GatewayEventListener;
|
||||
import com.gemstone.gemfire.cache.util.GatewayQueueAttributes;
|
||||
|
||||
/**
|
||||
* This class used to allow decoupling of 'gateway' parsing from 'gateway-hub'
|
||||
* parsing
|
||||
* The GatewayProxy class used to allow decoupling of 'gateway' parsing from 'gateway-hub' parsing.
|
||||
*
|
||||
* @author David Turanski
|
||||
*
|
||||
* @author John Blum
|
||||
* @since com.gemstone.gemfire.cache.util.Gateway
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class GatewayProxy {
|
||||
|
||||
private List<GatewayEndpoint> endpoints;
|
||||
private Gateway.OrderPolicy orderPolicy;
|
||||
|
||||
private GatewayQueue queue;
|
||||
|
||||
private Integer concurrencyLevel = Gateway.DEFAULT_CONCURRENCY_LEVEL;
|
||||
private Integer socketBufferSize = Gateway.DEFAULT_SOCKET_BUFFER_SIZE;
|
||||
//private Integer socketReadTimeout = Gateway.DEFAULT_SOCKET_READ_TIMEOUT;
|
||||
|
||||
private List<GatewayEndpoint> endpoints;
|
||||
private List<GatewayEventListener> listeners;
|
||||
|
||||
private String id;
|
||||
|
||||
private List<GatewayEventListener> listeners;
|
||||
public void setConcurrencyLevel(Integer concurrencyLevel) {
|
||||
this.concurrencyLevel = concurrencyLevel;
|
||||
}
|
||||
|
||||
private String orderPolicy;
|
||||
|
||||
private int socketBufferSize = Gateway.DEFAULT_SOCKET_BUFFER_SIZE;
|
||||
|
||||
private GatewayQueue queue;
|
||||
public Integer getConcurrencyLevel() {
|
||||
return (concurrencyLevel != null ? concurrencyLevel : Gateway.DEFAULT_CONCURRENCY_LEVEL);
|
||||
}
|
||||
|
||||
public void setEndpoints(List<GatewayEndpoint> endpoints) {
|
||||
this.endpoints = endpoints;
|
||||
}
|
||||
|
||||
public List<GatewayEndpoint> getEndpoints() {
|
||||
return (endpoints != null ? endpoints : Collections.<GatewayEndpoint>emptyList());
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public void setListeners(List<GatewayEventListener> listeners) {
|
||||
this.listeners = listeners;
|
||||
}
|
||||
|
||||
public List<GatewayEventListener> getListeners() {
|
||||
return (listeners != null ? listeners : Collections.<GatewayEventListener>emptyList());
|
||||
}
|
||||
|
||||
public void setOrderPolicy(Gateway.OrderPolicy orderPolicy) {
|
||||
this.orderPolicy = orderPolicy;
|
||||
}
|
||||
|
||||
public Gateway.OrderPolicy getOrderPolicy() {
|
||||
return this.orderPolicy;
|
||||
}
|
||||
|
||||
public void setQueue(GatewayQueue queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
@@ -59,50 +93,31 @@ public class GatewayProxy {
|
||||
return this.queue;
|
||||
}
|
||||
|
||||
public Integer getConcurrencyLevel() {
|
||||
return this.concurrencyLevel;
|
||||
}
|
||||
|
||||
public List<GatewayEndpoint> getEndpoints() {
|
||||
return endpoints;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public List<GatewayEventListener> getListeners() {
|
||||
return this.listeners;
|
||||
}
|
||||
|
||||
public String getOrderPolicy() {
|
||||
return this.orderPolicy;
|
||||
public void setSocketBufferSize(int socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
}
|
||||
|
||||
public Integer getSocketBufferSize() {
|
||||
return this.socketBufferSize;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
return (socketBufferSize != null ? socketBufferSize : Gateway.DEFAULT_SOCKET_BUFFER_SIZE);
|
||||
}
|
||||
|
||||
public void setOrderPolicy(String orderPolicy) {
|
||||
this.orderPolicy = orderPolicy;
|
||||
/*
|
||||
public void setSocketReadTimeout(final Integer socketReadTimeout) {
|
||||
this.socketReadTimeout = socketReadTimeout;
|
||||
}
|
||||
|
||||
public void setSocketBufferSize(int socketBufferSize) {
|
||||
this.socketBufferSize = socketBufferSize;
|
||||
|
||||
public Integer getSocketReadTimeout() {
|
||||
return (socketReadTimeout != null ? socketReadTimeout : Gateway.DEFAULT_SOCKET_READ_TIMEOUT);
|
||||
}
|
||||
*/
|
||||
|
||||
public static class GatewayEndpoint {
|
||||
private String host;
|
||||
|
||||
private String id;
|
||||
|
||||
private int port;
|
||||
|
||||
private String host;
|
||||
private String id;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
@@ -129,75 +144,74 @@ public class GatewayProxy {
|
||||
}
|
||||
|
||||
public static class GatewayQueue {
|
||||
private Integer alertThreshold;
|
||||
|
||||
private Boolean enableBatchConflation;
|
||||
|
||||
private Integer batchTimeInterval;
|
||||
|
||||
private Integer batchSize;
|
||||
|
||||
private Boolean persistent;
|
||||
|
||||
private String diskStoreRef;
|
||||
|
||||
private Integer alertThreshold;
|
||||
private Integer batchSize;
|
||||
private Integer batchTimeInterval;
|
||||
private Integer maximumQueueMemory;
|
||||
|
||||
public Integer getAlertThreshold() {
|
||||
return alertThreshold;
|
||||
}
|
||||
private String diskStoreRef;
|
||||
|
||||
public void setAlertThreshold(Integer alertThreshold) {
|
||||
this.alertThreshold = alertThreshold;
|
||||
}
|
||||
|
||||
public Boolean getEnableBatchConflation() {
|
||||
return enableBatchConflation;
|
||||
}
|
||||
|
||||
public void setEnableBatchConflation(Boolean enableBatchConflation) {
|
||||
this.enableBatchConflation = enableBatchConflation;
|
||||
}
|
||||
|
||||
public Integer getBatchTimeInterval() {
|
||||
return batchTimeInterval;
|
||||
}
|
||||
|
||||
public void setBatchTimeInterval(Integer batchTimeInterval) {
|
||||
this.batchTimeInterval = batchTimeInterval;
|
||||
}
|
||||
|
||||
public Integer getBatchSize() {
|
||||
return batchSize;
|
||||
public Integer getAlertThreshold() {
|
||||
return (alertThreshold != null ? alertThreshold : GatewayQueueAttributes.DEFAULT_ALERT_THRESHOLD);
|
||||
}
|
||||
|
||||
public void setBatchSize(Integer batchSize) {
|
||||
this.batchSize = batchSize;
|
||||
}
|
||||
|
||||
public Boolean getPersistent() {
|
||||
return persistent;
|
||||
public Integer getBatchSize() {
|
||||
return (batchSize != null ? batchSize : GatewayQueueAttributes.DEFAULT_BATCH_SIZE);
|
||||
}
|
||||
|
||||
public void setPersistent(Boolean persistent) {
|
||||
this.persistent = persistent;
|
||||
public void setBatchTimeInterval(Integer batchTimeInterval) {
|
||||
this.batchTimeInterval = batchTimeInterval;
|
||||
}
|
||||
|
||||
public String getDiskStoreRef() {
|
||||
return diskStoreRef;
|
||||
public Integer getBatchTimeInterval() {
|
||||
return (batchTimeInterval != null ? batchTimeInterval : GatewayQueueAttributes.DEFAULT_BATCH_TIME_INTERVAL);
|
||||
}
|
||||
|
||||
public void setDiskStoreRef(String diskStoreRef) {
|
||||
this.diskStoreRef = diskStoreRef;
|
||||
}
|
||||
|
||||
public Integer getMaximumQueueMemory() {
|
||||
return maximumQueueMemory;
|
||||
public String getDiskStoreRef() {
|
||||
return diskStoreRef;
|
||||
}
|
||||
|
||||
public void setEnableBatchConflation(Boolean enableBatchConflation) {
|
||||
this.enableBatchConflation = enableBatchConflation;
|
||||
}
|
||||
|
||||
public Boolean getEnableBatchConflation() {
|
||||
return (enableBatchConflation != null ? enableBatchConflation
|
||||
: GatewayQueueAttributes.DEFAULT_BATCH_CONFLATION);
|
||||
}
|
||||
|
||||
public void setMaximumQueueMemory(Integer maximumQueueMemory) {
|
||||
this.maximumQueueMemory = maximumQueueMemory;
|
||||
}
|
||||
|
||||
public Integer getMaximumQueueMemory() {
|
||||
return (maximumQueueMemory != null ? maximumQueueMemory
|
||||
: GatewayQueueAttributes.DEFAULT_MAXIMUM_QUEUE_MEMORY);
|
||||
}
|
||||
|
||||
public void setPersistent(Boolean persistent) {
|
||||
this.persistent = persistent;
|
||||
}
|
||||
|
||||
public Boolean getPersistent() {
|
||||
return (persistent != null ? persistent : GatewayQueueAttributes.DEFAULT_ENABLE_PERSISTENCE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* 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.wan;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
|
||||
/**
|
||||
* The OrderPolicyConverter class is a Spring Converter and JavaBeans PropertyEditor used to convert a String value
|
||||
* into an appropriate GemFire Gateway.OrderPolicy enum.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @see org.springframework.data.gemfire.wan.OrderPolicyType
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public class OrderPolicyConverter extends AbstractPropertyEditorConverterSupport<Gateway.OrderPolicy> {
|
||||
|
||||
/**
|
||||
* Converts the given String into a GemFire Gateway.OrderPolicy enum.
|
||||
*
|
||||
* @param source the String to convert.
|
||||
* @return a GemFire Gateway.OrderPolicy enum for the given String.
|
||||
* @throws java.lang.IllegalArgumentException if the String is not a valid GemFire Gateway.OrderPolicy.
|
||||
* @see org.springframework.data.gemfire.wan.OrderPolicyType#getOrderPolicy()
|
||||
* @see org.springframework.data.gemfire.wan.OrderPolicyType#valueOfIgnoreCase(String)
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
*/
|
||||
@Override
|
||||
public Gateway.OrderPolicy convert(final String source) {
|
||||
return assertConverted(source, OrderPolicyType.getOrderPolicy(OrderPolicyType.valueOfIgnoreCase(source)),
|
||||
Gateway.OrderPolicy.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
/*
|
||||
* 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.wan;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.Gateway;
|
||||
|
||||
/**
|
||||
* The OrderPolicyType class is an enumeration of GemFire Gateway Order Policies.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings({ "deprecation", "unused" })
|
||||
public enum OrderPolicyType {
|
||||
KEY(Gateway.OrderPolicy.KEY),
|
||||
PARTITION(Gateway.OrderPolicy.PARTITION),
|
||||
THREAD(Gateway.OrderPolicy.THREAD);
|
||||
|
||||
private final Gateway.OrderPolicy orderPolicy;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the OrderPolicyType enum initialized with the matching GemFire Gateway.OrderPolicy
|
||||
* enumerated value.
|
||||
*
|
||||
* @param orderPolicy the matching GemFire Gateway.OrderPolicy enumerated value.
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
*/
|
||||
OrderPolicyType(final Gateway.OrderPolicy orderPolicy) {
|
||||
this.orderPolicy = orderPolicy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Null-safe operation to extract the matching GemFire Gateway.OrderPolicy enumerated value from
|
||||
* the specified OrderPolicyType.
|
||||
*
|
||||
* @param orderPolicyType the OrderPolicyType enum from which to extract the GemFire-based
|
||||
* Gateway.OrderPolicy enumerated value.
|
||||
* @return the GemFire Gateway.OrderPolicy enumerated value for the given OrderPolicyType.
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
* @see #getOrderPolicy()
|
||||
*/
|
||||
public static Gateway.OrderPolicy getOrderPolicy(final OrderPolicyType orderPolicyType) {
|
||||
return (orderPolicyType != null ? orderPolicyType.getOrderPolicy() : null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the matching OrderPolicyType given a GemFire Gateway.OrderPolicy enumerated value.
|
||||
*
|
||||
* @param orderPolicy the GemFire Gateway.OrderPolicy enumerated value used to match
|
||||
* the desired OrderPolicyType.
|
||||
* @return a OrderPolicyType matching the given GemFire Gateway.OrderPolicy enumerated value.
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
* @see #getOrderPolicy()
|
||||
*/
|
||||
public static OrderPolicyType valueOf(final Gateway.OrderPolicy orderPolicy) {
|
||||
for (OrderPolicyType orderPolicyType : values()) {
|
||||
if (orderPolicyType.getOrderPolicy().equals(orderPolicy)) {
|
||||
return orderPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a matching OrderPolicyType given the case-insensitive, name of the GemFire Gateway OrderPolicy.
|
||||
*
|
||||
* @param name a String name used to match the desired OrderPolicyType.
|
||||
* @return a OrderPolicyType enumerated value for the given name.
|
||||
* @see java.lang.String#equalsIgnoreCase(String)
|
||||
* @see #name()
|
||||
*/
|
||||
public static OrderPolicyType valueOfIgnoreCase(final String name) {
|
||||
for (OrderPolicyType orderPolicy : values()) {
|
||||
if (orderPolicy.name().equalsIgnoreCase(name)) {
|
||||
return orderPolicy;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the GemFire Gateway.OrderPolicy corresponding to this OrderPolicyType enum.
|
||||
*
|
||||
* @return a GemFire Gateway.OrderPolicy for this enum.
|
||||
* @see com.gemstone.gemfire.cache.util.Gateway.OrderPolicy
|
||||
*/
|
||||
public Gateway.OrderPolicy getOrderPolicy() {
|
||||
return orderPolicy;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 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.wan;
|
||||
|
||||
import org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport;
|
||||
|
||||
/**
|
||||
* The StartupPolicyConverter class is a Spring Converter and JavaBeans PropertyEditor responsible for
|
||||
* converting String values into appropriate StartupPolicyType enumerated values.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see org.springframework.data.gemfire.support.AbstractPropertyEditorConverterSupport
|
||||
* @see org.springframework.data.gemfire.wan.StartupPolicyType
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
public class StartupPolicyConverter extends AbstractPropertyEditorConverterSupport<StartupPolicyType> {
|
||||
|
||||
/**
|
||||
* Converts the given String value into an appropriate StartupPolicyType enumerated value.
|
||||
*
|
||||
* @param source the String to convert.
|
||||
* @return a StartupPolicyType enumerated value for the given String.
|
||||
* @throws java.lang.IllegalArgumentException if the String is not a valid GatewayHub Startup Policy.
|
||||
* @see StartupPolicyType#valueOfIgnoreCase(String)
|
||||
* @see #assertConverted(String, Object, Class)
|
||||
*/
|
||||
@Override
|
||||
public StartupPolicyType convert(final String source) {
|
||||
return assertConverted(source, StartupPolicyType.valueOfIgnoreCase(source),
|
||||
StartupPolicyType.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* 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.wan;
|
||||
|
||||
import com.gemstone.gemfire.cache.util.GatewayHub;
|
||||
|
||||
/**
|
||||
* The StartupPolicyType class is an enumeration of GemFire GatewayHub Startup Policies.
|
||||
*
|
||||
* @author John Blum
|
||||
* @see com.gemstone.gemfire.cache.util.GatewayHub
|
||||
* @since 1.7.0
|
||||
*/
|
||||
@SuppressWarnings({"deprecation", "unused" })
|
||||
public enum StartupPolicyType {
|
||||
NONE(GatewayHub.STARTUP_POLICY_NONE),
|
||||
PRIMARY(GatewayHub.STARTUP_POLICY_PRIMARY),
|
||||
SECONDARY(GatewayHub.STARTUP_POLICY_SECONDARY);
|
||||
|
||||
public static final StartupPolicyType DEFAULT = StartupPolicyType.valueOfIgnoreCase(
|
||||
GatewayHub.DEFAULT_STARTUP_POLICY);
|
||||
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Constructs an instance of the StartupPolicyType enum initialized with the given GemFire "named",
|
||||
* GatewayHub Startup Policy.
|
||||
*
|
||||
* @param name a String specifying the name used by GemFire for the GatewayHub Startup Policy.
|
||||
*/
|
||||
StartupPolicyType(final String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a StartupPolicyType enumerated value matching the given official, case-insensitve "name"
|
||||
* for the GatewayHub Startup Policy used by GemFire.
|
||||
*
|
||||
* @param name a String specifying the name used by GemFire for the GatewayHub Startup Policy.
|
||||
* @return a StartupPolicyType enumerated value matching the given name used by GemFire to specify
|
||||
* the GatewayHub Startup Policy.
|
||||
* @see java.lang.String#equalsIgnoreCase(String)
|
||||
* @see #getName()
|
||||
*/
|
||||
public static StartupPolicyType valueOfIgnoreCase(final String name) {
|
||||
for (StartupPolicyType startupPolicyType : values()) {
|
||||
if (startupPolicyType.getName().equalsIgnoreCase(name)) {
|
||||
return startupPolicyType;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the official name used by GemFire to specify the GatewayHub Startup Policy.
|
||||
*
|
||||
* @return the official GatewayHub Startup Policy name used by GemFire.
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user