Completes JIRA improvement SGF-294 allowing GemFire Gateway Receivers to be configured for manual start using the Spring Data GemFire XML namespace. This commit completes the improvement in the 1.4 XSD first in order to backport the feature to the SDG 1.4.2 release.

This commit is contained in:
John Blum
2014-07-07 18:25:33 -07:00
parent 1ed3ad4295
commit db066287b0
12 changed files with 499 additions and 191 deletions

View File

@@ -24,9 +24,11 @@ import org.w3c.dom.Element;
/**
* @author David Turanski
*
* @author John Blum
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
*/
class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected Class<?> getBeanClass(Element element) {
return GatewayReceiverFactoryBean.class;
@@ -34,15 +36,19 @@ class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
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"));
builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
builder.setLazyInit(false);
ParsingUtils.setPropertyValue(element, builder, "bind-address");
ParsingUtils.setPropertyValue(element, builder, "start-port");
ParsingUtils.setPropertyValue(element, builder, "end-port");
ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size");
ParsingUtils.setPropertyValue(element, builder, "manual-start");
ParsingUtils.setPropertyValue(element, builder, "maximum-time-between-pings");
ParsingUtils.setPropertyValue(element, builder, "bind-address");
ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size");
ParsingUtils.parseTransportFilters(element, parserContext, builder);
}
}

View File

@@ -25,7 +25,8 @@ import org.w3c.dom.Element;
/**
* @author David Turanski
*
* @author John Blum
* @see org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser
*/
class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser {
@@ -36,12 +37,12 @@ class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
String cacheRef = element.getAttribute("cache-ref");
// add cache reference (fallback to default if nothing is specified)
builder.addConstructorArgReference((StringUtils.hasText(cacheRef) ? cacheRef
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
: GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME));
ParsingUtils.setPropertyValue(element, builder, NAME_ATTRIBUTE);
ParsingUtils.setPropertyValue(element, builder, "alert-threshold");
ParsingUtils.setPropertyValue(element, builder, "batch-size");
ParsingUtils.setPropertyValue(element, builder, "batch-time-interval");
@@ -52,39 +53,40 @@ class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser {
ParsingUtils.setPropertyValue(element, builder, "manual-start");
ParsingUtils.setPropertyValue(element, builder, "maximum-queue-memory");
ParsingUtils.setPropertyValue(element, builder, "order-policy");
ParsingUtils.setPropertyValue(element, builder, "parallel");
ParsingUtils.setPropertyValue(element, builder, "persistent");
ParsingUtils.setPropertyValue(element, builder, "remote-distributed-system-id");
ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size");
ParsingUtils.setPropertyValue(element, builder, "socket-read-timeout");
ParsingUtils.setPropertyValue(element, builder, "persistent");
ParsingUtils.setPropertyValue(element, builder, "parallel");
ParsingUtils.setPropertyValue(element, builder, NAME_ATTRIBUTE);
Element eventFilterElement = DomUtils.getChildElementByTagName(element, "event-filter");
if (eventFilterElement != null) {
builder.addPropertyValue("eventFilters",
ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, eventFilterElement, builder));
builder.addPropertyValue("eventFilters", ParsingUtils.parseRefOrNestedBeanDeclaration(
parserContext, eventFilterElement, builder));
}
ParsingUtils.parseTransportFilters(element, parserContext, builder);
/**
* set the name for an inner bean
*/
// set the name for the GatewaySender as an inner bean
if (!StringUtils.hasText(element.getAttribute(NAME_ATTRIBUTE))) {
if (element.getParentNode().getNodeName().endsWith("region")) {
Element region = (Element) element.getParentNode();
String regionName = StringUtils.hasText(region.getAttribute("name")) ? region.getAttribute("name")
: region.getAttribute("id");
int i = 0;
String name = regionName + ".gatewaySender#" + i;
while (parserContext.getRegistry().isBeanNameInUse(name)) {
i++;
name = regionName + ".gatewaySender#" + i;
String regionName = (StringUtils.hasText(region.getAttribute(NAME_ATTRIBUTE))
? region.getAttribute(NAME_ATTRIBUTE) : region.getAttribute(ID_ATTRIBUTE));
int number = 0;
String gatewaySenderName = (regionName + ".gatewaySender#" + number);
while (parserContext.getRegistry().isBeanNameInUse(gatewaySenderName)) {
gatewaySenderName = (regionName + ".gatewaySender#" + (++number));
}
builder.addPropertyValue("name", name);
builder.addPropertyValue("name", gatewaySenderName);
}
}
}
}

View File

@@ -27,6 +27,7 @@ import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.management.internal.cli.util.spring.StringUtils;
/**
* Base class for GemFire WAN Gateway component factory beans.
@@ -34,7 +35,7 @@ import com.gemstone.gemfire.cache.Cache;
* @author David Turanski
* @author John Blum
*/
public abstract class AbstractWANComponentFactoryBean<T> implements FactoryBean<T>, InitializingBean, BeanNameAware,
public abstract class AbstractWANComponentFactoryBean<T> implements BeanNameAware, FactoryBean<T>, InitializingBean,
DisposableBean {
protected static final List<String> VALID_ORDER_POLICIES = Arrays.asList("KEY", "PARTITION", "THREAD");
@@ -51,34 +52,24 @@ public abstract class AbstractWANComponentFactoryBean<T> implements FactoryBean<
protected AbstractWANComponentFactoryBean(final Cache cache) {
this.cache = cache;
}
public void setName(String name) {
@Override
public final void setBeanName(final String beanName) {
this.beanName = beanName;
}
public void setFactory(Object factory) {
this.factory = factory;
}
public void setName(final String name) {
this.name = name;
}
public String getName() {
return (name != null ? name: beanName);
return (StringUtils.hasText(name) ? name: beanName);
}
@Override
public void destroy() throws Exception {
// TODO Auto-generated method stub
}
@Override
public final void setBeanName(String beanName) {
this.beanName = beanName;
}
@Override
public final void afterPropertiesSet() throws Exception {
Assert.notNull(getName(), "Name cannot be null");
Assert.notNull(cache, "Cache cannot be null");
doInit();
}
protected abstract void doInit() throws Exception;
@Override
public abstract T getObject() throws Exception;
@@ -89,9 +80,18 @@ public abstract class AbstractWANComponentFactoryBean<T> implements FactoryBean<
public final boolean isSingleton() {
return true;
}
public void setFactory(Object factory) {
this.factory = factory;
@Override
public final void afterPropertiesSet() throws Exception {
Assert.notNull(getName(), "Name must not be null.");
Assert.notNull(cache, "Cache must not be null.");
doInit();
}
protected abstract void doInit() throws Exception;
@Override
public void destroy() throws Exception {
}
}

View File

@@ -15,8 +15,10 @@
*/
package org.springframework.data.gemfire.wan;
import java.io.IOException;
import java.util.List;
import org.springframework.context.SmartLifecycle;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -29,20 +31,26 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
* FactoryBean for creating a GemFire {@link GatewayReceiver}.
*
* @author David Turanski
*
* @author John Blum
* @see org.springframework.data.gemfire.wan.AbstractWANComponentFactoryBean
* @see com.gemstone.gemfire.cache.Cache
* @see com.gemstone.gemfire.cache.wan.GatewayReceiver
* @see com.gemstone.gemfire.cache.wan.GatewayReceiverFactory
* @since 1.2.2
*/
public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<GatewayReceiver> {
private GatewayReceiver gatewayReceiver;
public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<GatewayReceiver>
implements SmartLifecycle {
private List<GatewayTransportFilter> transportFilters;
private boolean manualStart = false;
private Integer startPort;
private volatile GatewayReceiver gatewayReceiver;
private Integer endPort;
private Integer maximumTimeBetweenPings;
private Integer socketBufferSize;
private Integer startPort;
private List<GatewayTransportFilter> transportFilters;
private String bindAddress;
@@ -63,44 +71,48 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
@Override
public Class<?> getObjectType() {
return GatewayReceiver.class;
return (gatewayReceiver != null ? gatewayReceiver.getClass() : GatewayReceiver.class);
}
@Override
protected void doInit() throws Exception {
GatewayReceiverFactory gatewayReceiverFactory = cache.createGatewayReceiverFactory();
if (!CollectionUtils.isEmpty(transportFilters)) {
for (GatewayTransportFilter transportFilter : transportFilters) {
gatewayReceiverFactory.addGatewayTransportFilter(transportFilter);
}
}
int minPort = (startPort == null) ? GatewayReceiver.DEFAULT_START_PORT : startPort;
int maxPort = (endPort == null) ? GatewayReceiver.DEFAULT_END_PORT : endPort;
Assert.isTrue(minPort <= maxPort, "startPort must be less then or equal to " + maxPort);
gatewayReceiverFactory.setStartPort(minPort);
gatewayReceiverFactory.setEndPort(maxPort);
if (socketBufferSize != null) {
gatewayReceiverFactory.setSocketBufferSize(socketBufferSize);
}
if (maximumTimeBetweenPings != null) {
gatewayReceiverFactory.setMaximumTimeBetweenPings(maximumTimeBetweenPings);
}
if (bindAddress != null) {
gatewayReceiverFactory.setBindAddress(bindAddress);
}
int minPort = (startPort != null ? startPort : GatewayReceiver.DEFAULT_START_PORT);
int maxPort = (endPort != null ? endPort : GatewayReceiver.DEFAULT_END_PORT);
Assert.isTrue(minPort <= maxPort, String.format("'startPort' must be less than or equal to %1$d.", maxPort));
gatewayReceiverFactory.setStartPort(minPort);
gatewayReceiverFactory.setEndPort(maxPort);
if (maximumTimeBetweenPings != null) {
gatewayReceiverFactory.setMaximumTimeBetweenPings(maximumTimeBetweenPings);
}
if (socketBufferSize != null) {
gatewayReceiverFactory.setSocketBufferSize(socketBufferSize);
}
gatewayReceiver = gatewayReceiverFactory.create();
gatewayReceiver.start();
}
public void setGatewayReceiver(GatewayReceiver gatewayReceiver) {
public void setGatewayReceiver(final GatewayReceiver gatewayReceiver) {
this.gatewayReceiver = gatewayReceiver;
}
public void setTransportFilters(List<GatewayTransportFilter> transportFilters) {
this.transportFilters = transportFilters;
public void setBindAddress(String bindAddress) {
this.bindAddress = bindAddress;
}
public void setStartPort(Integer startPort) {
@@ -111,6 +123,10 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
this.endPort = endPort;
}
public void setManualStart(Boolean manualStart) {
this.manualStart = Boolean.TRUE.equals(manualStart);
}
public void setMaximumTimeBetweenPings(Integer maximumTimeBetweenPings) {
this.maximumTimeBetweenPings = maximumTimeBetweenPings;
}
@@ -119,8 +135,48 @@ public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean<
this.socketBufferSize = socketBufferSize;
}
public void setBindAddress(String bindAddress) {
this.bindAddress = bindAddress;
public void setTransportFilters(List<GatewayTransportFilter> transportFilters) {
this.transportFilters = transportFilters;
}
@Override
public boolean isAutoStartup() {
return !manualStart;
}
@Override
public int getPhase() {
return Integer.MAX_VALUE;
}
@Override
public boolean isRunning() {
return gatewayReceiver.isRunning();
}
@Override
public void start() {
Assert.state(gatewayReceiver != null, "The GatewayReceiver was not properly configured and initialized!");
if (!isRunning()) {
try {
gatewayReceiver.start();
}
catch (IOException e) {
throw new RuntimeException("Failed to start Gateway Receiver due to I/O error.", e);
}
}
}
@Override
public void stop() {
gatewayReceiver.stop();
}
@Override
public void stop(final Runnable callback) {
stop();
callback.run();
}
}

View File

@@ -33,6 +33,13 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
*
* @author David Turanski
* @author John Blum
* @see org.springframework.context.SmartLifecycle
* @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.wan.GatewaySender
* @see com.gemstone.gemfire.cache.wan.GatewaySenderFactory
* @since 1.2.2
*/
@SuppressWarnings("unused")
public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<GatewaySender>
@@ -81,7 +88,7 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
@Override
public Class<?> getObjectType() {
return GatewaySender.class;
return (gatewaySender != null ? gatewaySender.getClass() : GatewaySender.class);
}
@Override
@@ -159,6 +166,7 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
GatewaySenderWrapper wrapper = new GatewaySenderWrapper(gatewaySenderFactory.create(getName(),
remoteDistributedSystemId));
wrapper.setManualStart(manualStart);
gatewaySender = wrapper;
}
@@ -204,7 +212,7 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
}
public void setManualStart(Boolean manualStart) {
this.manualStart = manualStart;
this.manualStart = Boolean.TRUE.equals(manualStart);
}
public void setMaximumQueueMemory(Integer maximumQueueMemory) {
@@ -247,12 +255,38 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
this.socketReadTimeout = socketReadTimeout;
}
/* (non-Javadoc)
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
*/
@Override
public boolean isAutoStartup() {
return !manualStart;
}
/* (non-Javadoc)
* @see org.springframework.context.Phased#getPhase()
*/
@Override
public int getPhase() {
return Integer.MAX_VALUE;
}
/* (non-Javadoc)
* @see org.springframework.context.Lifecycle#isRunning()
*/
@Override
public boolean isRunning() {
return gatewaySender.isRunning();
}
/* (non-Javadoc)
* @see org.springframework.context.Lifecycle#start()
*/
@Override
public synchronized void start() {
if (!gatewaySender.isRunning()){
Assert.notNull(gatewaySender, "The GatewaySender was not properly configured and initialized!");
if (!isRunning()){
gatewaySender.start();
}
}
@@ -265,30 +299,6 @@ public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean<Ga
gatewaySender.stop();
}
/* (non-Javadoc)
* @see org.springframework.context.Lifecycle#isRunning()
*/
@Override
public boolean isRunning() {
return gatewaySender.isRunning();
}
/* (non-Javadoc)
* @see org.springframework.context.Phased#getPhase()
*/
@Override
public int getPhase() {
return Integer.MAX_VALUE;
}
/* (non-Javadoc)
* @see org.springframework.context.SmartLifecycle#isAutoStartup()
*/
@Override
public boolean isAutoStartup() {
return !manualStart;
}
/* (non-Javadoc)
* @see org.springframework.context.SmartLifecycle#stop(java.lang.Runnable)
*/

View File

@@ -1,21 +1,29 @@
package org.springframework.data.gemfire.wan;
import java.util.List;
import org.springframework.util.Assert;
import com.gemstone.gemfire.cache.util.Gateway;
import com.gemstone.gemfire.cache.wan.GatewayEventFilter;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
import java.util.List;
/**
* Created by dturanski on 9/16/13.
* @author David Turanski
* @author John Blum
* @see com.gemstone.gemfire.cache.util.Gateway
* @see com.gemstone.gemfire.cache.wan.GatewaySender
*/
public class GatewaySenderWrapper implements GatewaySender {
private final GatewaySender delegate;
private boolean manualStart;
public GatewaySenderWrapper(GatewaySender delegate) {
this.delegate = delegate;
private final GatewaySender delegate;
public GatewaySenderWrapper(final GatewaySender gatewaySender) {
Assert.notNull(gatewaySender, "The target Gateway Sender must not be null.");
this.delegate = gatewaySender;
}
@Override
@@ -151,4 +159,10 @@ public class GatewaySenderWrapper implements GatewaySender {
public void setManualStart(boolean manualStart) {
this.manualStart = manualStart;
}
@Override
public String toString() {
return this.delegate.toString();
}
}

View File

@@ -2454,43 +2454,18 @@ Optionally specifies the GemFire gateway sender id. By default this value is the
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="remote-distributed-system-id" type="xsd:string"
use="required">
<xsd:attribute name="remote-distributed-system-id" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the remote distributed system id, an integer value representing the remote distributed system
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="manual-start" type="xsd:string"
use="optional">
<xsd:attribute name="alert-threshold" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies if the gateway sender is manually (true) or automatically(false) started
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-buffer-size" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the socket buffer size in bytes
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-read-timeout" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the socket read timeout in milliseconds
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="enable-batch-conflation" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies whether batch conflation is enabled (true or false)
Specifies the alert threshold in miliseconds, indicating the maximum time elapsed from when the gateway sent the message
to when the acknowldgement was received from the gateway receiver.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -2502,20 +2477,24 @@ The maximum time interval that can elapse before a partial batch is sent from a
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="alert-threshold" type="xsd:string"
use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the alert threshold in miliseconds, indicating the maximum time elapsed from when the gateway sent the message
to when the acknowldgement was received from the gateway receiver.
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="dispatcher-threads" type="xsd:string"
use="optional">
<xsd:attribute name="dispatcher-threads" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the number of dispatcher threads to allocate to the gateway sender
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="enable-batch-conflation" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies whether batch conflation is enabled (true or false)
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="manual-start" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies if the gateway sender is manually (true) or automatically (false) started. Default is an automatic start (false).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -2527,6 +2506,20 @@ Specifies the order policy. Order policy only applies if the gateway sender que
KEY: Indicates that events will be concurrently processed based on the event's key,
PARTITION: Indicates that events will be concurrently processed based on the event's partition (using the PartitionResolver)
THREAD: Indicates that events will be concurrently processed based on the event's originating member and thread
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-buffer-size" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the socket buffer size in bytes
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-read-timeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the socket read timeout in milliseconds
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
@@ -2540,23 +2533,14 @@ Specifies the batch size
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="persistent" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies whether persistence is enabled: true or false(default)
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="disk-store-ref" type="xsd:string"
use="optional">
<xsd:attribute name="disk-store-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Indicates the id of disk store to use for persistence
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maximum-queue-memory" type="xsd:string"
use="optional">
<xsd:attribute name="maximum-queue-memory" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the maximum memory in MB to allocate for the queue
@@ -2570,6 +2554,13 @@ Specifies the maximum memory in MB to allocate for the queue
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="persistent" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies whether persistence is enabled: true or false(default)
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:attributeGroup>
<!-- -->
<xsd:complexType name="gatewayReceiverType">
@@ -2587,6 +2578,27 @@ A gateway receiver definition (requires Gemfire 7.0 or later)
<xsd:element name="transport-filter" type="gatewayTransportFilterType"
minOccurs="0" maxOccurs="1" />
</xsd:sequence>
<xsd:attribute name="id" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The id of this bean definition
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The id of the cache - default is gemfireCache
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="bind-address" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the bind address (IP address or host name) for the gateway receiver
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="start-port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
@@ -2601,44 +2613,27 @@ Specifies the upper end of a port range to use for the gateway receiver
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="bind-address" type="xsd:string"
use="optional">
<xsd:attribute name="manual-start" type="xsd:string" default="false">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the bind address (IP address or host name) for the gateway receiver
Specifies if the gateway receiver is manually (true) or automatically (false) started. Default is an automatic start (false).
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maximum-time-between-pings" type="xsd:string"
use="optional">
<xsd:attribute name="maximum-time-between-pings" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the maximum time between pings in milliseconds
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-buffer-size" type="xsd:string"
use="optional">
<xsd:attribute name="socket-buffer-size" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Specifies the socket buffer size in bytes
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="id" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The id of this bean definition
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cache-ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The id of the cache - default is gemfireCache
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
<!-- -->
<xsd:complexType name="baseAsyncEventQueueType">

View File

@@ -0,0 +1,84 @@
/*
* Copyright 2010-2013 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.gemfire.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.data.gemfire.test.GemfireTestApplicationContextInitializer;
import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The GatewayReceiverNamespaceTest class is a test suite of test cases testing the contract and functionality of
* Gateway Receiver configuration in Spring Data GemFire using the XML namespace and schema (XSD).
*
* @author John Blum
* @see org.junit.Test
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(initializers = GemfireTestApplicationContextInitializer.class)
@SuppressWarnings("unused")
public class GatewayReceiverNamespaceTest {
@Resource(name = "&Default")
private GatewayReceiverFactoryBean defaultFactoryBean;
@Resource(name = "&Auto")
private GatewayReceiverFactoryBean autoGatewayReceiver;
@Resource(name = "&Manual")
private GatewayReceiverFactoryBean manualGatewayReceiver;
@Test
public void testDefault() throws Exception {
assertNotNull("The 'Default' GatewayReceiverFactoryBean was not properly configured and initialized!", defaultFactoryBean);
assertTrue(defaultFactoryBean.isAutoStartup());
GatewayReceiver defaultGatewayReceiver = defaultFactoryBean.getObject();
assertNotNull(defaultGatewayReceiver);
assertEquals("192.168.0.1", defaultGatewayReceiver.getBindAddress());
assertEquals(12345, defaultGatewayReceiver.getStartPort());
assertEquals(54321, defaultGatewayReceiver.getEndPort());
assertEquals(5000, defaultGatewayReceiver.getMaximumTimeBetweenPings());
assertEquals(32768, defaultGatewayReceiver.getSocketBufferSize());
}
@Test
public void testAuto() {
assertNotNull("The 'Auto' GatewayReceiverFactoryBean was not properly configured and initialized!", autoGatewayReceiver);
assertTrue(autoGatewayReceiver.isAutoStartup());
}
@Test
public void testManual() {
assertNotNull("The 'Manual' GatewayReceiverFactoryBean was not properly configured and initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isAutoStartup());
}
}

View File

@@ -27,13 +27,15 @@ import com.gemstone.gemfire.cache.wan.GatewayTransportFilter;
*
*/
public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
private int startPort;
private int endPort;
private String bindAddress;
private List<GatewayTransportFilter> gatewayTransportFilters = new ArrayList<GatewayTransportFilter>();
private int maximumTimeBetweenPings;
private int socketBufferSize;
private int startPort;
private List<GatewayTransportFilter> gatewayTransportFilters = new ArrayList<GatewayTransportFilter>();
private String bindAddress;
private String hostnameForClients;
/* (non-Javadoc)
@@ -115,14 +117,15 @@ public class StubGatewayReceiverFactory implements GatewayReceiverFactory {
@Override
public GatewayReceiver create() {
GatewayReceiver gatewayReceiver = mock(GatewayReceiver.class);
when(gatewayReceiver.getBindAddress()).thenReturn(this.bindAddress);
when(gatewayReceiver.getEndPort()).thenReturn(this.endPort);
when(gatewayReceiver.getGatewayTransportFilters()).thenReturn(this.gatewayTransportFilters);
when(gatewayReceiver.getHost()).thenReturn(this.hostnameForClients);
when(gatewayReceiver.getMaximumTimeBetweenPings()).thenReturn(this.maximumTimeBetweenPings);
when(gatewayReceiver.getSocketBufferSize()).thenReturn(this.socketBufferSize);
when(gatewayReceiver.getStartPort()).thenReturn(this.startPort);
when(gatewayReceiver.getHost()).thenReturn(this.hostnameForClients);
return gatewayReceiver;
}

View File

@@ -0,0 +1,94 @@
/*
* 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 static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.gemstone.gemfire.cache.wan.GatewayReceiver;
/**
* The ManualGatewayReceiverStartIntegrationTest class is a test suite of test cases testing the manual start capability
* of Gateway Receivers when configured with the Spring Data GemFire XML namespace.
*
* @author John Blum
* @see org.junit.Test
* @see org.junit.runner.RunWith
* @see org.springframework.test.context.ContextConfiguration
* @see org.springframework.test.context.junit4.SpringJUnit4ClassRunner
* @since 1.5.0
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@SuppressWarnings("unused")
public class ManualGatewayReceiverStartIntegrationTest {
@Resource(name = "Auto")
private GatewayReceiver autoGatewayReceiver;
@Resource(name = "Manual")
private GatewayReceiver manualGatewayReceiver;
@Test
public void testAutoGatewayReceiver() {
assertNotNull("The 'Auto' GatewayReceiver was not properly configured or initialized!", autoGatewayReceiver);
assertEquals(7070, autoGatewayReceiver.getStartPort());
assertEquals(7700, autoGatewayReceiver.getEndPort());
assertTrue(autoGatewayReceiver.isRunning());
final int gatewayReceiverPort = autoGatewayReceiver.getPort();
assertTrue(gatewayReceiverPort >= autoGatewayReceiver.getStartPort()
&& gatewayReceiverPort <= autoGatewayReceiver.getEndPort());
autoGatewayReceiver.stop();
assertFalse(autoGatewayReceiver.isRunning());
}
@Test
public void testManualGatewayReceiverConfiguration() throws IOException {
assertNotNull("The 'Manual' GatewayReceiver was not properly configured or initialized!", manualGatewayReceiver);
assertFalse(manualGatewayReceiver.isRunning());
assertEquals(6060, manualGatewayReceiver.getStartPort());
assertEquals(6600, manualGatewayReceiver.getEndPort());
manualGatewayReceiver.start();
assertTrue(manualGatewayReceiver.isRunning());
final int gateReceiverPort = manualGatewayReceiver.getPort();
assertTrue(gateReceiverPort >= manualGatewayReceiver.getStartPort()
&& gateReceiverPort <= manualGatewayReceiver.getEndPort());
manualGatewayReceiver.stop();
assertFalse(manualGatewayReceiver.isRunning());
}
}

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
">
<gfe:cache/>
<gfe:gateway-receiver id="Default" bind-address="192.168.0.1" start-port="12345" end-port="54321"
maximum-time-between-pings="5000" socket-buffer-size="32768"/>
<gfe:gateway-receiver id="Auto" manual-start="false"/>
<gfe:gateway-receiver id="Manual" manual-start="true"/>
</beans>

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:gfe="http://www.springframework.org/schema/gemfire"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
">
<util:properties id="gemfirePeerCacheConfigurationSettings">
<prop key="name">SpringDataGemFirePeerCache</prop>
<prop key="mcast-port">0</prop>
<prop key="log-level">config</prop>
</util:properties>
<gfe:cache properties-ref="gemfirePeerCacheConfigurationSettings"/>
<gfe:replicated-region id="Example" persistent="false"/>
<gfe:gateway-receiver id="Auto" start-port="7070" end-port="7700"/>
<gfe:gateway-receiver id="Manual" start-port="6060" end-port="6600" manual-start="true"/>
</beans>