SGF-15
+ finished parsing support for locators and servers
+ improved schema a bit by adding more up-front validation
This commit is contained in:
costin
2010-09-01 12:04:21 +03:00
parent bdb7a4669e
commit d736c302dd
6 changed files with 96 additions and 29 deletions

View File

@@ -73,7 +73,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
private int socketBufferSize = PoolFactory.DEFAULT_SOCKET_BUFFER_SIZE;
private int statisticInterval = PoolFactory.DEFAULT_STATISTIC_INTERVAL;
private int subscriptionAckInterval = PoolFactory.DEFAULT_SUBSCRIPTION_ACK_INTERVAL;
private boolean enableSubscription = PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED;
private boolean subscriptionEnabled = PoolFactory.DEFAULT_SUBSCRIPTION_ENABLED;
private int subscriptionMessageTrackingTimeout = PoolFactory.DEFAULT_SUBSCRIPTION_MESSAGE_TRACKING_TIMEOUT;
private int subscriptionRedundancy = PoolFactory.DEFAULT_SUBSCRIPTION_REDUNDANCY;
private boolean threadLocalConnections = PoolFactory.DEFAULT_THREAD_LOCAL_CONNECTIONS;
@@ -139,7 +139,7 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
poolFactory.setServerGroup(serverGroup);
poolFactory.setSocketBufferSize(socketBufferSize);
poolFactory.setStatisticInterval(statisticInterval);
poolFactory.setSubscriptionEnabled(enableSubscription);
poolFactory.setSubscriptionEnabled(subscriptionEnabled);
poolFactory.setSubscriptionAckInterval(subscriptionAckInterval);
poolFactory.setSubscriptionMessageTrackingTimeout(subscriptionMessageTrackingTimeout);
poolFactory.setSubscriptionRedundancy(subscriptionRedundancy);
@@ -284,10 +284,10 @@ public class PoolFactoryBean implements FactoryBean<Pool>, InitializingBean, Dis
}
/**
* @param enableSubscription the enableSubscription to set
* @param subscriptionEnabled the subscriptionEnabled to set
*/
public void setEnableSubscription(boolean enableSubscription) {
this.enableSubscription = enableSubscription;
public void setSubscriptionEnabled(boolean subscriptionEnabled) {
this.subscriptionEnabled = subscriptionEnabled;
}
/**

View File

@@ -16,12 +16,19 @@
package org.springframework.data.gemfire.config;
import java.util.List;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.ManagedList;
import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser;
import org.springframework.beans.factory.xml.ParserContext;
import org.springframework.data.gemfire.client.PoolConnection;
import org.springframework.data.gemfire.client.PoolFactoryBean;
import org.springframework.util.StringUtils;
import org.springframework.util.xml.DomUtils;
import org.w3c.dom.Element;
/**
@@ -29,12 +36,53 @@ import org.w3c.dom.Element;
*
* @author Costin Leau
*/
class PoolParser extends AbstractSingleBeanDefinitionParser {
class PoolParser extends AbstractSimpleBeanDefinitionParser {
protected Class<?> getBeanClass(Element element) {
return PoolFactoryBean.class;
}
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());
// parse nested locator/server elements
for (Element subElement : subElements) {
String name = subElement.getLocalName();
if ("locator".equals(name)) {
locators.add(parseLocator(subElement));
}
if ("server".equals(name)) {
servers.add(parseServer(subElement));
}
}
if (!locators.isEmpty()) {
builder.addPropertyValue("locators", locators);
}
if (!servers.isEmpty()) {
builder.addPropertyValue("servers", servers);
}
}
private Object parseServer(Element subElement) {
return parseConnection(subElement);
}
private Object parseLocator(Element subElement) {
return parseConnection(subElement);
}
private BeanDefinition parseConnection(Element element) {
BeanDefinitionBuilder defBuilder = BeanDefinitionBuilder.genericBeanDefinition(PoolConnection.class);
ParsingUtils.setPropertyValue(element, defBuilder, "host", "host");
ParsingUtils.setPropertyValue(element, defBuilder, "port", "port");
return defBuilder.getBeanDefinition();
}
@Override
protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext)
throws BeanDefinitionStoreException {
@@ -44,4 +92,4 @@ class PoolParser extends AbstractSingleBeanDefinitionParser {
}
return name;
}
}
}