SGF-396 - Enable support for variable Locator and Server endpoints on a SDG GFE Pool bean definition in a Spring Context.

This commit is contained in:
John Blum
2015-04-13 18:53:35 -07:00
parent d931897c0e
commit ee392c6b7f
6 changed files with 474 additions and 104 deletions

View File

@@ -31,6 +31,9 @@ import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
import com.gemstone.gemfire.cache.server.CacheServer;
import com.gemstone.gemfire.internal.DistributionLocator;
/**
* Parser for GFE <pool;gt; bean definitions.
*
@@ -40,7 +43,18 @@ import org.w3c.dom.Element;
*/
class PoolParser extends AbstractSimpleBeanDefinitionParser {
@Override
protected static final int DEFAULT_LOCATOR_PORT = DistributionLocator.DEFAULT_LOCATOR_PORT;
protected static final int DEFAULT_SERVER_PORT = CacheServer.DEFAULT_PORT;
protected static final String DEFAULT_HOST = "localhost";
protected static final String HOST_ATTRIBUTE_NAME = "host";
protected static final String LOCATOR_ELEMENT_NAME = "locator";
protected static final String LOCATORS_ATTRIBUTE_NAME = "locators";
protected static final String PORT_ATTRIBUTE_NAME = "port";
protected static final String SERVER_ELEMENT_NAME = "server";
protected static final String SERVERS_ATTRIBUTE_NAME = "servers";
@Override
protected Class<?> getBeanClass(Element element) {
return PoolFactoryBean.class;
}
@@ -49,21 +63,24 @@ class PoolParser extends AbstractSimpleBeanDefinitionParser {
protected void postProcess(BeanDefinitionBuilder builder, Element element) {
List<Element> subElements = DomUtils.getChildElements(element);
ManagedList<Object> locators = new ManagedList<Object>(subElements.size());
ManagedList<Object> servers = new ManagedList<Object>(subElements.size());
ManagedList<BeanDefinition> locators = new ManagedList<BeanDefinition>(subElements.size());
ManagedList<BeanDefinition> servers = new ManagedList<BeanDefinition>(subElements.size());
// parse nested locator/server elements
for (Element subElement : subElements) {
String name = subElement.getLocalName();
if ("locator".equals(name)) {
if (LOCATOR_ELEMENT_NAME.equals(name)) {
locators.add(parseLocator(subElement));
}
if ("server".equals(name)) {
if (SERVER_ELEMENT_NAME.equals(name)) {
servers.add(parseServer(subElement));
}
}
locators.addAll(parseLocators(element));
servers.addAll(parseServers(element));
if (!locators.isEmpty()) {
builder.addPropertyValue("locators", locators);
}
@@ -74,24 +91,89 @@ class PoolParser extends AbstractSimpleBeanDefinitionParser {
}
/* (non-Javadoc) */
private BeanDefinition parseConnection(Element element) {
BeanDefinition buildConnection(String host, String port, boolean server) {
BeanDefinitionBuilder inetSocketAddressBuilder = BeanDefinitionBuilder.genericBeanDefinition(
InetSocketAddress.class);
inetSocketAddressBuilder.addConstructorArgValue(element.getAttribute("host"));
inetSocketAddressBuilder.addConstructorArgValue(element.getAttribute("port"));
inetSocketAddressBuilder.addConstructorArgValue(defaultHost(host));
inetSocketAddressBuilder.addConstructorArgValue(defaultPort(port, server));
return inetSocketAddressBuilder.getBeanDefinition();
}
/* (non-Javadoc) */
private Object parseLocator(Element subElement) {
return parseConnection(subElement);
String defaultHost(String host) {
return (StringUtils.hasText(host) ? host : DEFAULT_HOST);
}
/* (non-Javadoc) */
private Object parseServer(Element subElement) {
return parseConnection(subElement);
String defaultPort(String port, boolean server) {
return (StringUtils.hasText(port) ? port : (server ? String.valueOf(DEFAULT_SERVER_PORT)
: String.valueOf(DEFAULT_LOCATOR_PORT)));
}
/* (non-Javadoc) */
ManagedList<BeanDefinition> parseConnections(String hostPortCommaDelimitedList, boolean server) {
ManagedList<BeanDefinition> connections = new ManagedList<BeanDefinition>();
if (StringUtils.hasText(hostPortCommaDelimitedList)) {
String[] hostPorts = hostPortCommaDelimitedList.split(",");
for (String hostPort : hostPorts) {
connections.add(parseConnection(hostPort, server));
}
}
return connections;
}
/* (non-Javadoc) */
BeanDefinition parseConnection(String hostPort, boolean server) {
String port = defaultPort(null, server);
String host;
int portIndex = hostPort.indexOf('[');
if (portIndex > -1) {
host = hostPort.substring(0, portIndex).trim();
port = parseDigits(hostPort.substring(portIndex)).trim();
}
else {
host = hostPort.trim();
}
return buildConnection(host, port, server);
}
/* (non-Javadoc) */
String parseDigits(String value) {
StringBuilder digits = new StringBuilder();
for (char chr : value.toCharArray()) {
if (Character.isDigit(chr)) {
digits.append(chr);
}
}
return digits.toString();
}
/* (non-Javadoc) */
BeanDefinition parseLocator(Element element) {
return buildConnection(element.getAttribute(HOST_ATTRIBUTE_NAME), element.getAttribute(PORT_ATTRIBUTE_NAME), false);
}
ManagedList<BeanDefinition> parseLocators(Element element) {
return parseConnections(element.getAttribute(LOCATORS_ATTRIBUTE_NAME), false);
}
/* (non-Javadoc) */
BeanDefinition parseServer(Element element) {
return buildConnection(element.getAttribute(HOST_ATTRIBUTE_NAME), element.getAttribute(PORT_ATTRIBUTE_NAME), false);
}
ManagedList<BeanDefinition> parseServers(Element element) {
return parseConnections(element.getAttribute(SERVERS_ATTRIBUTE_NAME), true);
}
/* (non-Javadoc) */

View File

@@ -2061,46 +2061,43 @@ Note that in order to instantiate a pool, a GemFire cache needs to be already st
<xsd:attribute name="id" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the pool definition (by default "gemfirePool").]]></xsd:documentation>
The name of the pool definition (by default "gemfirePool").
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="free-connection-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="idle-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="load-conditioning-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="keep-alive" type="xsd:string" use="optional" />
<xsd:attribute name="max-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="min-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="multi-user-authentication" type="xsd:string"
use="optional" />
<xsd:attribute name="ping-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="pr-single-hop-enabled" type="xsd:string"
use="optional" />
<xsd:attribute name="read-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="retry-attempts" type="xsd:string"
use="optional" />
<xsd:attribute name="server-group" type="xsd:string"
use="optional" />
<xsd:attribute name="socket-buffer-size" type="xsd:string"
use="optional" />
<xsd:attribute name="statistic-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-ack-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-enabled" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-message-tracking-timeout"
type="xsd:string" use="optional" />
<xsd:attribute name="subscription-redundancy" type="xsd:string"
use="optional" />
<xsd:attribute name="thread-local-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="free-connection-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="idle-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="load-conditioning-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="keep-alive" type="xsd:string" use="optional"/>
<xsd:attribute name="locators" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Comma-delimited list of Locator endpoints used by this Pool in the form of: host1[port1],host2[port2],...,hostN[portN]
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="max-connections" type="xsd:string" use="optional"/>
<xsd:attribute name="min-connections" type="xsd:string" use="optional"/>
<xsd:attribute name="multi-user-authentication" type="xsd:string" use="optional"/>
<xsd:attribute name="ping-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="pr-single-hop-enabled" type="xsd:string" use="optional"/>
<xsd:attribute name="read-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="retry-attempts" type="xsd:string" use="optional"/>
<xsd:attribute name="server-group" type="xsd:string" use="optional"/>
<xsd:attribute name="servers" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Comma-delimited list of Server endpoints used by this Pool in the form of: host1[port1],host2[port2],...,hostN[portN]
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-buffer-size" type="xsd:string" use="optional"/>
<xsd:attribute name="statistic-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-ack-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-enabled" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-message-tracking-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-redundancy" type="xsd:string" use="optional"/>
<xsd:attribute name="thread-local-connections" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- -->

View File

@@ -2061,46 +2061,43 @@ Note that in order to instantiate a pool, a GemFire cache needs to be already st
<xsd:attribute name="id" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
The name of the pool definition (by default "gemfirePool").]]></xsd:documentation>
The name of the pool definition (by default "gemfirePool").
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="free-connection-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="idle-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="load-conditioning-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="keep-alive" type="xsd:string" use="optional" />
<xsd:attribute name="max-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="min-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="multi-user-authentication" type="xsd:string"
use="optional" />
<xsd:attribute name="ping-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="pr-single-hop-enabled" type="xsd:string"
use="optional" />
<xsd:attribute name="read-timeout" type="xsd:string"
use="optional" />
<xsd:attribute name="retry-attempts" type="xsd:string"
use="optional" />
<xsd:attribute name="server-group" type="xsd:string"
use="optional" />
<xsd:attribute name="socket-buffer-size" type="xsd:string"
use="optional" />
<xsd:attribute name="statistic-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-ack-interval" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-enabled" type="xsd:string"
use="optional" />
<xsd:attribute name="subscription-message-tracking-timeout"
type="xsd:string" use="optional" />
<xsd:attribute name="subscription-redundancy" type="xsd:string"
use="optional" />
<xsd:attribute name="thread-local-connections" type="xsd:string"
use="optional" />
<xsd:attribute name="free-connection-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="idle-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="load-conditioning-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="keep-alive" type="xsd:string" use="optional"/>
<xsd:attribute name="locators" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Comma-delimited list of Locator endpoints used by this Pool in the form of: host1[port1],host2[port2],...,hostN[portN]
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="max-connections" type="xsd:string" use="optional"/>
<xsd:attribute name="min-connections" type="xsd:string" use="optional"/>
<xsd:attribute name="multi-user-authentication" type="xsd:string" use="optional"/>
<xsd:attribute name="ping-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="pr-single-hop-enabled" type="xsd:string" use="optional"/>
<xsd:attribute name="read-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="retry-attempts" type="xsd:string" use="optional"/>
<xsd:attribute name="server-group" type="xsd:string" use="optional"/>
<xsd:attribute name="servers" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[
Comma-delimited list of Server endpoints used by this Pool in the form of: host1[port1],host2[port2],...,hostN[portN]
]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="socket-buffer-size" type="xsd:string" use="optional"/>
<xsd:attribute name="statistic-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-ack-interval" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-enabled" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-message-tracking-timeout" type="xsd:string" use="optional"/>
<xsd:attribute name="subscription-redundancy" type="xsd:string" use="optional"/>
<xsd:attribute name="thread-local-connections" type="xsd:string" use="optional"/>
</xsd:complexType>
</xsd:element>
<!-- -->