diff --git a/docs/pom.xml b/docs/pom.xml index eefa6b01..c12506a6 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.data.gemfire spring-gemfire - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT Spring GemFire Documentation diff --git a/docs/src/main/resources/changelog.txt b/docs/src/main/resources/changelog.txt index ba844545..c483776e 100644 --- a/docs/src/main/resources/changelog.txt +++ b/docs/src/main/resources/changelog.txt @@ -2,15 +2,29 @@ SPRING GEMFIRE INTEGRATION CHANGELOG ==================================== http://www.springsource.org/spring-gemfire -Changes in version 1.0.1 (2011-mm-dd) +Changes in version 1.0.1 (2011-04-26) ------------------------------------- General -* Upgraded to GemFire 6.5.1.2 +* Upgraded to GemFire 6.5.1.4 * Fix networking issue with the sample on some Linux distributions (Ubuntu) +* Loosen type constraints in the schema to allow placeholders +* Added 'statistics' attribute to all write regions Package org.springframework.data.gemfire * Introduced auto-close (configurable) on RegionFactoryBean +Package org.springframework.data.gemfire.config +* Fixed bug causing region names to be used as aliases for region beans + +Package org.springframework.data.gemfire.client +* Improved dependency initialization between cache and pools + +Package org.springframework.data.gemfire.serialization +* Improved cache-wide registration of custom instantiators + +Package org.springframework.data.gemfire.support +* Introduced GemfireDaoSupport + Changes in version 1.0.0 (2011-02-02) ------------------------------------- diff --git a/pom.xml b/pom.xml index b7a74b74..2501a6a6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.data.gemfire spring-gemfire - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT Spring GemFire Project Spring GemFire Integration for Java @@ -280,7 +280,7 @@ limitations under the License. protected 1.5 - http://java.sun.com/j2se/1.6.0/docs/api/ + http://download.oracle.com/javase/6/docs/api/ http://static.springsource.org/spring/docs/3.0.x/javadoc-api/ diff --git a/samples/hello-world/pom.xml b/samples/hello-world/pom.xml index c9ec2bbd..e098fbef 100644 --- a/samples/hello-world/pom.xml +++ b/samples/hello-world/pom.xml @@ -4,13 +4,13 @@ samples org.springframework.data.gemfire.samples - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT ../ 4.0.0 org.springframework.data.gemfire.samples hello-world - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT Spring GemFire - Hello World Sample A simple Hello World example illustrating the basic steps in configuring GemFire with Spring diff --git a/samples/pom.xml b/samples/pom.xml index e43501df..ce5efb30 100644 --- a/samples/pom.xml +++ b/samples/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.springframework.data.gemfire.samples samples - 1.0.1.BUILD-SNAPSHOT + 1.0.2.BUILD-SNAPSHOT Spring GemFire Samples pom http://www.springframework.org/spring-gemfire diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java index 343fafc8..7a35cbf6 100644 --- a/src/main/java/org/springframework/data/gemfire/config/CacheParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/CacheParser.java @@ -32,6 +32,7 @@ import org.w3c.dom.Element; */ class CacheParser extends AbstractSingleBeanDefinitionParser { + @Override protected Class getBeanClass(Element element) { return CacheFactoryBean.class; } diff --git a/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java b/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java new file mode 100644 index 00000000..b2bcafdc --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/CacheServerParser.java @@ -0,0 +1,86 @@ +/* + * Copyright 2011 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.BeanDefinitionStoreException; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +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.server.CacheServerFactoryBean; +import org.springframework.util.StringUtils; +import org.springframework.util.xml.DomUtils; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * Namespace parser for "cache-server" element. + * + * @author Costin Leau + */ +class CacheServerParser extends AbstractSimpleBeanDefinitionParser { + + @Override + protected Class getBeanClass(Element element) { + return CacheServerFactoryBean.class; + } + + @Override + protected String resolveId(Element element, AbstractBeanDefinition definition, ParserContext parserContext) + throws BeanDefinitionStoreException { + String name = super.resolveId(element, definition, parserContext); + if (!StringUtils.hasText(name)) { + name = "gemfire-server"; + } + return name; + } + + @Override + protected boolean isEligibleAttribute(Attr attribute, ParserContext parserContext) { + return super.isEligibleAttribute(attribute, parserContext) && !"groups".equals(attribute.getName()) + && !"cache-ref".equals(attribute.getName()); + } + + @Override + protected void postProcess(BeanDefinitionBuilder builder, Element element) { + + String attr = element.getAttribute("cache-ref"); + // add cache reference (fallback to default if nothing is specified) + builder.addPropertyReference("cache", (StringUtils.hasText(attr) ? attr : "gemfire-cache")); + + attr = element.getAttribute("groups"); + if (StringUtils.hasText(attr)) { + builder.addPropertyValue("serverGroups", StringUtils.commaDelimitedListToStringArray(attr)); + } + + parseSubscription(builder, element); + } + + private void parseSubscription(BeanDefinitionBuilder builder, Element element) { + Element subConfig = DomUtils.getChildElementByTagName(element, "subscription-config"); + if (subConfig == null) { + return; + } + + ParsingUtils.setPropertyValue(subConfig, builder, "capacity", "subscriptionCapacity"); + ParsingUtils.setPropertyValue(subConfig, builder, "disk-store", "subscriptionDiskStore"); + String attr = element.getAttribute("eviction-type"); + if (StringUtils.hasText(attr)) { + builder.addPropertyValue("subscriptionEvictionPolicy", attr.toUpperCase()); + } + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java index e0a39fa2..22affcea 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ClientRegionParser.java @@ -89,6 +89,8 @@ class ClientRegionParser extends AliasReplacingBeanDefinitionParser { // client attributes BeanDefinitionBuilder attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); + ParsingUtils.parseStatistics(element, attrBuilder); + boolean overwriteDataPolicy = false; overwriteDataPolicy |= ParsingUtils.parseEviction(parserContext, element, attrBuilder); 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 bd2f1045..1d4101dd 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireNamespaceHandler.java @@ -32,6 +32,7 @@ class GemfireNamespaceHandler extends NamespaceHandlerSupport { registerBeanDefinitionParser("partitioned-region", new PartitionedRegionParser()); registerBeanDefinitionParser("client-region", new ClientRegionParser()); registerBeanDefinitionParser("pool", new PoolParser()); + registerBeanDefinitionParser("cache-server", new CacheServerParser()); registerBeanDefinitionParser("transaction-manager", new TransactionManagerParser()); } 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 38bc6be6..de338990 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java +++ b/src/main/java/org/springframework/data/gemfire/config/ParsingUtils.java @@ -217,4 +217,9 @@ abstract class ParsingUtils { attrBuilder.addPropertyValue("evictionAttributes", evictionDefBuilder.getBeanDefinition()); return true; } + + + static void parseStatistics(Element element, BeanDefinitionBuilder attrBuilder) { + setPropertyValue(element, attrBuilder, "statistics", "statisticsEnabled"); + } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java index 42645e9e..b4f2bc16 100644 --- a/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/PartitionedRegionParser.java @@ -78,6 +78,7 @@ class PartitionedRegionParser extends AliasReplacingBeanDefinitionParser { ParsingUtils.parseEviction(parserContext, element, attrBuilder); ParsingUtils.parseDiskStorage(element, attrBuilder); + ParsingUtils.parseStatistics(element, attrBuilder); // partition attributes BeanDefinitionBuilder parAttrBuilder = BeanDefinitionBuilder.genericBeanDefinition(PartitionAttributesFactoryBean.class); diff --git a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java index 9a319fa6..b79852d4 100644 --- a/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java +++ b/src/main/java/org/springframework/data/gemfire/config/ReplicatedRegionParser.java @@ -64,6 +64,8 @@ class ReplicatedRegionParser extends AliasReplacingBeanDefinitionParser { // add attributes BeanDefinitionBuilder attrBuilder = BeanDefinitionBuilder.genericBeanDefinition(RegionAttributesFactoryBean.class); + ParsingUtils.parseStatistics(element, attrBuilder); + attr = element.getAttribute("publisher"); if (StringUtils.hasText(attr)) { attrBuilder.addPropertyValue("publisher", Boolean.valueOf(attr)); diff --git a/src/main/java/org/springframework/data/gemfire/serialization/InstantiatorFactoryBean.java b/src/main/java/org/springframework/data/gemfire/serialization/InstantiatorFactoryBean.java index 0b90c7dc..83bbafce 100644 --- a/src/main/java/org/springframework/data/gemfire/serialization/InstantiatorFactoryBean.java +++ b/src/main/java/org/springframework/data/gemfire/serialization/InstantiatorFactoryBean.java @@ -123,7 +123,7 @@ public class InstantiatorFactoryBean implements BeanClassLoaderAware, FactoryBea * Sets the distribution of the region of this {@link Instantiator} during the container startup. * Default is false, meaning the registration will not be distributed to other clients. * - * @see #register(Instantiator, boolean) + * @see Instantiator#register(Instantiator, boolean) * @param distribute whether the registration is distributable or not */ public void setDistribute(boolean distribute) { diff --git a/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java b/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java new file mode 100644 index 00000000..8c0db0f7 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/server/CacheServerFactoryBean.java @@ -0,0 +1,230 @@ +/* + * Copyright 2011 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.server; + +import java.io.IOException; +import java.util.Collections; +import java.util.Set; + +import org.springframework.beans.factory.BeanInitializationException; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.beans.factory.FactoryBean; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.SmartLifecycle; +import org.springframework.core.io.Resource; +import org.springframework.util.Assert; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.InterestRegistrationListener; +import com.gemstone.gemfire.cache.server.CacheServer; +import com.gemstone.gemfire.cache.server.ClientSubscriptionConfig; +import com.gemstone.gemfire.cache.server.ServerLoadProbe; + +/** + * FactoryBean for easy creation and configuration of GemFire {@link CacheServer} instances. + * + * @author Costin Leau + */ +public class CacheServerFactoryBean implements FactoryBean, InitializingBean, DisposableBean, + SmartLifecycle { + + private boolean autoStartup = true; + + private int port = CacheServer.DEFAULT_PORT; + private int maxConnections = CacheServer.DEFAULT_MAX_CONNECTIONS; + private int maxThreads = CacheServer.DEFAULT_MAX_THREADS; + private boolean notifyBySubscription = CacheServer.DEFAULT_NOTIFY_BY_SUBSCRIPTION; + private int socketBufferSize = CacheServer.DEFAULT_SOCKET_BUFFER_SIZE; + private int maxTimeBetweenPings = CacheServer.DEFAULT_MAXIMUM_TIME_BETWEEN_PINGS; + private int maxMessageCount = CacheServer.DEFAULT_MAXIMUM_MESSAGE_COUNT; + private int messageTimeToLive = CacheServer.DEFAULT_MESSAGE_TIME_TO_LIVE; + private String[] serverGroups = CacheServer.DEFAULT_GROUPS; + private ServerLoadProbe serverLoadProbe = CacheServer.DEFAULT_LOAD_PROBE; + private long loadPollInterval = CacheServer.DEFAULT_LOAD_POLL_INTERVAL; + private String bindAddress = CacheServer.DEFAULT_BIND_ADDRESS; + private String hostNameForClients = CacheServer.DEFAULT_HOSTNAME_FOR_CLIENTS; + private Set listeners = Collections.emptySet(); + + private SubscriptionEvictionPolicy evictionPolicy = SubscriptionEvictionPolicy.valueOf(ClientSubscriptionConfig.DEFAULT_EVICTION_POLICY.toUpperCase()); + private int subscriptionCapacity = ClientSubscriptionConfig.DEFAULT_CAPACITY; + private Resource subscriptionDiskStore; + + private Cache cache; + private CacheServer cacheServer; + + + public CacheServer getObject() { + return cacheServer; + } + + public Class getObjectType() { + return ((this.cacheServer != null) ? cacheServer.getClass() : CacheServer.class); + } + + public boolean isSingleton() { + return true; + } + + public void afterPropertiesSet() throws IOException { + Assert.notNull(cache, "cache is required"); + + cacheServer = cache.addCacheServer(); + cacheServer.setBindAddress(bindAddress); + cacheServer.setGroups(serverGroups); + cacheServer.setHostnameForClients(hostNameForClients); + cacheServer.setLoadPollInterval(loadPollInterval); + cacheServer.setLoadProbe(serverLoadProbe); + cacheServer.setMaxConnections(maxConnections); + cacheServer.setMaximumMessageCount(maxMessageCount); + cacheServer.setMaximumTimeBetweenPings(maxTimeBetweenPings); + cacheServer.setMaxThreads(maxThreads); + cacheServer.setMessageTimeToLive(messageTimeToLive); + cacheServer.setNotifyBySubscription(notifyBySubscription); + cacheServer.setPort(port); + cacheServer.setSocketBufferSize(socketBufferSize); + + for (InterestRegistrationListener listener : listeners) { + cacheServer.registerInterestRegistrationListener(listener); + } + + // client config + ClientSubscriptionConfig config = cacheServer.getClientSubscriptionConfig(); + config.setCapacity(subscriptionCapacity); + config.setEvictionPolicy(evictionPolicy.name().toLowerCase()); + config.setDiskStoreName(subscriptionDiskStore.getFile().getCanonicalPath()); + + start(); + } + + public void destroy() { + stop(); + cacheServer = null; + } + + public boolean isAutoStartup() { + return autoStartup; + } + + public void stop(Runnable callback) { + stop(); + callback.run(); + } + + public int getPhase() { + // start the latest + return Integer.MAX_VALUE; + } + + public boolean isRunning() { + return (cacheServer != null ? cacheServer.isRunning() : false); + } + + public void start() { + try { + cacheServer.start(); + } catch (IOException ex) { + throw new BeanInitializationException("Cannot start cache server", ex); + } + } + + public void stop() { + if (cacheServer != null) { + cacheServer.stop(); + } + } + + public void setAutoStartup(boolean autoStartup) { + this.autoStartup = autoStartup; + } + + public void setPort(int port) { + this.port = port; + } + + public void setMaxConnections(int maxConnections) { + this.maxConnections = maxConnections; + } + + public void setMaxThreads(int maxThreads) { + this.maxThreads = maxThreads; + } + + public void setNotifyBySubscription(boolean notifyBySubscription) { + this.notifyBySubscription = notifyBySubscription; + } + + public void setSocketBufferSize(int socketBufferSize) { + this.socketBufferSize = socketBufferSize; + } + + public void setMaxTimeBetweenPings(int maxTimeBetweenPings) { + this.maxTimeBetweenPings = maxTimeBetweenPings; + } + + public void setMaxMessageCount(int maxMessageCount) { + this.maxMessageCount = maxMessageCount; + } + + public void setMessageTimeToLive(int messageTimeToLive) { + this.messageTimeToLive = messageTimeToLive; + } + + public void setServerGroups(String[] serverGroups) { + this.serverGroups = serverGroups; + } + + public void setServerLoadProbe(ServerLoadProbe serverLoadProbe) { + this.serverLoadProbe = serverLoadProbe; + } + + public void setLoadPollInterval(long loadPollInterval) { + this.loadPollInterval = loadPollInterval; + } + + public void setBindAddress(String bindAddress) { + this.bindAddress = bindAddress; + } + + public void setHostNameForClients(String hostNameForClients) { + this.hostNameForClients = hostNameForClients; + } + + public void setListeners(Set listeners) { + this.listeners = listeners; + } + + public void setCache(Cache cache) { + this.cache = cache; + } + + /** + * @param evictionPolicy the evictionPolicy to set + */ + public void setSubscriptionEvictionPolicy(SubscriptionEvictionPolicy evictionPolicy) { + this.evictionPolicy = evictionPolicy; + } + + /** + * @param subscriptionCapacity the subscriptionCapacity to set + */ + public void setSubscriptionCapacity(int subscriptionCapacity) { + this.subscriptionCapacity = subscriptionCapacity; + } + + public void setSubscriptionDiskStore(Resource resource) { + this.subscriptionDiskStore = resource; + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicy.java b/src/main/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicy.java new file mode 100644 index 00000000..d7c1efda --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/server/SubscriptionEvictionPolicy.java @@ -0,0 +1,28 @@ +/* + * Copyright 2011 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.server; + +import com.gemstone.gemfire.cache.server.CacheServer; + +/** + * Enumeration of the various client subscription policies for {@link CacheServer}. + * + * @author Costin Leau + */ +public enum SubscriptionEvictionPolicy { + NONE, MEM, ENTRY +} diff --git a/src/main/java/org/springframework/data/gemfire/server/package-info.java b/src/main/java/org/springframework/data/gemfire/server/package-info.java new file mode 100644 index 00000000..457f4f8a --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/server/package-info.java @@ -0,0 +1,5 @@ +/** + * Support package for GemFire {@link com.gemstone.gemfire.cache.server.CacheServer}. + * + */ +package org.springframework.data.gemfire.server; \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java b/src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java new file mode 100644 index 00000000..97a652d3 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/support/GemfireDaoSupport.java @@ -0,0 +1,85 @@ +/* + * Copyright 2011 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.support; + +import org.springframework.dao.support.DaoSupport; +import org.springframework.data.gemfire.GemfireTemplate; +import org.springframework.util.Assert; + +import com.gemstone.gemfire.cache.Region; + +/** + * Convenient super class for GemFire data access objects. Intended for + * GemfireTemplate usage. + * + *

Requires a Region to be set, providing a GemfireTemplate based on it to subclasses. + * Can alternatively be initialized directly via a GemfireTemplate, to reuse the latter's + * settings. + * + *

This class will create its own GemfireTemplate if an Region reference is passed in. + * A custom GemfireTemplate instance can be used through overriding createGemfireTemplate. + * + * @author Costin Leau + */ +public class GemfireDaoSupport extends DaoSupport { + + private GemfireTemplate gemfireTemplate; + + /** + * Sets the GemFire Region to be used by this DAO. + * Will automatically create a GemfireTemplate for the given Region. + * + * @param region + */ + public void setRegion(Region region) { + this.gemfireTemplate = createGemfireTemplate(region); + } + + /** + * Creates a GemfireTemplate for the given Region. + *

Can be overridden in subclasses to provide a GemfireTemplate instance + * with different configuration, or a custom GemfireTemplate subclass. + * @param region the GemFire Region to create a GemfireTemplate for + * @return the new GemfireTemplate instance + * @see #setRegion + */ + protected GemfireTemplate createGemfireTemplate(Region region) { + return new GemfireTemplate(region); + } + + /** + * Set the GemfireTemplate for this DAO explicitly, + * as an alternative to specifying a GemFire {@link Region}. + * @see #setRegion + */ + public final void setGemfireTemplate(GemfireTemplate gemfireTemplate) { + this.gemfireTemplate = gemfireTemplate; + } + + /** + * Return the GemfireTemplate for this DAO, pre-initialized + * with the Region or set explicitly. + */ + public final GemfireTemplate getGemfireTemplate() { + return gemfireTemplate; + } + + @Override + protected final void checkDaoConfig() { + Assert.notNull(gemfireTemplate, "region or gemfireTemplate is required"); + } +} \ 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 25b420e3..2bb1ca58 100644 --- a/src/main/resources/META-INF/spring.schemas +++ b/src/main/resources/META-INF/spring.schemas @@ -1,2 +1,3 @@ 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.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd \ No newline at end of file +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.xsd=org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd \ No newline at end of file diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd index 9a92af95..2a69a302 100644 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.0.xsd @@ -6,7 +6,7 @@ targetNamespace="http://www.springframework.org/schema/gemfire" elementFormDefault="qualified" attributeFormDefault="unqualified" - version="1.0"> + version="1.0.1"> @@ -74,7 +74,7 @@ The name of the bean defining the GemFire cache (by default 'gemfire-cache'). ]]> - + - + - + - + + + + + + @@ -396,7 +404,7 @@ The name of the partitioned region with which this newly created partitioned reg ]]> - + - + - + - + - + - + - + - + - + --> - + - + - + - + - - - - - - - - + + + + + + + + - - - - - - - + + + + + + + diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd new file mode 100644 index 00000000..184e391d --- /dev/null +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-gemfire-1.1.xsd @@ -0,0 +1,906 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + namespace and its 'properties' element. + ]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java b/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java new file mode 100644 index 00000000..1148c3d0 --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/config/CacheServerNamespaceTest.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011 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.assertTrue; + +import org.junit.Test; +import org.springframework.data.gemfire.RecreatingContextTest; + +import com.gemstone.gemfire.cache.server.CacheServer; + +/** + * + * @author Costin Leau + */ +public class CacheServerNamespaceTest extends RecreatingContextTest { + + @Override + protected String location() { + return "org/springframework/data/gemfire/config/server-ns.xml"; + } + + @Test + public void testBasicCacheServer() throws Exception { + CacheServer cacheServer = ctx.getBean("advanced-config", CacheServer.class); + assertTrue(cacheServer.isRunning()); + assertEquals(1, cacheServer.getGroups().length); + assertEquals("test-server", cacheServer.getGroups()[0]); + assertEquals(22, cacheServer.getMaxConnections()); + + } +} 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 3b95a617..15b6624b 100644 --- a/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java +++ b/src/test/java/org/springframework/data/gemfire/config/PartitionedRegionNamespaceTest.java @@ -61,6 +61,8 @@ public class PartitionedRegionNamespaceTest { assertEquals("redundant", TestUtils.readField("name", fb)); RegionAttributes attrs = TestUtils.readField("attributes", fb); + assertTrue(attrs.getStatisticsEnabled()); + PartitionAttributes pAttr = attrs.getPartitionAttributes(); assertEquals(1, pAttr.getRedundantCopies()); diff --git a/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java b/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java new file mode 100644 index 00000000..5b369dda --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/support/GemfireDaoSupportTests.java @@ -0,0 +1,56 @@ +/* + * Copyright 2011 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.support; + +import java.util.ArrayList; +import java.util.List; + +import junit.framework.TestCase; + +import org.springframework.data.gemfire.GemfireTemplate; + +/** + * @author Costin Leau + * + */ +public class GemfireDaoSupportTests extends TestCase { + + public void testGemfireDaoSupportWithTemplate() throws Exception { + GemfireTemplate template = new GemfireTemplate(); + final List test = new ArrayList(); + GemfireDaoSupport dao = new GemfireDaoSupport() { + protected void initDao() { + test.add("test"); + } + }; + dao.setGemfireTemplate(template); + dao.afterPropertiesSet(); + assertNotNull("template not created", dao.getGemfireTemplate()); + assertEquals("incorrect template", template, dao.getGemfireTemplate()); + assertEquals("initDao not called", test.size(), 1); + } + + public void testInvalidDaoTemplate() throws Exception { + GemfireDaoSupport dao = new GemfireDaoSupport() { + }; + try { + dao.afterPropertiesSet(); + fail("expected exception"); + } catch (IllegalArgumentException iae) { + // okay + } + } +} \ No newline at end of file diff --git a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml index 67a251f4..c2a2a803 100644 --- a/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml +++ b/src/test/resources/org/springframework/data/gemfire/config/partitioned-ns.xml @@ -12,7 +12,7 @@ - + diff --git a/src/test/resources/org/springframework/data/gemfire/config/server-ns.xml b/src/test/resources/org/springframework/data/gemfire/config/server-ns.xml new file mode 100644 index 00000000..a03427d6 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/config/server-ns.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/resources/port.properties b/src/test/resources/port.properties index 66e8f405..00ec631d 100644 --- a/src/test/resources/port.properties +++ b/src/test/resources/port.properties @@ -1,2 +1,3 @@ gfe.port=40403 -gfe.port.4=40404 \ No newline at end of file +gfe.port.4=40404 +gfe.port.6=40406 \ No newline at end of file