diff --git a/.springBeans b/.springBeans index 4dff6476..08fe5a66 100644 --- a/.springBeans +++ b/.springBeans @@ -1,7 +1,7 @@ 1 - + diff --git a/build.gradle b/build.gradle index 7ad02d00..333af648 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ repositories { maven { url "http://repo.springsource.org/libs-snapshot" } maven { url "http://repo.springsource.org/plugins-release" } maven { url "http://repo1.maven.org/maven2" } + mavenLocal() } diff --git a/gradle.properties b/gradle.properties index d3ceb21a..fcff683b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,8 +6,9 @@ slf4jVersion = 1.6.4 # Common libraries springVersion = 3.1.1.RELEASE -springDataCommonsVersion = 1.3.0.BUILD-SNAPSHOT -gemfireVersion = 6.6.3 +springDataCommonsVersion = 1.3.2.BUILD-SNAPSHOT +#gemfireVersion = 6.6.3 +gemfireVersion = 7.0 # Testing junitVersion = 4.8.1 diff --git a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java index bafab68a..965bc84e 100644 --- a/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/RegionFactoryBean.java @@ -17,7 +17,6 @@ package org.springframework.data.gemfire; import java.lang.reflect.Field; -import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,6 +27,7 @@ import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; +import com.gemstone.gemfire.cache.AsyncEventQueue; import com.gemstone.gemfire.cache.AttributesFactory; import com.gemstone.gemfire.cache.Cache; import com.gemstone.gemfire.cache.CacheClosedException; @@ -39,11 +39,12 @@ import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.RegionFactory; import com.gemstone.gemfire.cache.Scope; +import com.gemstone.gemfire.cache.wan.GatewaySender; /** - * FactoryBean for creating generic GemFire {@link Region}s. Will try to first - * locate the region (by name) and, in case none if found, proceed to creating - * one using the given settings. + * Base class for FactoryBeans used to create GemFire {@link Region}s. Will try + * to first locate the region (by name) and, in case none if found, proceed to + * creating one using the given settings. * * Note that this factory bean allows for very flexible creation of GemFire * {@link Region}. For "client" regions however, see @@ -69,20 +70,26 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean cacheWriter; + private GatewaySender gatewaySenders[]; + + private AsyncEventQueue asyncEventQueues[]; + private RegionAttributes attributes; private Scope scope; private boolean persistent; + private Boolean enableGateway; + + private String hubId; + private String diskStoreName; private String dataPolicyName; private Region region; - private List> subRegions; - @Override public void afterPropertiesSet() throws Exception { super.afterPropertiesSet(); @@ -102,12 +109,39 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean regionFactory = (attributes != null ? c.createRegionFactory(attributes) : c . createRegionFactory()); + if (hubId != null) { + enableGateway = enableGateway == null ? true : enableGateway; + Assert.isTrue(enableGateway, "hubId requires the enableGateway property to be true"); + + regionFactory.setGatewayHubId(hubId); + } + if (enableGateway != null) { + if (enableGateway) { + Assert.notNull(hubId, "enableGateway requires the hubId property to be true"); + } + regionFactory.setEnableGateway(enableGateway); + } if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener listener : cacheListeners) { regionFactory.addCacheListener(listener); } } + if (!ObjectUtils.isEmpty(gatewaySenders)) { + Assert.isTrue( + hubId == null, + "It is invalid to configure a region with both a hubId and gatewaySenders. Note that the enableGateway and hubId properties are deprecated since Gemfire 7.0"); + for (GatewaySender gatewaySender : gatewaySenders) { + regionFactory.addGatewaySender(gatewaySender); + } + } + + if (!ObjectUtils.isEmpty(asyncEventQueues)) { + for (AsyncEventQueue asyncEventQueue : asyncEventQueues) { + regionFactory.addAsyncEventQueue(asyncEventQueue); + } + } + if (cacheLoader != null) { regionFactory.setCacheLoader(cacheLoader); } @@ -256,11 +290,6 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean> subRegions) { - log.info("setting subRegions"); - this.subRegions = subRegions; - } - /** * Sets the cache loader used for the region used by this factory. Used only * when a new region is created.Overrides the settings specified through @@ -315,6 +344,22 @@ public abstract class RegionFactoryBean extends RegionLookupFactoryBean subElements = DomUtils.getChildElements(element); - - // parse nested elements for (Element subElement : subElements) { - String name = subElement.getLocalName(); - - if ("cache-listener".equals(name)) { - builder.addPropertyValue("cacheListeners", parseCacheListener(parserContext, subElement, builder)); + if (subElement.getLocalName().equals("cache-listener")) { + builder.addPropertyValue("cacheListeners", + ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder)); } - - else if ("cache-loader".equals(name)) { - builder.addPropertyValue("cacheLoader", parseCacheLoader(parserContext, subElement, builder)); + else if (subElement.getLocalName().equals("cache-loader")) { + builder.addPropertyValue("cacheLoader", + ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder)); } - - else if ("cache-writer".equals(name)) { - builder.addPropertyValue("cacheWriter", parseCacheWriter(parserContext, subElement, builder)); + else if (subElement.getLocalName().equals("cache-writer")) { + builder.addPropertyValue("cacheWriter", + ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder)); } - // subregion - else if (name.endsWith("region")) { + else if (subElement.getLocalName().endsWith("region")) { doParseSubRegion(element, subElement, parserContext, builder, subRegion); } } + + } + + private void parseCollectionOfCustomSubElements(ParserContext parserContext, Element element, + BeanDefinitionBuilder builder, String className, String subElementName, String propertyName) { + List subElements = DomUtils.getChildElementsByTagName(element, new String[] { subElementName, + subElementName + "-ref" }); + if (!CollectionUtils.isEmpty(subElements)) { + + ManagedArray array = new ManagedArray(className, subElements.size()); + for (Element subElement : subElements) { + array.add(ParsingUtils.parseRefOrNestedCustomElement(parserContext, subElement, builder)); + } + builder.addPropertyValue(propertyName, array); + } } private BeanDefinition parseSubRegion(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { @@ -151,16 +192,4 @@ abstract class AbstractRegionParser extends AliasReplacingBeanDefinitionParser { String name = element.getAttribute(NAME_ATTRIBUTE); return StringUtils.hasText(name) ? name : element.getAttribute(ID_ATTRIBUTE); } - - private Object parseCacheListener(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheLoader(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } - - private Object parseCacheWriter(ParserContext parserContext, Element subElement, BeanDefinitionBuilder builder) { - return ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, subElement, builder); - } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java b/src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java new file mode 100644 index 00000000..0b9b1e71 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/AsyncEventQueueParser.java @@ -0,0 +1,54 @@ +/* + * Copyright 2010-2012 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 org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.wan.AsyncEventQueueFactoryBean; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +import com.gemstone.gemfire.internal.lang.StringUtils; + +/** + * @author David Turanski + * + */ +public class AsyncEventQueueParser extends AbstractSingleBeanDefinitionParser { + + @Override + protected Class getBeanClass(Element element) { + return AsyncEventQueueFactoryBean.class; + } + + @Override + protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + builder.setLazyInit(false); + Element asyncEventListenerElement = DomUtils.getChildElementByTagName(element, "async-event-listener"); + Object asyncEventListener = ParsingUtils.parseRefOrSingleNestedBeanDeclaration(parserContext, + asyncEventListenerElement, builder); + String cacheName = StringUtils.isEmpty(element.getAttribute("cache-ref")) ? "gemfire-cache" : element + .getAttribute("cache-ref"); + builder.addConstructorArgReference(cacheName); + builder.addConstructorArgValue(asyncEventListener); + ParsingUtils.setPropertyValue(element, builder, "batch-size"); + ParsingUtils.setPropertyValue(element, builder, "maximum-queue-memory"); + ParsingUtils.setPropertyValue(element, builder, "disk-store-ref"); + ParsingUtils.setPropertyValue(element, builder, "persistent"); + ParsingUtils.setPropertyValue(element, builder, "parallel"); + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/GatewayHubParser.java b/src/main/java/org/springframework/data/gemfire/config/GatewayHubParser.java new file mode 100644 index 00000000..54535b89 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GatewayHubParser.java @@ -0,0 +1,101 @@ +/* + * Copyright 2010-2012 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 java.util.List; + +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.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; + +/** + * @author David Turanski + * + */ +class GatewayHubParser extends AbstractSimpleBeanDefinitionParser { + @Override + protected Class getBeanClass(Element element) { + return GatewayHubFactoryBean.class; + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @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 : "gemfire-cache")); + ParsingUtils.setPropertyValue(element, builder, "bind-address"); + ParsingUtils.setPropertyValue(element, builder, "manual-start"); + ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size"); + ParsingUtils.setPropertyValue(element, builder, "startup-policy"); + List gatewayElements = DomUtils.getChildElementsByTagName(element, "gateway"); + if (!CollectionUtils.isEmpty(gatewayElements)) { + ManagedList gateways = new ManagedList(); + 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 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); + } + + Element gatewayListenerElement = DomUtils.getChildElementByTagName(gatewayElement, "gateway-listener"); + if (gatewayListenerElement != null) { + Object obj = ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, gatewayListenerElement, + gatewayBuilder); + gatewayBuilder.addPropertyValue("listeners", obj); + } + + 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"); + ParsingUtils.setPropertyValue(gatewayQueueElement, queueBuilder, "enable-batch-conflation"); + gatewayBuilder.addPropertyValue("queue", queueBuilder.getBeanDefinition()); + } + gateways.add(gatewayBuilder.getBeanDefinition()); + } + builder.addPropertyValue("gateways", gateways); + } + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java b/src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java new file mode 100644 index 00000000..afefe8c1 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GatewayReceiverParser.java @@ -0,0 +1,48 @@ +/* + * Copyright 2010-2012 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 org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.wan.GatewayReceiverFactoryBean; +import org.springframework.util.StringUtils; +import org.w3c.dom.Element; + +/** + * @author David Turanski + * + */ +class GatewayReceiverParser extends AbstractSimpleBeanDefinitionParser { + @Override + protected Class getBeanClass(Element element) { + return GatewayReceiverFactoryBean.class; + } + + @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 : "gemfire-cache")); + ParsingUtils.setPropertyValue(element, builder, "start-port"); + ParsingUtils.setPropertyValue(element, builder, "end-port"); + ParsingUtils.setPropertyValue(element, builder, "socket-buffer-size"); + ParsingUtils.setPropertyValue(element, builder, "maximum-time-between-pings"); + ParsingUtils.setPropertyValue(element, builder, "bind-address"); + ParsingUtils.parseTransportFilters(element, parserContext, builder); + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java b/src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java new file mode 100644 index 00000000..b4065a89 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GatewaySenderParser.java @@ -0,0 +1,67 @@ +/* + * Copyright 2010-2012 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 org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.xml.AbstractSimpleBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Element; + +/** + * @author David Turanski + * + */ +class GatewaySenderParser extends AbstractSimpleBeanDefinitionParser { + + @Override + protected Class getBeanClass(Element element) { + return GatewaySenderFactoryBean.class; + } + + @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 : "gemfire-cache")); + ParsingUtils.setPropertyValue(element, builder, "alert-threshold"); + ParsingUtils.setPropertyValue(element, builder, "batch-size"); + ParsingUtils.setPropertyValue(element, builder, "batch-time-interval"); + ParsingUtils.setPropertyValue(element, builder, "disk-store-ref"); + ParsingUtils.setPropertyValue(element, builder, "disk-synchronous"); + ParsingUtils.setPropertyValue(element, builder, "dispatcher-threads"); + ParsingUtils.setPropertyValue(element, builder, "enable-batch-conflation"); + ParsingUtils.setPropertyValue(element, builder, "manual-start"); + ParsingUtils.setPropertyValue(element, builder, "maximum-queue-memory"); + ParsingUtils.setPropertyValue(element, builder, "order-policy"); + 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"); + + Element eventFilterElement = DomUtils.getChildElementByTagName(element, "event-filter"); + if (eventFilterElement != null) { + builder.addPropertyValue("eventFilters", + ParsingUtils.parseRefOrNestedBeanDeclaration(parserContext, eventFilterElement, builder)); + } + + ParsingUtils.parseTransportFilters(element, parserContext, builder); + } +} diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java new file mode 100644 index 00000000..e857c8d1 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java @@ -0,0 +1,34 @@ +/* + * Copyright 2010-2012 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 org.springframework.beans.factory.xml.NamespaceHandlerSupport; +import org.springframework.data.gemfire.repository.config.GemfireRepositoryParser; + +/** + * Namespace handler for GemFire definitions. + * + * @author Costin Leau + * @author David Turanski + */ +class GemfireDataNamespaceHandler extends NamespaceHandlerSupport { + + @Override + public void init() { + registerBeanDefinitionParser("repositories", new GemfireRepositoryParser()); + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java index 80ffcdfa..64c8c78c 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java @@ -16,8 +16,13 @@ package org.springframework.data.gemfire.config; +import java.util.Arrays; +import java.util.List; + +import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.beans.factory.xml.NamespaceHandlerSupport; -import org.springframework.data.gemfire.repository.config.GemfireRepositoryParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.w3c.dom.Element; /** * Namespace handler for GemFire definitions. @@ -26,12 +31,25 @@ import org.springframework.data.gemfire.repository.config.GemfireRepositoryParse * @author David Turanski */ class GemfireNamespaceHandler extends NamespaceHandlerSupport { + static final List GEMFIRE7_ELEMENTS = Arrays.asList("async-event-queue", "gateway-sender", + "gateway-receiver"); + + @Override + public BeanDefinition parse(Element element, ParserContext parserContext) { + + boolean v7ElementsPresent = GEMFIRE7_ELEMENTS.contains(element.getLocalName()); + + if (v7ElementsPresent) { + ParsingUtils.throwExceptionIfNotGemfireV7(element.getLocalName(), null, parserContext); + } + + return super.parse(element, parserContext); + } @Override public void init() { registerBeanDefinitionParser("cache", new CacheParser()); registerBeanDefinitionParser("client-cache", new ClientCacheParser()); - registerBeanDefinitionParser("lookup-region", new LookupRegionParser()); registerBeanDefinitionParser("replicated-region", new ReplicatedRegionParser()); registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser()); @@ -43,6 +61,10 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("cache-server", new CacheServerParser()); registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser()); registerBeanDefinitionParser("cq-listener-container", new GemfireListenerContainerParser()); - registerBeanDefinitionParser("repositories", new GemfireRepositoryParser()); + registerBeanDefinitionParser("async-event-queue", new AsyncEventQueueParser()); + registerBeanDefinitionParser("gateway-sender", new GatewaySenderParser()); + registerBeanDefinitionParser("gateway-receiver", new GatewayReceiverParser()); + // V6 WAN parsers + registerBeanDefinitionParser("gateway-hub", new GatewayHubParser()); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java index f47c1d60..72e24f41 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -33,6 +33,7 @@ import org.springframework.util.StringUtils; import org.springframework.util.xml.DomUtils; import org.w3c.dom.Element; +import com.gemstone.gemfire.cache.CacheFactory; import com.gemstone.gemfire.cache.ExpirationAction; import com.gemstone.gemfire.cache.ExpirationAttributes; import com.gemstone.gemfire.cache.LossAction; @@ -48,6 +49,8 @@ import com.gemstone.gemfire.cache.Scope; */ abstract class ParsingUtils { + final static String GEMFIRE_VERSION = CacheFactory.getVersion(); + private static final String ALIASES_KEY = ParsingUtils.class.getName() + ":aliases"; static void setPropertyValue(Element element, BeanDefinitionBuilder builder, String attributeName, @@ -119,11 +122,14 @@ abstract class ParsingUtils { */ static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, BeanDefinitionBuilder builder) { - return parseRefOrNestedBeanDeclaration(parserContext, element, builder, "ref"); + return parseRefOrNestedBeanDeclaration(parserContext, element, builder, "ref", false); } - static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, - BeanDefinitionBuilder builder, String refAttrName) { + static Object getBeanReference(ParserContext parserContext, Element element) { + return getBeanReference(parserContext, element, "ref"); + } + + static Object getBeanReference(ParserContext parserContext, Element element, String refAttrName) { String attr = element.getAttribute(refAttrName); boolean hasRef = StringUtils.hasText(attr); @@ -138,18 +144,54 @@ abstract class ParsingUtils { } return new RuntimeBeanReference(attr); } - - if (childElements.isEmpty()) { - parserContext.getReaderContext().error( - "specify either '" + refAttrName + "' attribute or a nested bean declaration for '" - + element.getLocalName() + "' element", element); + else { + return null; } + } + + static Object parseRefOrNestedCustomElement(ParserContext parserContext, Element element, + BeanDefinitionBuilder builder) { + Object beanRef = ParsingUtils.getBeanReference(parserContext, element, "bean"); + if (beanRef != null) { + return beanRef; + } + else { + return parserContext.getDelegate().parseCustomElement(element, builder.getBeanDefinition()); + } + } + + static Object parseRefOrSingleNestedBeanDeclaration(ParserContext parserContext, Element element, + BeanDefinitionBuilder builder) { + return parseRefOrNestedBeanDeclaration(parserContext, element, builder, "ref", true); + } + + static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, + BeanDefinitionBuilder builder, String refAttrName) { + return parseRefOrNestedBeanDeclaration(parserContext, element, builder, refAttrName, false); + } + + static Object parseRefOrNestedBeanDeclaration(ParserContext parserContext, Element element, + BeanDefinitionBuilder builder, String refAttrName, boolean single) { + Object beanRef = getBeanReference(parserContext, element, refAttrName); + if (beanRef != null) { + return beanRef; + } + + // check nested declarations + List childElements = DomUtils.getChildElements(element); // nested parse nested bean definition if (childElements.size() == 1) { return parserContext.getDelegate().parsePropertySubElement(childElements.get(0), builder.getRawBeanDefinition()); } + else { + if (single) { + parserContext.getReaderContext().error( + "the element '" + element.getLocalName() + + "' does not support multiple nested bean definitions", element); + } + } ManagedList list = new ManagedList(); @@ -199,6 +241,14 @@ abstract class ParsingUtils { return true; } + static void parseTransportFilters(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) { + Element transportFilterElement = DomUtils.getChildElementByTagName(element, "transport-filter"); + if (transportFilterElement != null) { + builder.addPropertyValue("transportFilters", + parseRefOrNestedBeanDeclaration(parserContext, transportFilterElement, builder)); + } + } + static void parseStatistics(Element element, BeanDefinitionBuilder attrBuilder) { setPropertyValue(element, attrBuilder, "statistics", "statisticsEnabled"); } @@ -276,6 +326,17 @@ abstract class ParsingUtils { } } + static void throwExceptionIfNotGemfireV7(String elementName, String attributeName, ParserContext parserContext) { + boolean checkGemfireV7 = !GEMFIRE_VERSION.startsWith("7"); + if (checkGemfireV7) { + String messagePrefix = (attributeName == null) ? "element '" + elementName + "'" : "attribute '" + + attributeName + " of element '" + elementName + "'"; + parserContext.getReaderContext().error( + messagePrefix + " requires Gemfire version 7 or later. The current version is " + GEMFIRE_VERSION, + null); + } + } + static void parseScope(Element element, BeanDefinitionBuilder builder) { String scope = element.getAttribute("scope"); if (StringUtils.hasText(scope)) { diff --git a/src/main/java/org/springframework/data/gemfire/mapping/GemfirePersistentProperty.java b/src/main/java/org/springframework/data/gemfire/mapping/GemfirePersistentProperty.java index ea04d880..bbd891ac 100644 --- a/src/main/java/org/springframework/data/gemfire/mapping/GemfirePersistentProperty.java +++ b/src/main/java/org/springframework/data/gemfire/mapping/GemfirePersistentProperty.java @@ -42,11 +42,24 @@ public class GemfirePersistentProperty extends AnnotationBasedPersistentProperty super(field, propertyDescriptor, owner, simpleTypeHolder); } - /* (non-Javadoc) - * @see org.springframework.data.mapping.model.AbstractPersistentProperty#createAssociation() + /* + * (non-Javadoc) + * + * @see org.springframework.data.mapping.model.AbstractPersistentProperty# + * createAssociation() */ @Override protected Association createAssociation() { - return null; + return new Association(this, null); } + + @Override + public boolean isAssociation() { + return field.isAnnotationPresent(RegionRef.class) || super.isAssociation(); + } + + public RegionRef geRegionRef() { + return getField().getAnnotation(RegionRef.class); + } + } diff --git a/src/main/java/org/springframework/data/gemfire/mapping/MappingPdxSerializer.java b/src/main/java/org/springframework/data/gemfire/mapping/MappingPdxSerializer.java index 5d65d809..868b84fb 100644 --- a/src/main/java/org/springframework/data/gemfire/mapping/MappingPdxSerializer.java +++ b/src/main/java/org/springframework/data/gemfire/mapping/MappingPdxSerializer.java @@ -21,6 +21,7 @@ import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; import org.springframework.core.convert.ConversionService; +import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.data.convert.EntityInstantiator; import org.springframework.data.convert.EntityInstantiators; import org.springframework.data.mapping.PersistentEntity; @@ -37,21 +38,24 @@ import com.gemstone.gemfire.pdx.PdxSerializer; import com.gemstone.gemfire.pdx.PdxWriter; /** - * {@link PdxSerializer} implementation that uses a {@link GemfireMappingContext} to read and write entities. + * {@link PdxSerializer} implementation that uses a + * {@link GemfireMappingContext} to read and write entities. * * @author Oliver Gierke */ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAware { private final GemfireMappingContext mappingContext; + private final ConversionService conversionService; private EntityInstantiators instantiators; + private SpELContext context; /** - * Creates a new {@link MappingPdxSerializer} using the given {@link GemfireMappingContext} and - * {@link ConversionService}. + * Creates a new {@link MappingPdxSerializer} using the given + * {@link GemfireMappingContext} and {@link ConversionService}. * * @param mappingContext must not be {@literal null}. * @param conversionService must not be {@literal null}. @@ -68,7 +72,16 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw } /** - * Configures the {@link EntityInstantiator}s to be used to create the instances to be read. + * Creates a new {@link MappingPdxSerializer} using the default + * {@link GemfireMappingContext} and {@link DefaultConversionService}. + */ + public MappingPdxSerializer() { + this(new GemfireMappingContext(), new DefaultConversionService()); + } + + /** + * Configures the {@link EntityInstantiator}s to be used to create the + * instances to be read. * * @param gemfireInstantiators must not be {@literal null}. */ @@ -77,9 +90,12 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw this.instantiators = new EntityInstantiators(gemfireInstantiators); } - /* + /* * (non-Javadoc) - * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + * + * @see + * org.springframework.context.ApplicationContextAware#setApplicationContext + * (org.springframework.context.ApplicationContext) */ @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { @@ -88,8 +104,11 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw /* * (non-Javadoc) - * @see com.gemstone.gemfire.pdx.PdxSerializer#fromData(java.lang.Class, com.gemstone.gemfire.pdx.PdxReader) + * + * @see com.gemstone.gemfire.pdx.PdxSerializer#fromData(java.lang.Class, + * com.gemstone.gemfire.pdx.PdxReader) */ + @Override public Object fromData(Class type, final PdxReader reader) { final GemfirePersistentEntity entity = mappingContext.getPersistentEntity(type); @@ -102,9 +121,11 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw Object instance = instantiator.createInstance(entity, provider); - final BeanWrapper, Object> wrapper = BeanWrapper.create(instance, conversionService); + final BeanWrapper, Object> wrapper = BeanWrapper + .create(instance, conversionService); entity.doWithProperties(new PropertyHandler() { + @Override public void doWithPersistentProperty(GemfirePersistentProperty persistentProperty) { if (entity.isConstructorArgument(persistentProperty)) { @@ -115,7 +136,8 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw try { wrapper.setProperty(persistentProperty, value); - } catch (Exception e) { + } + catch (Exception e) { throw new MappingException("Could not read value " + value.toString(), e); } } @@ -126,20 +148,25 @@ public class MappingPdxSerializer implements PdxSerializer, ApplicationContextAw /* * (non-Javadoc) - * @see com.gemstone.gemfire.pdx.PdxSerializer#toData(java.lang.Object, com.gemstone.gemfire.pdx.PdxWriter) + * + * @see com.gemstone.gemfire.pdx.PdxSerializer#toData(java.lang.Object, + * com.gemstone.gemfire.pdx.PdxWriter) */ + @Override public boolean toData(Object value, final PdxWriter writer) { GemfirePersistentEntity entity = mappingContext.getPersistentEntity(value.getClass()); final BeanWrapper, Object> wrapper = BeanWrapper.create(value, conversionService); entity.doWithProperties(new PropertyHandler() { + @Override public void doWithPersistentProperty(GemfirePersistentProperty persistentProperty) { try { Object value = wrapper.getProperty(persistentProperty); writer.writeObject(persistentProperty.getName(), value); - } catch (Exception e) { + } + catch (Exception e) { throw new MappingException("Could not write value for property " + persistentProperty.toString(), e); } } diff --git a/src/main/java/org/springframework/data/gemfire/mapping/RegionRef.java b/src/main/java/org/springframework/data/gemfire/mapping/RegionRef.java new file mode 100644 index 00000000..a2c9d752 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/mapping/RegionRef.java @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2012 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.mapping; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.springframework.data.annotation.Reference; + +/** + * @author David Turanski + * + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Documented +@Reference +public @interface RegionRef { + String value() default ""; +} diff --git a/src/main/java/org/springframework/data/gemfire/mapping/Regions.java b/src/main/java/org/springframework/data/gemfire/mapping/Regions.java index ad33c903..46ed7cce 100644 --- a/src/main/java/org/springframework/data/gemfire/mapping/Regions.java +++ b/src/main/java/org/springframework/data/gemfire/mapping/Regions.java @@ -15,6 +15,7 @@ */ package org.springframework.data.gemfire.mapping; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -22,7 +23,6 @@ import java.util.Map; import org.springframework.data.mapping.context.MappingContext; import org.springframework.util.Assert; -import com.gemstone.bp.edu.emory.mathcs.backport.java.util.Collections; import com.gemstone.gemfire.cache.Region; /** @@ -33,10 +33,12 @@ import com.gemstone.gemfire.cache.Region; public class Regions implements Iterable> { private final Map> regions; + private final MappingContext, ?> context; /** - * Creates a new {@link Regions} wrapper for the given {@link Region}s and {@link MappingContext}. + * Creates a new {@link Regions} wrapper for the given {@link Region}s and + * {@link MappingContext}. * * @param regions must not be {@literal null}. * @param context must not be {@literal null}. @@ -58,8 +60,9 @@ public class Regions implements Iterable> { } /** - * Returns the {@link Region} the given type is mapped to. Will try to find a {@link Region} with the simple class - * name in case no mapping information is found. + * Returns the {@link Region} the given type is mapped to. Will try to find + * a {@link Region} with the simple class name in case no mapping + * information is found. * * @param type must not be {@literal null}. * @return the {@link Region} the given type is mapped to. @@ -89,6 +92,7 @@ public class Regions implements Iterable> { /* * (non-Javadoc) + * * @see java.lang.Iterable#iterator() */ @Override diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java index 7c09dc8c..80577347 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactory.java @@ -40,13 +40,15 @@ import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Region; /** - * {@link RepositoryFactorySupport} implementation creating repository proxies for Gemfire. + * {@link RepositoryFactorySupport} implementation creating repository proxies + * for Gemfire. * * @author Oliver Gierke */ public class GemfireRepositoryFactory extends RepositoryFactorySupport { private final MappingContext, GemfirePersistentProperty> context; + private final Regions regions; /** @@ -66,7 +68,10 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { /* * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getEntityInformation(java.lang.Class) + * + * @see + * org.springframework.data.repository.core.support.RepositoryFactorySupport + * #getEntityInformation(java.lang.Class) */ @Override @SuppressWarnings("unchecked") @@ -78,7 +83,11 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { /* * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getTargetRepository(org.springframework.data.repository.core.RepositoryMetadata) + * + * @see + * org.springframework.data.repository.core.support.RepositoryFactorySupport + * #getTargetRepository(org.springframework.data.repository.core. + * RepositoryMetadata) */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) @@ -98,17 +107,21 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { Region region = regions.getRegion(domainClass); if (region == null) { - throw new IllegalStateException(String.format("No region '%s' found for domain class %s! Make sure you have " - + "configured a Gemfire region of that name in your application context!", entity.getRegionName(), domainClass)); + throw new IllegalStateException(String.format( + "No region '%s' found for domain class %s! Make sure you have " + + "configured a Gemfire region of that name in your application context!", + entity.getRegionName(), domainClass)); } Class regionKeyType = region.getAttributes().getKeyConstraint(); Class entityIdType = metadata.getIdType(); if (regionKeyType != null && entity.getIdProperty() != null) { - Assert.isTrue(regionKeyType.isAssignableFrom(entityIdType), String.format( - "The region referenced only supports keys of type %s but the entity to be stored has an id of type %s!", - regionKeyType, entityIdType)); + Assert.isTrue( + regionKeyType.isAssignableFrom(entityIdType), + String.format( + "The region referenced only supports keys of type %s but the entity to be stored has an id of type %s!", + regionKeyType, entityIdType)); } return new GemfireTemplate(region); @@ -116,7 +129,11 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { /* * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getRepositoryBaseClass(org.springframework.data.repository.core.RepositoryMetadata) + * + * @see + * org.springframework.data.repository.core.support.RepositoryFactorySupport + * #getRepositoryBaseClass(org.springframework.data.repository.core. + * RepositoryMetadata) */ @Override protected Class getRepositoryBaseClass(RepositoryMetadata metadata) { @@ -125,7 +142,11 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { /* * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryFactorySupport#getQueryLookupStrategy(org.springframework.data.repository.query.QueryLookupStrategy.Key) + * + * @see + * org.springframework.data.repository.core.support.RepositoryFactorySupport + * #getQueryLookupStrategy(org.springframework.data.repository.query. + * QueryLookupStrategy.Key) */ @Override protected QueryLookupStrategy getQueryLookupStrategy(Key key) { @@ -142,7 +163,8 @@ public class GemfireRepositoryFactory extends RepositoryFactorySupport { String namedQueryName = queryMethod.getNamedQueryName(); if (namedQueries.hasQuery(namedQueryName)) { - return new StringBasedGemfireRepositoryQuery(namedQueries.getQuery(namedQueryName), queryMethod, template); + return new StringBasedGemfireRepositoryQuery(namedQueries.getQuery(namedQueryName), queryMethod, + template); } return new PartTreeGemfireRepositoryQuery(queryMethod, template); diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBean.java b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBean.java index 1152b123..367f93e0 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryBean.java @@ -17,6 +17,7 @@ package org.springframework.data.gemfire.repository.support; import java.io.Serializable; import java.util.Collection; +import java.util.Collections; import org.springframework.beans.BeansException; import org.springframework.beans.factory.FactoryBean; @@ -29,7 +30,6 @@ import org.springframework.data.repository.Repository; import org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport; import org.springframework.data.repository.core.support.RepositoryFactorySupport; -import com.gemstone.bp.edu.emory.mathcs.backport.java.util.Collections; import com.gemstone.gemfire.cache.Region; /** @@ -38,20 +38,24 @@ import com.gemstone.gemfire.cache.Region; * @author Oliver Gierke */ public class GemfireRepositoryFactoryBean, S, ID extends Serializable> extends -RepositoryFactoryBeanSupport implements ApplicationContextAware { + RepositoryFactoryBeanSupport implements ApplicationContextAware { private MappingContext, GemfirePersistentProperty> context; + private Iterable> regions; /* * (non-Javadoc) - * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext) + * + * @see + * org.springframework.context.ApplicationContextAware#setApplicationContext + * (org.springframework.context.ApplicationContext) */ @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { Collection regions = applicationContext.getBeansOfType(Region.class).values(); - this.regions = Collections.unmodifiableCollection(regions); + this.regions = (Iterable) Collections.unmodifiableCollection(regions); } /** @@ -59,13 +63,17 @@ RepositoryFactoryBeanSupport implements ApplicationContextAware { * * @param context the context to set */ - public void setMappingContext(MappingContext, GemfirePersistentProperty> context) { + public void setMappingContext( + MappingContext, GemfirePersistentProperty> context) { this.context = context; } /* * (non-Javadoc) - * @see org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport#createRepositoryFactory() + * + * @see + * org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport + * #createRepositoryFactory() */ @Override protected RepositoryFactorySupport createRepositoryFactory() { diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java index 30a3ed41..d958d7b2 100644 --- a/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java +++ b/src/main/java/org/springframework/data/gemfire/repository/support/SimpleGemfireRepository.java @@ -24,6 +24,7 @@ import com.gemstone.gemfire.cache.Region; public class SimpleGemfireRepository implements GemfireRepository { private final GemfireTemplate template; + private final EntityInformation entityInformation; /** @@ -43,8 +44,10 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) + * * @see org.springframework.data.repository.CrudRepository#save(S) */ + @Override public U save(U entity) { template.put(entityInformation.getId(entity), entity); return entity; @@ -52,8 +55,12 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#save(java.lang.Iterable) + * + * @see + * org.springframework.data.repository.CrudRepository#save(java.lang.Iterable + * ) */ + @Override public Iterable save(Iterable entities) { List result = new ArrayList(); for (U entity : entities) { @@ -64,8 +71,11 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#findOne(java.io.Serializable) + * + * @see org.springframework.data.repository.CrudRepository#findOne(java.io. + * Serializable) */ + @Override @SuppressWarnings("unchecked") public T findOne(ID id) { Object object = template.get(id); @@ -74,18 +84,24 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#exists(java.io.Serializable) + * + * @see org.springframework.data.repository.CrudRepository#exists(java.io. + * Serializable) */ + @Override public boolean exists(ID id) { return findOne(id) != null; } /* * (non-Javadoc) + * * @see org.springframework.data.repository.CrudRepository#findAll() */ + @Override public Collection findAll() { return template.execute(new GemfireCallback>() { + @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Collection doInGemfire(Region region) { return region.values(); @@ -93,9 +109,12 @@ public class SimpleGemfireRepository implements Gemf }); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#findAll(java.lang.Iterable) + * + * @see + * org.springframework.data.repository.CrudRepository#findAll(java.lang. + * Iterable) */ @Override @SuppressWarnings("unchecked") @@ -111,11 +130,15 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) + * * @see org.springframework.data.repository.CrudRepository#count() */ + @Override public long count() { return template.execute(new GemfireCallback() { + @Override @SuppressWarnings("rawtypes") + // TODO: Take into account keySetOnServer() public Long doInGemfire(Region region) throws GemFireCheckedException, GemFireException { return Long.valueOf(region.keySet().size()); } @@ -124,16 +147,24 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Object) + * + * @see + * org.springframework.data.repository.CrudRepository#delete(java.lang.Object + * ) */ + @Override public void delete(T entity) { template.remove(entityInformation.getId(entity)); } /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable) + * + * @see + * org.springframework.data.repository.CrudRepository#delete(java.lang.Iterable + * ) */ + @Override public void delete(Iterable entities) { for (T entity : entities) { delete(entity); @@ -142,11 +173,14 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) + * * @see org.springframework.data.repository.CrudRepository#deleteAll() */ + @Override public void deleteAll() { template.execute(new GemfireCallback() { + @Override @SuppressWarnings("rawtypes") public Void doInGemfire(Region region) { region.clear(); @@ -157,15 +191,21 @@ public class SimpleGemfireRepository implements Gemf /* * (non-Javadoc) - * @see org.springframework.data.repository.CrudRepository#delete(java.io.Serializable) + * + * @see org.springframework.data.repository.CrudRepository#delete(java.io. + * Serializable) */ + @Override public void delete(ID id) { template.remove(id); } - /* + /* * (non-Javadoc) - * @see org.springframework.data.gemfire.repository.GemfireRepository#save(org.springframework.data.gemfire.repository.Wrapper) + * + * @see + * org.springframework.data.gemfire.repository.GemfireRepository#save(org + * .springframework.data.gemfire.repository.Wrapper) */ @Override public T save(Wrapper wrapper) { diff --git a/src/main/java/org/springframework/data/gemfire/wan/AbstractWANComponentFactoryBean.java b/src/main/java/org/springframework/data/gemfire/wan/AbstractWANComponentFactoryBean.java new file mode 100644 index 00000000..1b601a42 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/AbstractWANComponentFactoryBean.java @@ -0,0 +1,74 @@ +/* + * Copyright 2010-2012 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.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.factory.BeanNameAware; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.util.Assert; + +import com.gemstone.gemfire.cache.Cache; + +/** + * Base class for Gemfire WAN Gateway component factory beans + * @author David Turanski + * + */ +public abstract class AbstractWANComponentFactoryBean implements FactoryBean, InitializingBean, BeanNameAware, + DisposableBean { + protected Log log = LogFactory.getLog(this.getClass()); + + protected String name; + + protected final Cache cache; + + protected AbstractWANComponentFactoryBean(Cache cache) { + this.cache = cache; + } + + @Override + public void destroy() throws Exception { + // TODO Auto-generated method stub + } + + @Override + public final void setBeanName(String name) { + this.name = name; + } + + @Override + public final void afterPropertiesSet() throws Exception { + Assert.notNull(name, "Name cannot be null"); + Assert.notNull(cache, "Cache cannot be null"); + doInit(); + } + + protected abstract void doInit(); + + @Override + public abstract T getObject() throws Exception; + + @Override + public abstract Class getObjectType(); + + @Override + public final boolean isSingleton() { + return true; + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/wan/AsyncEventQueueFactoryBean.java b/src/main/java/org/springframework/data/gemfire/wan/AsyncEventQueueFactoryBean.java new file mode 100644 index 00000000..0cecf9a6 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/AsyncEventQueueFactoryBean.java @@ -0,0 +1,126 @@ +/* + * Copyright 2010-2012 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.util.Assert; + +import com.gemstone.gemfire.cache.AsyncEventQueue; +import com.gemstone.gemfire.cache.AsyncEventQueueFactory; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheClosedException; +import com.gemstone.gemfire.cache.wan.AsyncEventListener; + +/** + * FactoryBean for creating GemFire {@link AsyncEventQueue}s. + * @author David Turanski + * + */ +public class AsyncEventQueueFactoryBean extends AbstractWANComponentFactoryBean { + + public void setDiskStoreRef(String diskStoreRef) { + this.diskStoreRef = diskStoreRef; + } + + private final AsyncEventListener asyncEventListener; + + private AsyncEventQueue asyncEventQueue; + + private Integer batchSize; + + private Integer maximumQueueMemory; + + private Boolean persistent; + + private Boolean parallel; + + private String diskStoreRef; + + /** + * + * @param cache the gemfire cache + * @param asyncEventListener required {@link AsyncEventListener} + */ + public AsyncEventQueueFactoryBean(Cache cache, AsyncEventListener asyncEventListener) { + super(cache); + this.asyncEventListener = asyncEventListener; + } + + @Override + public AsyncEventQueue getObject() throws Exception { + return asyncEventQueue; + } + + @Override + public Class getObjectType() { + return AsyncEventQueue.class; + } + + @Override + protected void doInit() { + Assert.notNull(asyncEventListener, "AsyncEventListener cannot be null"); + + AsyncEventQueueFactory asyncEventQueueFactory = cache.createAsyncEventQueueFactory(); + if (parallel != null) { + asyncEventQueueFactory.setParallel(parallel); + } + if (persistent != null) { + asyncEventQueueFactory.setPersistent(persistent); + } + if (batchSize != null) { + asyncEventQueueFactory.setBatchSize(batchSize); + } + if (diskStoreRef != null) { + persistent = (persistent == null) ? Boolean.TRUE : persistent; + Assert.isTrue(persistent, "specifying a disk store requires persistent property to be true"); + asyncEventQueueFactory.setDiskStoreName(diskStoreRef); + } + + if (maximumQueueMemory != null) { + asyncEventQueueFactory.setMaximumQueueMemory(maximumQueueMemory); + } + + asyncEventQueue = asyncEventQueueFactory.create(name, asyncEventListener); + } + + @Override + public void destroy() throws Exception { + if (!cache.isClosed()) { + try { + asyncEventQueue.stop(); + asyncEventListener.close(); + } + catch (CacheClosedException cce) { + // nothing to see folks, move on. + } + } + } + + public void setBatchSize(Integer batchSize) { + this.batchSize = batchSize; + } + + public void setMaximumQueueMemory(Integer maximumQueueMemory) { + this.maximumQueueMemory = maximumQueueMemory; + } + + public void setPersistent(Boolean persistent) { + this.persistent = persistent; + } + + public void setParallel(Boolean parallel) { + this.parallel = parallel; + } +} diff --git a/src/main/java/org/springframework/data/gemfire/wan/GatewayHubFactoryBean.java b/src/main/java/org/springframework/data/gemfire/wan/GatewayHubFactoryBean.java new file mode 100644 index 00000000..9896c4a8 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/GatewayHubFactoryBean.java @@ -0,0 +1,190 @@ +/* + * Copyright 2010-2012 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 java.util.Arrays; +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; + +/** + * FactoryBean for creating a GemFire {@link GatewayHub} (deprecated in Gemfire + * 7) + * @author David Turanski + * + */ +public class GatewayHubFactoryBean extends AbstractWANComponentFactoryBean { + private static List validStartupPolicyValues = Arrays.asList("none", "primary", "secondary"); + + private static List 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 List gateways; + + /** + * @param cache the Gemfire cache + */ + public GatewayHubFactoryBean(Cache cache) { + super(cache); + } + + @Override + public GatewayHub getObject() throws Exception { + return gatewayHub; + } + + @Override + public Class getObjectType() { + return GatewayHub.class; + } + + @Override + protected void doInit() { + gatewayHub = cache.addGatewayHub(name, port == null ? GatewayHub.DEFAULT_PORT : port); + + if (log.isDebugEnabled()) { + log.debug("added gateway hub " + name); + } + + Assert.notNull(cache.getGatewayHub(name)); + + 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); + } + 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.getSocketReadTimeout() != null) { + gw.setSocketReadTimeout(gateway.getSocketReadTimeout()); + } + + 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 setPort(Integer port) { + this.port = port; + } + + public void setBindAddress(String bindAddress) { + this.bindAddress = bindAddress; + } + + public void setMaximumTimeBetweenPings(Integer maximumTimeBetweenPings) { + this.maximumTimeBetweenPings = maximumTimeBetweenPings; + } + + public void setSocketBufferSize(Integer socketBufferSize) { + this.socketBufferSize = socketBufferSize; + } + + public void setStartupPolicy(String startupPolicy) { + this.startupPolicy = startupPolicy; + } + + public void setManualStart(Boolean manualStart) { + this.manualStart = manualStart; + } + + public void setGateways(List gateways) { + this.gateways = gateways; + } +} diff --git a/src/main/java/org/springframework/data/gemfire/wan/GatewayProxy.java b/src/main/java/org/springframework/data/gemfire/wan/GatewayProxy.java new file mode 100644 index 00000000..7f210435 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/GatewayProxy.java @@ -0,0 +1,212 @@ +/* + * Copyright 2010-2012 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 java.util.List; + +import com.gemstone.gemfire.cache.util.GatewayEventListener; + +/** + * This class used to allow decoupling of 'gateway' parsing from 'gateway-hub' + * parsing + * + * @author David Turanski + * + */ +public class GatewayProxy { + + private List endpoints; + + private Integer concurrencyLevel; + + private String id; + + private List listeners; + + private String orderPolicy; + + private int socketBufferSize; + + private int socketReadTimeout; + + private GatewayQueue queue; + + public void setEndpoints(List endpoints) { + this.endpoints = endpoints; + } + + public void setListeners(List listeners) { + this.listeners = listeners; + } + + public void setQueue(GatewayQueue queue) { + this.queue = queue; + } + + public GatewayQueue getQueue() { + return this.queue; + } + + public Integer getConcurrencyLevel() { + return this.concurrencyLevel; + } + + public List getEndpoints() { + return endpoints; + } + + public String getId() { + return this.id; + } + + public List getListeners() { + return this.listeners; + } + + public String getOrderPolicy() { + return this.orderPolicy; + } + + public Integer getSocketBufferSize() { + return this.socketBufferSize; + } + + public Integer getSocketReadTimeout() { + return this.socketReadTimeout; + } + + public void setId(String id) { + this.id = id; + } + + public void setOrderPolicy(String orderPolicy) { + this.orderPolicy = orderPolicy; + } + + public void setSocketBufferSize(int socketBufferSize) { + this.socketBufferSize = socketBufferSize; + + } + + public void setSocketReadTimeout(int socketReadTimeout) { + this.socketReadTimeout = socketReadTimeout; + } + + public static class GatewayEndpoint { + private String host; + + private String id; + + private int port; + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + } + + public static class GatewayQueue { + private Integer alertThreshold; + + private Boolean enableBatchConflation; + + private Integer batchTimeInterval; + + private Integer batchSize; + + private Boolean persistent; + + private String diskStoreRef; + + private Integer maximumQueueMemory; + + public Integer getAlertThreshold() { + return alertThreshold; + } + + 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 void setBatchSize(Integer batchSize) { + this.batchSize = batchSize; + } + + public Boolean getPersistent() { + return persistent; + } + + public void setPersistent(Boolean persistent) { + this.persistent = persistent; + } + + public String getDiskStoreRef() { + return diskStoreRef; + } + + public void setDiskStoreRef(String diskStoreRef) { + this.diskStoreRef = diskStoreRef; + } + + public Integer getMaximumQueueMemory() { + return maximumQueueMemory; + } + + public void setMaximumQueueMemory(Integer maximumQueueMemory) { + this.maximumQueueMemory = maximumQueueMemory; + } + + } +} diff --git a/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java b/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java new file mode 100644 index 00000000..81137be1 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/GatewayReceiverFactoryBean.java @@ -0,0 +1,123 @@ +/* + * Copyright 2010-2012 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 java.util.List; + +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; +import com.gemstone.gemfire.cache.wan.GatewayReceiverFactory; +import com.gemstone.gemfire.cache.wan.GatewayTransportFilter; + +/** + * FactoryBean for creating a GemFire {@link GatewayReceiver}. + * + * @author David Turanski + * + */ +public class GatewayReceiverFactoryBean extends AbstractWANComponentFactoryBean { + private GatewayReceiver gatewayReceiver; + + private List transportFilters; + + private Integer startPort; + + private Integer endPort; + + private Integer maximumTimeBetweenPings; + + private Integer socketBufferSize; + + private String bindAddress; + + /** + * + * @param cache + */ + public GatewayReceiverFactoryBean(Cache cache) { + super(cache); + // Bean name not required. + this.name = "gateway-receiver"; + } + + @Override + public GatewayReceiver getObject() throws Exception { + return gatewayReceiver; + } + + @Override + public Class getObjectType() { + return GatewayReceiver.class; + } + + @Override + protected void doInit() { + 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); + } + + gatewayReceiver = gatewayReceiverFactory.create(); + } + + public void setGatewayReceiver(GatewayReceiver gatewayReceiver) { + this.gatewayReceiver = gatewayReceiver; + } + + public void setTransportFilters(List transportFilters) { + this.transportFilters = transportFilters; + } + + public void setStartPort(Integer startPort) { + this.startPort = startPort; + } + + public void setEndPort(Integer endPort) { + this.endPort = endPort; + } + + public void setMaximumTimeBetweenPings(Integer maximumTimeBetweenPings) { + this.maximumTimeBetweenPings = maximumTimeBetweenPings; + } + + public void setSocketBufferSize(Integer socketBufferSize) { + this.socketBufferSize = socketBufferSize; + } + + public void setBindAddress(String bindAddress) { + this.bindAddress = bindAddress; + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBean.java b/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBean.java new file mode 100644 index 00000000..4845afa0 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/wan/GatewaySenderFactoryBean.java @@ -0,0 +1,236 @@ +/* + * Copyright 2010-2012 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 java.util.Arrays; +import java.util.List; + +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.wan.GatewayEventFilter; +import com.gemstone.gemfire.cache.wan.GatewaySender; +import com.gemstone.gemfire.cache.wan.GatewaySenderFactory; +import com.gemstone.gemfire.cache.wan.GatewayTransportFilter; + +/** + * FactoryBean for creating a GemFire {@link GatewaySender}. + * @author David Turanski + * + */ +public class GatewaySenderFactoryBean extends AbstractWANComponentFactoryBean { + private static List validOrderPolicyValues = Arrays.asList("KEY", "PARTITION", "THREAD"); + + private GatewaySender gatewaySender; + + private int remoteDistributedSystemId; + + private List eventFilters; + + private List transportFilters; + + private Integer alertThreshold; + + private Boolean enableBatchConflation; + + private Integer batchSize; + + private Integer batchTimeInterval; + + private String diskStoreRef; + + private Boolean diskSynchronous; + + private Integer dispatcherThreads; + + private Boolean manualStart; + + private Integer maximumQueueMemory; + + private String orderPolicy; + + private Boolean parallel; + + private Boolean persistent; + + private Integer socketBufferSize; + + private Integer socketReadTimeout; + + /** + * + * @param cache the Gemfire cache + */ + public GatewaySenderFactoryBean(Cache cache) { + super(cache); + } + + @Override + public GatewaySender getObject() throws Exception { + return gatewaySender; + } + + @Override + public Class getObjectType() { + return GatewaySender.class; + } + + @Override + protected void doInit() { + GatewaySenderFactory gatewaySenderFactory = cache.createGatewaySenderFactory(); + if (diskStoreRef != null) { + persistent = (persistent == null) ? Boolean.TRUE : persistent; + Assert.isTrue(persistent, "specifying a disk store requires persistent property to be true"); + gatewaySenderFactory.setDiskStoreName(diskStoreRef); + } + + if (diskSynchronous != null) { + persistent = (persistent == null) ? Boolean.TRUE : persistent; + Assert.isTrue(persistent, "specifying a disk synchronous requires persistent property to be true"); + gatewaySenderFactory.setDiskSynchronous(diskSynchronous); + } + + if (persistent != null) { + gatewaySenderFactory.setPersistenceEnabled(persistent); + } + + parallel = (parallel == null) ? Boolean.FALSE : parallel; + + gatewaySenderFactory.setParallel(parallel); + + if (orderPolicy != null) { + Assert.isTrue(parallel, "specifying an order policy requires the parallel property to be true"); + + Assert.isTrue(validOrderPolicyValues.contains(orderPolicy.toUpperCase()), "The value of order policy:'" + + orderPolicy + "' is invalid"); + gatewaySenderFactory.setOrderPolicy(Gateway.OrderPolicy.valueOf(orderPolicy.toUpperCase())); + } + + if (!CollectionUtils.isEmpty(eventFilters)) { + for (GatewayEventFilter eventFilter : eventFilters) { + gatewaySenderFactory.addGatewayEventFilter(eventFilter); + } + } + if (!CollectionUtils.isEmpty(transportFilters)) { + for (GatewayTransportFilter transportFilter : transportFilters) { + gatewaySenderFactory.addGatewayTransportFilter(transportFilter); + } + } + if (alertThreshold != null) { + gatewaySenderFactory.setAlertThreshold(alertThreshold); + } + if (enableBatchConflation != null) { + gatewaySenderFactory.setBatchConflationEnabled(enableBatchConflation); + } + if (batchSize != null) { + gatewaySenderFactory.setBatchSize(batchSize); + } + if (batchTimeInterval != null) { + gatewaySenderFactory.setBatchTimeInterval(batchTimeInterval); + } + if (dispatcherThreads != null) { + gatewaySenderFactory.setDispatcherThreads(dispatcherThreads); + } + if (manualStart != null) { + gatewaySenderFactory.setManualStart(manualStart); + } + if (maximumQueueMemory != null) { + gatewaySenderFactory.setMaximumQueueMemory(maximumQueueMemory); + } + if (socketBufferSize != null) { + gatewaySenderFactory.setSocketBufferSize(socketBufferSize); + } + if (socketReadTimeout != null) { + gatewaySenderFactory.setSocketReadTimeout(socketReadTimeout); + } + gatewaySender = gatewaySenderFactory.create(name, remoteDistributedSystemId); + } + + public void setGatewaySender(GatewaySender gatewaySender) { + this.gatewaySender = gatewaySender; + } + + public void setRemoteDistributedSystemId(int remoteDistributedSystemId) { + this.remoteDistributedSystemId = remoteDistributedSystemId; + } + + public void setEventFilters(List gatewayEventFilters) { + this.eventFilters = gatewayEventFilters; + } + + public void setTransportFilters(List gatewayTransportFilters) { + this.transportFilters = gatewayTransportFilters; + } + + public void setAlertThreshold(Integer alertThreshold) { + this.alertThreshold = alertThreshold; + } + + public void setEnableBatchConflation(Boolean enableBatchConflation) { + this.enableBatchConflation = enableBatchConflation; + } + + public void setBatchSize(Integer batchSize) { + this.batchSize = batchSize; + } + + public void setBatchTimeInterval(Integer batchTimeInterval) { + this.batchTimeInterval = batchTimeInterval; + } + + public void setDiskStoreRef(String diskStoreRef) { + this.diskStoreRef = diskStoreRef; + } + + public void setDiskSynchronous(Boolean diskSynchronous) { + this.diskSynchronous = diskSynchronous; + } + + public void setDispatcherThreads(Integer dispatcherThreads) { + this.dispatcherThreads = dispatcherThreads; + } + + public void setManualStart(Boolean manualStart) { + this.manualStart = manualStart; + } + + public void setMaximumQueueMemory(Integer maximumQueueMemory) { + this.maximumQueueMemory = maximumQueueMemory; + } + + public void setOrderPolicy(String orderPolicy) { + this.orderPolicy = orderPolicy; + } + + public void setParallel(Boolean parallel) { + this.parallel = parallel; + } + + public void setPersistent(Boolean persistent) { + this.persistent = persistent; + } + + public void setSocketBufferSize(Integer socketBufferSize) { + this.socketBufferSize = socketBufferSize; + } + + public void setSocketReadTimeout(Integer socketReadTimeout) { + this.socketReadTimeout = socketReadTimeout; + } + +} diff --git a/src/main/resources/META-INF/spring.handlers b/src/main/resources/META-INF/spring.handlers index 2cd966aa..4f907e5b 100644 --- a/src/main/resources/META-INF/spring.handlers +++ b/src/main/resources/META-INF/spring.handlers @@ -1 +1,2 @@ -http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.GemfireNamespaceHandler \ No newline at end of file +http\://www.springframework.org/schema/gemfire=org.springframework.data.gemfire.config.GemfireNamespaceHandler +http\://www.springframework.org/schema/data/gemfire=org.springframework.data.gemfire.config.GemfireDataNamespaceHandler \ No newline at end of file diff --git a/src/main/resources/META-INF/spring.schemas b/src/main/resources/META-INF/spring.schemas index 5bff7b59..d9bbf67d 100644 --- a/src/main/resources/META-INF/spring.schemas +++ b/src/main/resources/META-INF/spring.schemas @@ -1,4 +1,6 @@ http\://www.springframework.org/schema/gemfire/spring-gemfire-1.0.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd http\://www.springframework.org/schema/gemfire/spring-gemfire-1.1.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd http\://www.springframework.org/schema/gemfire/spring-gemfire-1.2.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd -http\://www.springframework.org/schema/gemfire/spring-gemfire.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd \ No newline at end of file +http\://www.springframework.org/schema/gemfire/spring-gemfire.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd +http\://www.springframework.org/schema/data/gemfire/spring-data-gemfire-1.2.xsd=org/springframework/data/gemfire/config/spring-data-gemfire-1.2.xsd +http\://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd=org/springframework/data/gemfire/config/spring-data-gemfire-1.2.xsd \ No newline at end of file diff --git a/src/main/resources/META-INF/spring.tooling b/src/main/resources/META-INF/spring.tooling index e0b7fdbf..460138cb 100644 --- a/src/main/resources/META-INF/spring.tooling +++ b/src/main/resources/META-INF/spring.tooling @@ -1,4 +1,8 @@ # Tooling related information for the gemfire namespace http\://www.springframework.org/schema/gemfire@name=gemfire Namespace http\://www.springframework.org/schema/gemfire@prefix=gfe -http\://www.springframework.org/schema/gemfire@icon=org/springframework/data/gemfire/config/spring-gemfire.gif \ No newline at end of file +http\://www.springframework.org/schema/gemfire@icon=org/springframework/data/gemfire/config/spring-gemfire.gif +# +http\://www.springframework.org/schema/data/gemfire@name=Spring data gemfire Namespace +http\://www.springframework.org/schema/data/gemfire@prefix=gfe-data +http\://www.springframework.org/schema/data/gemfire@icon=org/springframework/data/gemfire/config/spring-gemfire.gif \ No newline at end of file diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.2.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.2.xsd new file mode 100644 index 00000000..65131ef5 --- /dev/null +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.2.xsd @@ -0,0 +1,65 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + The reference to a GemfireTemplate. + Will default to 'gemfireTemplate'. + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd old mode 100644 new mode 100755 index 543041a9..42d870f4 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.2.xsd @@ -1,140 +1,158 @@ - - - - - - - - + + + + + - - - - - - - + + + + + + - - - - - + + + + - - - - - + + + + - - - + + + - - + - + - - + - + - - + - - - + + + - - - - + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + namespace and its 'properties' element. ]]> - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - + + + + + - - - - - - - + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - + + + - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - + + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - - + + + + + - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - + + + + - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - + + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - + + + + - - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - + + + + - - - - - - - + + + + + + - - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - - + + + + + + + + + + + + - - - - - - - - + + + + + + + - - - - - + + + + - - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The reference to a GemfireTemplate. - Will default to 'gemfireTemplate'. - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - + + - - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - + - - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java index e43169d2..ef07dad9 100644 --- a/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/CacheIntegrationTest.java @@ -59,6 +59,6 @@ public class CacheIntegrationTest extends RecreatingContextTest { @Test public void testCacheWithXml() throws Exception { - Cache cache = ctx.getBean("cache-with-xml", Cache.class); + ctx.getBean("cache-with-xml", Cache.class); } } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java index 762e4a22..ee2a1404 100644 --- a/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java +++ b/src/test/java/org/springframework/data/gemfire/GemfireTemplateTest.java @@ -30,6 +30,7 @@ import com.gemstone.gemfire.cache.query.SelectResults; public class GemfireTemplateTest extends RecreatingContextTest { private static final String MULTI_QUERY = "select * from /simple"; + private static final String SINGLE_QUERY = "(select * from /simple).size"; @Override @@ -38,28 +39,33 @@ public class GemfireTemplateTest extends RecreatingContextTest { } @Test - public void testFind() throws Exception { - GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); - SelectResults find = template.find(MULTI_QUERY); - assertNotNull(find); - } - - @Test - public void testFindUnique() throws Exception { - GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); - Integer find = template.findUnique(SINGLE_QUERY); - assertEquals(find, Integer.valueOf(0)); + public void testAll() throws Exception { + testFind(); + testFindUnique(); } @Test(expected = InvalidDataAccessApiUsageException.class) public void testFindMultiException() throws Exception { GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); - SelectResults find = template.find(SINGLE_QUERY); + template.find(SINGLE_QUERY); } @Test(expected = InvalidDataAccessApiUsageException.class) public void testFindMultiOne() throws Exception { GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); - SelectResults find = template.findUnique(MULTI_QUERY); + template.findUnique(MULTI_QUERY); } + + private void testFind() throws Exception { + GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); + SelectResults find = template.find(MULTI_QUERY); + assertNotNull(find); + } + + private void testFindUnique() throws Exception { + GemfireTemplate template = ctx.getBean("template", GemfireTemplate.class); + Integer find = template.findUnique(SINGLE_QUERY); + assertEquals(find, Integer.valueOf(0)); + } + } \ No newline at end of file diff --git a/src/test/java/org/springframework/data/gemfire/SimpleCacheListener.java b/src/test/java/org/springframework/data/gemfire/SimpleCacheListener.java index c6c923d4..c729a93f 100644 --- a/src/test/java/org/springframework/data/gemfire/SimpleCacheListener.java +++ b/src/test/java/org/springframework/data/gemfire/SimpleCacheListener.java @@ -21,6 +21,7 @@ import com.gemstone.gemfire.cache.util.CacheListenerAdapter; /** * @author Costin Leau */ +@SuppressWarnings("rawtypes") public class SimpleCacheListener extends CacheListenerAdapter { } diff --git a/src/test/java/org/springframework/data/gemfire/SimpleCacheLoader.java b/src/test/java/org/springframework/data/gemfire/SimpleCacheLoader.java index 0e174d0a..3ec73763 100644 --- a/src/test/java/org/springframework/data/gemfire/SimpleCacheLoader.java +++ b/src/test/java/org/springframework/data/gemfire/SimpleCacheLoader.java @@ -23,12 +23,15 @@ import com.gemstone.gemfire.cache.LoaderHelper; /** * @author Costin Leau */ +@SuppressWarnings("rawtypes") public class SimpleCacheLoader implements CacheLoader { + @Override public Object load(LoaderHelper helper) throws CacheLoaderException { return null; } + @Override public void close() { } } diff --git a/src/test/java/org/springframework/data/gemfire/SimpleCacheWriter.java b/src/test/java/org/springframework/data/gemfire/SimpleCacheWriter.java index 89642282..25395019 100644 --- a/src/test/java/org/springframework/data/gemfire/SimpleCacheWriter.java +++ b/src/test/java/org/springframework/data/gemfire/SimpleCacheWriter.java @@ -21,6 +21,7 @@ import com.gemstone.gemfire.cache.util.CacheWriterAdapter; /** * @author Costin Leau */ +@SuppressWarnings("rawtypes") public class SimpleCacheWriter extends CacheWriterAdapter { } diff --git a/src/test/java/org/springframework/data/gemfire/SimpleObjectSizer.java b/src/test/java/org/springframework/data/gemfire/SimpleObjectSizer.java index b1149704..16e85a66 100644 --- a/src/test/java/org/springframework/data/gemfire/SimpleObjectSizer.java +++ b/src/test/java/org/springframework/data/gemfire/SimpleObjectSizer.java @@ -26,6 +26,7 @@ public class SimpleObjectSizer implements ObjectSizer { private static final ObjectSizer sizer = new ObjectSizerImpl(); + @Override public int sizeof(Object o) { return sizer.sizeof(o); } diff --git a/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java b/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java index 284a0dc8..fe02fd42 100644 --- a/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java +++ b/src/test/java/org/springframework/data/gemfire/SimplePartitionResolver.java @@ -24,16 +24,20 @@ import com.gemstone.gemfire.cache.PartitionResolver; /** * @author Costin Leau */ +@SuppressWarnings("rawtypes") public class SimplePartitionResolver implements PartitionResolver { + @Override public String getName() { return getClass().getName(); } + @Override public Serializable getRoutingObject(EntryOperation opDetails) { return getName(); } + @Override public void close() { } } diff --git a/src/test/java/org/springframework/data/gemfire/SubRegionTest.java b/src/test/java/org/springframework/data/gemfire/SubRegionTest.java index c8d4e10c..2d1c0af9 100644 --- a/src/test/java/org/springframework/data/gemfire/SubRegionTest.java +++ b/src/test/java/org/springframework/data/gemfire/SubRegionTest.java @@ -35,9 +35,15 @@ public class SubRegionTest extends RecreatingContextTest { return "org/springframework/data/gemfire/basic-subregion.xml"; } - @SuppressWarnings({ "rawtypes", "unchecked" }) @Test - public void testBasic() throws Exception { + public void testAll() throws Exception { + testBasic(); + testContext(); + testChildOnly(); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + private void testBasic() throws Exception { CacheFactoryBean cfb = new CacheFactoryBean(); cfb.setUseBeanFactoryLocator(false); cfb.afterPropertiesSet(); @@ -57,13 +63,10 @@ public class SubRegionTest extends RecreatingContextTest { assertNotNull(parent.getSubregion("child")); assertSame(child, parent.getSubregion("child")); - - cache.close(); } @SuppressWarnings("rawtypes") - @Test - public void testContext() throws Exception { + private void testContext() throws Exception { Region parent = ctx.getBean("parent", Region.class); Region child = ctx.getBean("/parent/child", Region.class); assertNotNull(parent.getSubregion("child")); @@ -72,7 +75,6 @@ public class SubRegionTest extends RecreatingContextTest { } @SuppressWarnings("rawtypes") - @Test public void testChildOnly() throws Exception { Region child = ctx.getBean("/parent/child", Region.class); assertEquals("/parent/child", child.getFullPath()); diff --git a/src/test/java/org/springframework/data/gemfire/UserObject.java b/src/test/java/org/springframework/data/gemfire/UserObject.java index 8f84a309..d49d27c9 100644 --- a/src/test/java/org/springframework/data/gemfire/UserObject.java +++ b/src/test/java/org/springframework/data/gemfire/UserObject.java @@ -16,8 +16,6 @@ package org.springframework.data.gemfire; -import org.springframework.data.gemfire.WiringDeclarableSupport; - import com.gemstone.gemfire.cache.CacheLoader; import com.gemstone.gemfire.cache.CacheLoaderException; import com.gemstone.gemfire.cache.LoaderHelper; @@ -27,11 +25,13 @@ import com.gemstone.gemfire.cache.LoaderHelper; * * @author Costin Leau */ +@SuppressWarnings("rawtypes") public class UserObject extends WiringDeclarableSupport implements CacheLoader { public static UserObject THIS; private String prop1; + private Object prop2; public UserObject() { @@ -39,6 +39,7 @@ public class UserObject extends WiringDeclarableSupport implements CacheLoader { THIS = this; } + @Override public Object load(LoaderHelper helper) throws CacheLoaderException { return new Object(); } diff --git a/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java b/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java index 97fb1adc..de75bded 100644 --- a/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java +++ b/src/test/java/org/springframework/data/gemfire/client/RegionIntegrationTest.java @@ -40,7 +40,6 @@ import com.gemstone.gemfire.cache.RegionAttributes; import com.gemstone.gemfire.cache.util.CacheListenerAdapter; import com.gemstone.gemfire.cache.util.CacheWriterAdapter; - /** * @author Costin Leau */ @@ -53,10 +52,12 @@ public class RegionIntegrationTest { private static class CacheLoad implements CacheLoader { + @Override public V load(LoaderHelper arg0) throws CacheLoaderException { return null; } + @Override public void close() { } } @@ -68,20 +69,28 @@ public class RegionIntegrationTest { private ApplicationContext ctx; @Test - public void testBasicRegion() throws Exception { + public void testAll() throws Exception { + testBasicRegion(); + testExistingRegion(); + testRegionWithListeners(); + testRegionAttributes(); + } + + private void testBasicRegion() throws Exception { + @SuppressWarnings("rawtypes") Region region = ctx.getBean("basic", Region.class); assertEquals("basic", region.getName()); } - @Test - public void testExistingRegion() throws Exception { + private void testExistingRegion() throws Exception { + @SuppressWarnings("rawtypes") Region region = ctx.getBean("root", Region.class); // the name property seems to be ignored assertEquals("root", region.getName()); } - @Test - public void testRegionWithListeners() throws Exception { + @SuppressWarnings("rawtypes") + private void testRegionWithListeners() throws Exception { Region region = ctx.getBean("listeners", Region.class); assertEquals("listeners", region.getName()); CacheListener[] listeners = region.getAttributes().getCacheListeners(); @@ -91,17 +100,20 @@ public class RegionIntegrationTest { assertSame(CacheWrite.class, region.getAttributes().getCacheWriter().getClass()); } - //@Test - // TODO: disabled since the interest registration requires a proper pool to be created, which requires another JVM to run with the server/locator + // @Test + // TODO: disabled since the interest registration requires a proper pool to + // be created, which requires another JVM to run with the server/locator + @SuppressWarnings("rawtypes") public void testRegionInterest() throws Exception { ClientRegionFactoryBean regionFB = (ClientRegionFactoryBean) ctx.getBean("&basic-client"); System.out.println("**** interests are " + Arrays.toString(regionFB.getInterests())); - BeanDefinition bd = ((BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory()).getBeanDefinition("basic-client"); + BeanDefinition bd = ((BeanDefinitionRegistry) ctx.getAutowireCapableBeanFactory()) + .getBeanDefinition("basic-client"); System.out.println(bd.getPropertyValues().getPropertyValue("interests").getValue()); } - @Test - public void testRegionAttributes() throws Exception { + @SuppressWarnings("rawtypes") + private void testRegionAttributes() throws Exception { Region region = ctx.getBean("attr-region", Region.class); assertEquals("attr-region", region.getName()); RegionAttributes attr = region.getAttributes(); diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java index 5e75f95a..8ed43f9b 100644 --- a/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/CacheNamespaceTest.java @@ -44,23 +44,30 @@ public class CacheNamespaceTest extends RecreatingContextTest { } @Test - public void testBasicCache() throws Exception { + public void testAll() throws Exception { + testBasicCache(); + testNamedCache(); + testCacheWithXml(); + // testBasicClientCache(); + // testBasicClientCacheWithXml(); + testHeapTunedCache(); + } + + private void testBasicCache() throws Exception { assertTrue(ctx.containsBean("gemfire-cache")); CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&gemfire-cache"); assertNull(TestUtils.readField("cacheXml", cfb)); assertNull(TestUtils.readField("properties", cfb)); } - @Test - public void testNamedCache() throws Exception { + private void testNamedCache() throws Exception { assertTrue(ctx.containsBean("cache-with-name")); CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&cache-with-name"); assertNull(TestUtils.readField("cacheXml", cfb)); assertNull(TestUtils.readField("properties", cfb)); } - @Test - public void testCacheWithXml() throws Exception { + private void testCacheWithXml() throws Exception { assertTrue(ctx.containsBean("cache-with-xml")); CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&cache-with-xml"); Resource res = TestUtils.readField("cacheXml", cfb); @@ -106,8 +113,7 @@ public class CacheNamespaceTest extends RecreatingContextTest { assertEquals("gemfire-client-cache.xml", res.getFilename()); } - @Test - public void testHeapTunedCache() throws Exception { + private void testHeapTunedCache() throws Exception { assertTrue(ctx.containsBean("heap-tuned-cache")); CacheFactoryBean cfb = (CacheFactoryBean) ctx.getBean("&heap-tuned-cache"); Float chp = (Float) TestUtils.readField("criticalHeapPercentage", cfb); diff --git a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java index 57fac6a3..df38496a 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ClientRegionNamespaceTest.java @@ -56,23 +56,31 @@ public class ClientRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicClient() throws Exception { + public void testAll() throws Exception { + testBasicClient(); + testBeanNames(); + testPublishingClient(); + testPersistent(); + testOverflowToDisk(); + } + + private void testBasicClient() throws Exception { assertTrue(context.containsBean("simple")); } - @Test - public void testBeanNames() throws Exception { + private void testBeanNames() throws Exception { assertTrue(ObjectUtils.isEmpty(context.getAliases("publisher"))); } - @Test - public void testPublishingClient() throws Exception { + @SuppressWarnings("rawtypes") + private void testPublishingClient() throws Exception { assertTrue(context.containsBean("empty")); ClientRegionFactoryBean fb = context.getBean("&empty", ClientRegionFactoryBean.class); assertEquals(DataPolicy.EMPTY, TestUtils.readField("dataPolicy", fb)); } // @Test + @SuppressWarnings("rawtypes") public void testComplexClient() throws Exception { assertTrue(context.containsBean("complex")); ClientRegionFactoryBean fb = context.getBean("&complex", ClientRegionFactoryBean.class); @@ -97,8 +105,8 @@ public class ClientRegionNamespaceTest { assertEquals(".*", TestUtils.readField("key", regexInt)); } - @Test - public void testPersistent() throws Exception { + @SuppressWarnings("rawtypes") + private void testPersistent() throws Exception { assertTrue(context.containsBean("persistent")); Region region = context.getBean("persistent", Region.class); RegionAttributes attrs = region.getAttributes(); @@ -106,8 +114,8 @@ public class ClientRegionNamespaceTest { assertEquals(1, attrs.getDiskDirSizes()[0]); } - @Test - public void testOverflowToDisk() throws Exception { + @SuppressWarnings("rawtypes") + private void testOverflowToDisk() throws Exception { assertTrue(context.containsBean("overflow")); ClientRegionFactoryBean fb = context.getBean("&overflow", ClientRegionFactoryBean.class); assertEquals(DataPolicy.NORMAL, TestUtils.readField("dataPolicy", fb)); diff --git a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java index df572f52..ab81282b 100644 --- a/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/DiskStoreAndEvictionRegionParsingTest.java @@ -83,7 +83,14 @@ public class DiskStoreAndEvictionRegionParsingTest { } @Test - public void testDiskStore() { + public void testAll() throws Exception { + testDiskStore(); + testReplicaDataOptions(); + testPartitionDataOptions(); + testEntryTtl(); + } + + private void testDiskStore() { assertEquals("diskStore1", diskStore1.getName()); assertEquals(50, diskStore1.getQueueSize()); assertEquals(true, diskStore1.getAutoCompact()); @@ -95,12 +102,13 @@ public class DiskStoreAndEvictionRegionParsingTest { assertSame(diskStore1, cache.findDiskStore("diskStore1")); } - @Test - public void testReplicaDataOptions() throws Exception { + @SuppressWarnings("rawtypes") + private void testReplicaDataOptions() throws Exception { assertTrue(context.containsBean("replicated-data")); RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class); assertTrue(fb instanceof ReplicatedRegionFactoryBean); assertEquals(Scope.DISTRIBUTED_ACK, TestUtils.readField("scope", fb)); + @SuppressWarnings("unused") Region region = context.getBean("replicated-data", Region.class); // eviction tests RegionAttributes attrs = TestUtils.readField("attributes", fb); @@ -111,8 +119,8 @@ public class DiskStoreAndEvictionRegionParsingTest { assertNull(evicAttr.getObjectSizer()); } - @Test - public void testPartitionDataOptions() throws Exception { + @SuppressWarnings("rawtypes") + private void testPartitionDataOptions() throws Exception { assertTrue(context.containsBean("partition-data")); RegionFactoryBean fb = context.getBean("&partition-data", RegionFactoryBean.class); assertTrue(fb instanceof PartitionedRegionFactoryBean); @@ -129,8 +137,8 @@ public class DiskStoreAndEvictionRegionParsingTest { assertEquals(SimpleObjectSizer.class, sizer.getClass()); } - @Test - public void testEntryTtl() throws Exception { + @SuppressWarnings("rawtypes") + private void testEntryTtl() throws Exception { assertTrue(context.containsBean("replicated-data")); RegionFactoryBean fb = context.getBean("&replicated-data", RegionFactoryBean.class); RegionAttributes attrs = TestUtils.readField("attributes", fb); diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java new file mode 100644 index 00000000..2b21fde5 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/GemfireV6GatewayNamespaceTest.java @@ -0,0 +1,107 @@ +/* + * Copyright 2010-2012 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.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.springframework.data.gemfire.RecreatingContextTest; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.wan.GatewayHubFactoryBean; +import org.springframework.data.gemfire.wan.GatewayProxy; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.util.GatewayEvent; +import com.gemstone.gemfire.cache.util.GatewayEventListener; +import com.gemstone.gemfire.cache.util.GatewayHub; + +/** + * @author David Turanski + * + */ +public class GemfireV6GatewayNamespaceTest extends RecreatingContextTest { + @Override + protected String location() { + return "/org/springframework/data/gemfire/config/gateway-v6-ns.xml"; + } + + /* + * Faster this way + */ + @Test + public void test() throws Exception { + testGatewayHubFactoryBean(); + testGatewaysInGemfire(); + } + + private void testGatewayHubFactoryBean() throws Exception { + GatewayHubFactoryBean gwhfb = ctx.getBean("&gateway-hub", GatewayHubFactoryBean.class); + List gateways = TestUtils.readField("gateways", gwhfb); + assertNotNull(gateways); + assertEquals(2, gateways.size()); + GatewayProxy gwp = gateways.get(0); + assertEquals("gateway", gwp.getId()); + assertTrue(gwp.getListeners().get(0) instanceof GatewayListener); + + gwp = gateways.get(1); + assertEquals("gateway2", gwp.getId()); + List endpoints = gwp.getEndpoints(); + assertEquals(2, endpoints.size()); + GatewayProxy.GatewayEndpoint endpoint; + + endpoint = endpoints.get(0); + assertEquals("endpoint1", endpoint.getId()); + assertEquals("host1", endpoint.getHost()); + assertEquals(1234, endpoint.getPort()); + + endpoint = endpoints.get(1); + assertEquals("endpoint2", endpoint.getId()); + assertEquals("host2", endpoint.getHost()); + assertEquals(2345, endpoint.getPort()); + } + + @SuppressWarnings("rawtypes") + private void testGatewaysInGemfire() { + Cache cache = ctx.getBean("gemfire-cache", Cache.class); + GatewayHub gwh = cache.getGatewayHub("gateway-hub"); + assertNotNull(gwh); + + Region region = ctx.getBean("region-with-gateway", Region.class); + assertTrue(region.getAttributes().getEnableGateway()); + assertEquals("gateway-hub", region.getAttributes().getGatewayHubId()); + } + + public static class GatewayListener implements GatewayEventListener { + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public boolean processEvents(List event) { + // TODO Auto-generated method stub + return false; + } + + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java new file mode 100644 index 00000000..b3e7fec2 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/GemfireV7GatewayNamespaceTest.java @@ -0,0 +1,221 @@ +/* + * Copyright 2010-2012 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.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Set; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.data.gemfire.RecreatingContextTest; +import org.springframework.data.gemfire.TestUtils; +import org.springframework.data.gemfire.wan.GatewaySenderFactoryBean; + +import com.gemstone.gemfire.cache.AsyncEventQueue; +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.util.Gateway.OrderPolicy; +import com.gemstone.gemfire.cache.wan.AsyncEvent; +import com.gemstone.gemfire.cache.wan.AsyncEventListener; +import com.gemstone.gemfire.cache.wan.GatewayEventFilter; +import com.gemstone.gemfire.cache.wan.GatewayReceiver; +import com.gemstone.gemfire.cache.wan.GatewaySender; +import com.gemstone.gemfire.cache.wan.GatewayTransportFilter; + +/** + * This test is only valid for GF 7.0 and above + * + * @author David Turanski + * + */ +public class GemfireV7GatewayNamespaceTest extends RecreatingContextTest { + @Override + protected String location() { + return "/org/springframework/data/gemfire/config/gateway-v7-ns.xml"; + } + + @Before + @Override + public void createCtx() { + if (ParsingUtils.GEMFIRE_VERSION.startsWith("7")) { + super.createCtx(); + } + } + + /* + * Faster this way + */ + @Test + public void test() throws Exception { + if (ctx != null) { + testGatewaySender(); + testInnerGatewaySender(); + testInnerGatewayReceiver(); + testAsyncEventQueue(); + } + } + + /** + * + */ + private void testAsyncEventQueue() { + AsyncEventQueue aseq = ctx.getBean("async-event-queue", AsyncEventQueue.class); + assertEquals(10, aseq.getBatchSize()); + assertTrue(aseq.isPersistent()); + assertEquals("diskstore", aseq.getDiskStoreName()); + assertEquals(50, aseq.getMaximumQueueMemory()); + } + + private void testGatewaySender() throws Exception { + GatewaySenderFactoryBean gwsfb = ctx.getBean("&gateway-sender", GatewaySenderFactoryBean.class); + Cache cache = TestUtils.readField("cache", gwsfb); + assertNotNull(cache); + List eventFilters = TestUtils.readField("eventFilters", gwsfb); + assertNotNull(eventFilters); + assertEquals(2, eventFilters.size()); + assertTrue(eventFilters.get(0) instanceof TestEventFilter); + + List transportFilters = TestUtils.readField("transportFilters", gwsfb); + assertNotNull(transportFilters); + assertEquals(2, transportFilters.size()); + assertTrue(transportFilters.get(0) instanceof TestTransportFilter); + + assertEquals(2, TestUtils.readField("remoteDistributedSystemId", gwsfb)); + assertEquals(10, TestUtils.readField("alertThreshold", gwsfb)); + assertEquals(11, TestUtils.readField("batchSize", gwsfb)); + assertEquals(12, TestUtils.readField("dispatcherThreads", gwsfb)); + assertEquals(true, TestUtils.readField("manualStart", gwsfb)); + } + + private void testInnerGatewaySender() { + Region region = ctx.getBean("region-inner-gateway-sender", Region.class); + GatewaySender gws = ctx.getBean("gateway-sender", GatewaySender.class); + assertNotNull(region.getAttributes().getGatewaySenders()); + assertEquals(2, region.getAttributes().getGatewaySenders().size()); + + // Isolate the inner gateway + Set gatewaySenders = region.getAttributes().getGatewaySenders(); + assertTrue(gatewaySenders.remove(gws)); + gatewaySenders.remove(gws); + + gws = gatewaySenders.iterator().next(); + List eventFilters = gws.getGatewayEventFilters(); + assertNotNull(eventFilters); + assertEquals(1, eventFilters.size()); + assertTrue(eventFilters.get(0) instanceof TestEventFilter); + + List transportFilters = gws.getGatewayTransportFilters(); + + assertNotNull(transportFilters); + assertEquals(1, transportFilters.size()); + assertTrue(transportFilters.get(0) instanceof TestTransportFilter); + + assertEquals(1, gws.getRemoteDSId()); + assertEquals(true, gws.isManualStart()); + assertEquals(10, gws.getAlertThreshold()); + assertEquals(11, gws.getBatchSize()); + assertEquals(3000, gws.getBatchTimeInterval()); + assertEquals(2, gws.getDispatcherThreads()); + assertEquals("diskstore", gws.getDiskStoreName()); + assertTrue(gws.isBatchConflationEnabled()); + assertEquals(50, gws.getMaximumQueueMemory()); + assertEquals(OrderPolicy.THREAD, gws.getOrderPolicy()); + assertTrue(gws.isPersistenceEnabled()); + assertTrue(gws.isParallel()); + assertEquals(16536, gws.getSocketBufferSize()); + assertEquals(3000, gws.getSocketReadTimeout()); + } + + private void testInnerGatewayReceiver() { + GatewayReceiver gwr = ctx.getBean("gateway-receiver", GatewayReceiver.class); + assertEquals(12345, gwr.getStartPort()); + assertEquals(23456, gwr.getEndPort()); + assertEquals("192.168.0.1", gwr.getBindAddress()); + assertEquals(3000, gwr.getMaximumTimeBetweenPings()); + assertEquals(16536, gwr.getSocketBufferSize()); + } + + @SuppressWarnings("rawtypes") + public static class TestEventFilter implements GatewayEventFilter { + + @Override + public void close() { + // TODO Auto-generated method stub + } + + @Override + public void afterAcknowledgement(AsyncEvent arg0) { + // TODO Auto-generated method stub + } + + @Override + public boolean beforeEnqueue(AsyncEvent arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean beforeTransmit(AsyncEvent arg0) { + // TODO Auto-generated method stub + return false; + } + + } + + public static class TestTransportFilter implements GatewayTransportFilter { + + @Override + public void close() { + // TODO Auto-generated method stub + + } + + @Override + public InputStream getInputStream(InputStream arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public OutputStream getOutputStream(OutputStream arg0) { + // TODO Auto-generated method stub + return null; + } + + } + + @SuppressWarnings("rawtypes") + public static class TestAsyncEventListener implements AsyncEventListener { + + @Override + public void close() { + // TODO Auto-generated method stub + } + + @Override + public boolean processEvents(List arg0) { + // TODO Auto-generated method stub + return false; + } + + } +} diff --git a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java index 012c92bd..44a48096 100644 --- a/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/IndexNamespaceTest.java @@ -38,11 +38,11 @@ import com.gemstone.gemfire.cache.query.IndexType; @ContextConfiguration("index-ns.xml") public class IndexNamespaceTest { - private String name = "test-index"; + private final String name = "test-index"; + @Autowired private ApplicationContext context; - @Before public void setUp() throws Exception { Cache cache = (Cache) context.getBean("gemfire-cache"); @@ -52,7 +52,12 @@ public class IndexNamespaceTest { } @Test - public void testBasicIndex() throws Exception { + public void testAll() throws Exception { + testBasicIndex(); + testComplexIndex(); + } + + private void testBasicIndex() throws Exception { Index idx = (Index) context.getBean("simple"); assertEquals("/test-index", idx.getFromClause()); @@ -62,8 +67,7 @@ public class IndexNamespaceTest { assertEquals(IndexType.FUNCTIONAL, idx.getType()); } - @Test - public void testComplexIndex() throws Exception { + private void testComplexIndex() throws Exception { Index idx = (Index) context.getBean("complex"); assertEquals("/test-index tsi", idx.getFromClause()); diff --git a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java index d646e752..38109ffc 100644 --- a/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/LocalRegionNamespaceTest.java @@ -49,12 +49,20 @@ public class LocalRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicLocal() throws Exception { + public void testAll() throws Exception { + testBasicLocal(); + testComplexLocal(); + testLocalWithAttributes(); + testPublishingLocal(); + testRegionLookup(); + } + + private void testBasicLocal() throws Exception { assertTrue(context.containsBean("simple")); } - @Test - public void testPublishingLocal() throws Exception { + @SuppressWarnings("rawtypes") + private void testPublishingLocal() throws Exception { assertTrue(context.containsBean("pub")); RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class); assertEquals("NORMAL", TestUtils.readField("dataPolicyName", fb)); @@ -64,8 +72,8 @@ public class LocalRegionNamespaceTest { assertFalse(attrs.getPublisher()); } - @Test - public void testComplexLocal() throws Exception { + @SuppressWarnings("rawtypes") + private void testComplexLocal() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); @@ -77,8 +85,8 @@ public class LocalRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } - @Test - public void testLocalWithAttributes() throws Exception { + @SuppressWarnings("rawtypes") + private void testLocalWithAttributes() throws Exception { assertTrue(context.containsBean("local-with-attributes")); Region region = context.getBean("local-with-attributes", Region.class); RegionAttributes attrs = region.getAttributes(); @@ -90,8 +98,8 @@ public class LocalRegionNamespaceTest { assertEquals(true, attrs.isDiskSynchronous()); } - @Test - public void testRegionLookup() throws Exception { + @SuppressWarnings("rawtypes") + private void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); Region existing = cache.createRegionFactory().create("existing"); assertTrue(context.containsBean("lookup")); diff --git a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java index e4056f79..66d26cc4 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -48,12 +48,18 @@ public class PartitionedRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicPartition() throws Exception { + public void testAll() throws Exception { + testBasicPartition(); + testComplexPartition(); + testPartitionOptions(); + } + + private void testBasicPartition() throws Exception { assertTrue(context.containsBean("simple")); } - @Test - public void testPartitionOptions() throws Exception { + @SuppressWarnings("rawtypes") + private void testPartitionOptions() throws Exception { assertTrue(context.containsBean("options")); RegionFactoryBean fb = context.getBean("&options", RegionFactoryBean.class); assertTrue(fb instanceof PartitionedRegionFactoryBean); @@ -70,8 +76,8 @@ public class PartitionedRegionNamespaceTest { assertSame(SimplePartitionResolver.class, pAttr.getPartitionResolver().getClass()); } - @Test - public void testComplexPartition() throws Exception { + @SuppressWarnings("rawtypes") + private void testComplexPartition() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); diff --git a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java index cd11c51a..cb182055 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PoolNamespaceTest.java @@ -46,7 +46,12 @@ public class PoolNamespaceTest { private ApplicationContext context; @Test - public void testBasicClient() throws Exception { + public void testAll() throws Exception { + testBasicClient(); + testComplexPool(); + } + + private void testBasicClient() throws Exception { assertTrue(context.containsBean("gemfire-pool")); assertEquals(context.getBean("gemfire-pool"), PoolManager.find("gemfire-pool")); PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&gemfire-pool"); @@ -57,8 +62,7 @@ public class PoolNamespaceTest { assertEquals(40403, locator.getPort()); } - @Test - public void testComplexPool() throws Exception { + private void testComplexPool() throws Exception { assertTrue(context.containsBean("complex")); PoolFactoryBean pfb = (PoolFactoryBean) context.getBean("&complex"); assertEquals(30, TestUtils.readField("retryAttempts", pfb)); diff --git a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java index 0184f1d9..7178836d 100644 --- a/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/ReplicatedRegionNamespaceTest.java @@ -50,12 +50,20 @@ public class ReplicatedRegionNamespaceTest { private ApplicationContext context; @Test - public void testBasicReplica() throws Exception { + public void testAll() throws Exception { + testBasicReplica(); + testPublishingReplica(); + testComplexReplica(); + testRegionLookup(); + testReplicaWithAttributes(); + } + + private void testBasicReplica() throws Exception { assertTrue(context.containsBean("simple")); } - @Test - public void testPublishingReplica() throws Exception { + @SuppressWarnings("rawtypes") + private void testPublishingReplica() throws Exception { assertTrue(context.containsBean("pub")); RegionFactoryBean fb = context.getBean("&pub", RegionFactoryBean.class); assertTrue(fb instanceof ReplicatedRegionFactoryBean); @@ -65,8 +73,8 @@ public class ReplicatedRegionNamespaceTest { assertFalse(attrs.getPublisher()); } - @Test - public void testComplexReplica() throws Exception { + @SuppressWarnings("rawtypes") + private void testComplexReplica() throws Exception { assertTrue(context.containsBean("complex")); RegionFactoryBean fb = context.getBean("&complex", RegionFactoryBean.class); CacheListener[] listeners = TestUtils.readField("cacheListeners", fb); @@ -78,8 +86,8 @@ public class ReplicatedRegionNamespaceTest { assertSame(context.getBean("c-writer"), TestUtils.readField("cacheWriter", fb)); } - @Test - public void testReplicaWithAttributes() throws Exception { + @SuppressWarnings("rawtypes") + private void testReplicaWithAttributes() throws Exception { assertTrue(context.containsBean("replicated-with-attributes")); Region region = context.getBean("replicated-with-attributes", Region.class); RegionAttributes attrs = region.getAttributes(); @@ -99,8 +107,8 @@ public class ReplicatedRegionNamespaceTest { assertEquals(true, attrs.getMulticastEnabled()); } - @Test - public void testRegionLookup() throws Exception { + @SuppressWarnings("rawtypes") + private void testRegionLookup() throws Exception { Cache cache = context.getBean(Cache.class); Region existing = cache.createRegionFactory().create("existing"); assertTrue(context.containsBean("lookup")); diff --git a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java index dc7b8c67..409aa0bc 100644 --- a/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/SubRegionNamespaceTest.java @@ -45,68 +45,71 @@ public class SubRegionNamespaceTest { @Autowired private ApplicationContext context; - - - @SuppressWarnings("rawtypes") @Test - public void testNestedReplicatedRegions() { - Region parent = context.getBean("parent",Region.class); + public void testAll() throws Exception { + testComplexNestedRegions(); + testMixedNestedRegions(); + testNestedRegionsWithSiblings(); + testNestedReplicatedRegions(); + } + + @SuppressWarnings("rawtypes") + private void testNestedReplicatedRegions() { + Region parent = context.getBean("parent", Region.class); Region child = context.getBean("/parent/child", Region.class); Region grandchild = context.getBean("/parent/child/grandchild", Region.class); assertNotNull(child); - assertEquals("/parent/child",child.getFullPath()); - assertSame(child,parent.getSubregion("child")); - - assertEquals("/parent/child/grandchild",grandchild.getFullPath()); - assertSame(grandchild,child.getSubregion("grandchild")); - + assertEquals("/parent/child", child.getFullPath()); + assertSame(child, parent.getSubregion("child")); + + assertEquals("/parent/child/grandchild", grandchild.getFullPath()); + assertSame(grandchild, child.getSubregion("grandchild")); + } - + @SuppressWarnings({ "unused", "rawtypes", "unchecked" }) - @Test - public void testMixedNestedRegions() { + private void testMixedNestedRegions() { Cache cache = context.getBean(Cache.class); - - Region parent = context.getBean("replicatedParent",Region.class); - parent.createSubregion("lookupChild",new AttributesFactory().create()); - + + Region parent = context.getBean("replicatedParent", Region.class); + parent.createSubregion("lookupChild", new AttributesFactory().create()); + Region child = context.getBean("/replicatedParent/lookupChild", Region.class); Region grandchild = context.getBean("/replicatedParent/lookupChild/partitionedGrandchild", Region.class); assertNotNull(child); - assertEquals("/replicatedParent/lookupChild",child.getFullPath()); - assertSame(child,parent.getSubregion("lookupChild")); - - assertEquals("/replicatedParent/lookupChild/partitionedGrandchild",grandchild.getFullPath()); - assertSame(grandchild,child.getSubregion("partitionedGrandchild")); - + assertEquals("/replicatedParent/lookupChild", child.getFullPath()); + assertSame(child, parent.getSubregion("lookupChild")); + + assertEquals("/replicatedParent/lookupChild/partitionedGrandchild", grandchild.getFullPath()); + assertSame(grandchild, child.getSubregion("partitionedGrandchild")); + } - + @SuppressWarnings("rawtypes") - @Test - public void testNestedRegionsWithSiblings() { - Region parent = context.getBean("parentWithSiblings",Region.class); - Region child1 = context.getBean("/parentWithSiblings/child1",Region.class); - assertEquals("/parentWithSiblings/child1",child1.getFullPath()); - Region child2 = context.getBean("/parentWithSiblings/child2",Region.class); - assertEquals("/parentWithSiblings/child2",child2.getFullPath()); - assertSame(child1,parent.getSubregion("child1")); - assertSame(child2,parent.getSubregion("child2")); - - Region grandchild1 = context.getBean("/parentWithSiblings/child1/grandChild11",Region.class); - assertEquals("/parentWithSiblings/child1/grandChild11",grandchild1.getFullPath()); + private void testNestedRegionsWithSiblings() { + Region parent = context.getBean("parentWithSiblings", Region.class); + Region child1 = context.getBean("/parentWithSiblings/child1", Region.class); + assertEquals("/parentWithSiblings/child1", child1.getFullPath()); + Region child2 = context.getBean("/parentWithSiblings/child2", Region.class); + assertEquals("/parentWithSiblings/child2", child2.getFullPath()); + assertSame(child1, parent.getSubregion("child1")); + assertSame(child2, parent.getSubregion("child2")); + + Region grandchild1 = context.getBean("/parentWithSiblings/child1/grandChild11", Region.class); + assertEquals("/parentWithSiblings/child1/grandChild11", grandchild1.getFullPath()); } - + @SuppressWarnings({ "unused", "rawtypes" }) - @Test - public void testComplexNestedRegions() throws Exception { - Region parent = context.getBean("complexNested",Region.class); - Region child1 = context.getBean("/complexNested/child1",Region.class); - Region child2 = context.getBean("/complexNested/child2",Region.class); - Region grandchild1 = context.getBean("/complexNested/child1/grandChild11",Region.class); - - SubRegionFactoryBean grandchild1fb = context.getBean("&/complexNested/child1/grandChild11",SubRegionFactoryBean.class); + private void testComplexNestedRegions() throws Exception { + Region parent = context.getBean("complexNested", Region.class); + Region child1 = context.getBean("/complexNested/child1", Region.class); + Region child2 = context.getBean("/complexNested/child2", Region.class); + Region grandchild1 = context.getBean("/complexNested/child1/grandChild11", Region.class); + + SubRegionFactoryBean grandchild1fb = context.getBean("&/complexNested/child1/grandChild11", + SubRegionFactoryBean.class); assertNotNull(grandchild1fb); - RegionAttributes attr = grandchild1fb.create(); + RegionAttributes attr = grandchild1fb.create(); assertNotNull(attr); CacheLoader cl = attr.getCacheLoader(); assertNotNull(cl); diff --git a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java b/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java index 618c5cf1..91df38a0 100644 --- a/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/TxEventHandlersTest.java @@ -52,6 +52,7 @@ public class TxEventHandlersTest { @Resource(name = "gemfire-cache") Cache cache; + @SuppressWarnings("rawtypes") @Resource(name = "local") Region local; diff --git a/src/test/java/org/springframework/data/gemfire/mapping/PdxReaderPropertyAccessorUnitTests.java b/src/test/java/org/springframework/data/gemfire/mapping/PdxReaderPropertyAccessorUnitTests.java index 5bfffdde..e1127d61 100644 --- a/src/test/java/org/springframework/data/gemfire/mapping/PdxReaderPropertyAccessorUnitTests.java +++ b/src/test/java/org/springframework/data/gemfire/mapping/PdxReaderPropertyAccessorUnitTests.java @@ -15,10 +15,12 @@ */ package org.springframework.data.gemfire.mapping; -import static org.hamcrest.CoreMatchers.*; -import static org.junit.Assert.*; -import static org.mockito.Mockito.*; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.when; +import java.util.Arrays; import java.util.List; import org.junit.Test; @@ -28,7 +30,6 @@ import org.mockito.runners.MockitoJUnitRunner; import org.springframework.core.convert.TypeDescriptor; import org.springframework.expression.TypedValue; -import com.gemstone.bp.edu.emory.mathcs.backport.java.util.Arrays; import com.gemstone.gemfire.pdx.PdxReader; /** @@ -42,7 +43,6 @@ public class PdxReaderPropertyAccessorUnitTests { PdxReader reader; @Test - @SuppressWarnings("unchecked") public void appliesToPdxReadersOnly() { List> classes = Arrays.asList(PdxReaderPropertyAccessor.INSTANCE.getSpecificTargetClasses()); assertThat(classes, hasItem(PdxReader.class)); diff --git a/src/test/java/org/springframework/data/gemfire/repository/sample/Address.java b/src/test/java/org/springframework/data/gemfire/repository/sample/Address.java index 0de38379..754eb8f8 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/sample/Address.java +++ b/src/test/java/org/springframework/data/gemfire/repository/sample/Address.java @@ -15,12 +15,17 @@ */ package org.springframework.data.gemfire.repository.sample; +import org.springframework.data.annotation.Id; +import org.springframework.data.gemfire.mapping.Region; + /** * * @author Oliver Gierke */ +@Region("address") public class Address { - + @Id public String zipCode; + public String city; } diff --git a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java index 11ef0405..7440a9d5 100644 --- a/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java +++ b/src/test/java/org/springframework/data/gemfire/repository/support/GemfireRepositoryFactoryIntegrationTests.java @@ -15,13 +15,13 @@ */ package org.springframework.data.gemfire.repository.support; +import java.util.Collections; + import org.junit.Test; import org.springframework.data.gemfire.mapping.Regions; import org.springframework.data.gemfire.repository.sample.PersonRepository; import org.springframework.test.context.ContextConfiguration; -import com.gemstone.bp.edu.emory.mathcs.backport.java.util.Collections; - /** * Integration test for {@link GemfireRepositoryFactory}. * @@ -41,7 +41,7 @@ public class GemfireRepositoryFactoryIntegrationTests extends AbstractGemfireRep @SuppressWarnings("unchecked") public void throwsExceptionIfReferencedRegionIsNotConfigured() { - GemfireRepositoryFactory factory = new GemfireRepositoryFactory(Collections.emptySet(), null); + GemfireRepositoryFactory factory = new GemfireRepositoryFactory((Iterable) Collections.emptySet(), null); factory.getRepository(PersonRepository.class); } } diff --git a/src/test/resources/org/springframework/data/gemfire/config/gateway-v6-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/gateway-v6-ns.xml new file mode 100644 index 00000000..bbc8c212 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/gateway-v6-ns.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/gateway-v7-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/gateway-v7-ns.xml new file mode 100644 index 00000000..1f68f483 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/gateway-v7-ns.xml @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml index e3656389..28d94c40 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/local-ns.xml @@ -15,8 +15,8 @@ - - + + diff --git a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml index e8c5ce65..9101253e 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/replicated-ns.xml @@ -16,7 +16,7 @@ - + diff --git a/src/test/resources/org/springframework/data/gemfire/repository/config/repo-context.xml b/src/test/resources/org/springframework/data/gemfire/repository/config/repo-context.xml index 6c8c4a44..515f9105 100644 --- a/src/test/resources/org/springframework/data/gemfire/repository/config/repo-context.xml +++ b/src/test/resources/org/springframework/data/gemfire/repository/config/repo-context.xml @@ -1,14 +1,17 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:p="http://www.springframework.org/schema/p" + xmlns:gfe="http://www.springframework.org/schema/gemfire" + xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire" + xsi:schemaLocation="http://www.springframework.org/schema/gemfire http://www.springframework.org/schema/gemfire/spring-gemfire.xsd + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/data/gemfire http://www.springframework.org/schema/data/gemfire/spring-data-gemfire.xsd"> - + - + +