From 418715a7397da9198490a95e3723859c2df30c79 Mon Sep 17 00:00:00 2001 From: David Turanski Date: Tue, 22 Jan 2013 08:32:02 -0500 Subject: [PATCH] added support for gfe-data:datasource --- .../client/AbstractGemfireDataSource.java | 180 ++++++++++++++++++ .../gemfire/client/GemfireDataSource.java | 55 ++++++ .../GemfireDataSourcePostProcessor.java | 67 +++++++ .../client/GemfireLocatorDataSource.java | 48 +++++ .../client/GemfireServerDataSource.java | 46 +++++ .../config/GemfireDataNamespaceHandler.java | 1 + .../config/GemfireDataSourceParser.java | 66 +++++++ .../support/ListRegionsOnServerFunction.java | 78 ++++++++ .../support/ListRegionsOnServerFunction.java | 77 ++++++++ .../config/spring-data-gemfire-1.3.xsd | 56 +++++- .../gemfire/client/GemFireDataSourceTest.java | 69 +++++++ .../data/gemfire/client/datasource-client.xml | 12 ++ .../data/gemfire/client/datasource-server.xml | 12 ++ 13 files changed, 766 insertions(+), 1 deletion(-) create mode 100644 src/main/java/org/springframework/data/gemfire/client/AbstractGemfireDataSource.java create mode 100644 src/main/java/org/springframework/data/gemfire/client/GemfireDataSource.java create mode 100644 src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java create mode 100644 src/main/java/org/springframework/data/gemfire/client/GemfireLocatorDataSource.java create mode 100644 src/main/java/org/springframework/data/gemfire/client/GemfireServerDataSource.java create mode 100644 src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java create mode 100644 src/main/java/org/springframework/data/gemfire/repository/support/ListRegionsOnServerFunction.java create mode 100644 src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java create mode 100644 src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceTest.java create mode 100644 src/test/resources/org/springframework/data/gemfire/client/datasource-client.xml create mode 100644 src/test/resources/org/springframework/data/gemfire/client/datasource-server.xml diff --git a/src/main/java/org/springframework/data/gemfire/client/AbstractGemfireDataSource.java b/src/main/java/org/springframework/data/gemfire/client/AbstractGemfireDataSource.java new file mode 100644 index 00000000..b1ff6fc7 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/client/AbstractGemfireDataSource.java @@ -0,0 +1,180 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import java.net.InetSocketAddress; +import java.util.List; +import java.util.Properties; +import java.util.Set; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.data.gemfire.function.execution.GemfireFunctionOperations; +import org.springframework.data.gemfire.function.execution.GemfireOnServersFunctionTemplate; +import org.springframework.data.gemfire.repository.support.ListRegionsOnServerFunction; + +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientCacheFactory; +import com.gemstone.gemfire.cache.client.ClientRegionFactory; +import com.gemstone.gemfire.cache.client.ClientRegionShortcut; +import com.gemstone.gemfire.cache.client.Pool; +import com.gemstone.gemfire.cache.query.QueryService; +import com.gemstone.gemfire.distributed.DistributedSystem; + +/** + * @author David Turanski + * + */ +public abstract class AbstractGemfireDataSource { + protected Log logger = LogFactory.getLog(getClass()); + protected ClientCache cache; + + public AbstractGemfireDataSource(ClientCacheFactory clientCacheFactory) { + this.cache = clientCacheFactory.create(); + } + + public AbstractGemfireDataSource(String host, int port, Properties properties) { + ClientCacheFactory clientCacheFactory = new ClientCacheFactory(); + addRemoteConnection(clientCacheFactory, host, port); + initializeClientCache(clientCacheFactory,properties); + this.cache = clientCacheFactory.create(); + createClientRegions(); + } + + public AbstractGemfireDataSource(List remoteConnections, Properties properties) { + + ClientCacheFactory clientCacheFactory = new ClientCacheFactory(); + for (InetSocketAddress remoteConnection: remoteConnections) { + addRemoteConnection(clientCacheFactory, remoteConnection.getHostName(), remoteConnection.getPort()); + } + initializeClientCache(clientCacheFactory,properties); + this.cache = clientCacheFactory.create(); + createClientRegions(); + } + + protected abstract void addRemoteConnection(ClientCacheFactory clientCacheFactory, String host, int port); + + public void connect() { + this.connect(); + } + + public String getName() { + return cache.getName(); + } + + public String getServerGroup() { + return cache.getDefaultPool().getServerGroup(); + } + + + public List getLocators() { + return cache.getDefaultPool().getLocators(); + } + + + public List getServers() { + return cache.getDefaultPool().getServers(); + } + + + + public QueryService getQueryService() { + return cache.getQueryService(); + } + + + public QueryService getQueryService(String poolName) { + return cache.getQueryService(poolName); + } + + + public QueryService getLocalQueryService() { + return cache.getLocalQueryService(); + } + + + public void close(boolean keepalive) { + cache.close(keepalive); + } + + public void readyForEvents() { + cache.readyForEvents(); + + } + + public Set getCurrentServers() { + return cache.getCurrentServers(); + } + + + public Pool getDefaultPool() { + return cache.getDefaultPool(); + } + + public DistributedSystem getDistributedSystem() { + return cache.getDistributedSystem(); + } + + + + public Region getRegion(String path) { + return cache.getRegion(path); + } + + + public Set> rootRegions() { + return cache.rootRegions(); + } + + + public void close() { + cache.close(); + } + + + public boolean isClosed() { + return cache.isClosed(); + } + + /** + * + */ + private void createClientRegions() { + GemfireFunctionOperations template = new GemfireOnServersFunctionTemplate(cache); + Iterable regionNames = template.executeAndExtract(new ListRegionsOnServerFunction()); + + ClientRegionFactory clientRegionFactory = null; + if (regionNames !=null && regionNames.iterator().hasNext()) { + clientRegionFactory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY); + } + + for (String regionName: regionNames) { + if (logger.isDebugEnabled()) { + logger.debug("creating client region for " + regionName); + clientRegionFactory.create(regionName); + } + } + + } + + /** + * @param clientCacheFactory + * @param properties + */ + private void initializeClientCache(ClientCacheFactory clientCacheFactory, Properties properties) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSource.java b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSource.java new file mode 100644 index 00000000..495217c0 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSource.java @@ -0,0 +1,55 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import java.util.Set; + +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.client.Pool; +import com.gemstone.gemfire.cache.query.QueryService; +import com.gemstone.gemfire.distributed.DistributedSystem; + +/** + * @author David Turanski + * + */ +public interface GemfireDataSource { + + public void connect(); + + public String getName(); + + public String getServerGroup(); + + public QueryService getQueryService(); + + public QueryService getQueryService(String poolName); + + public QueryService getLocalQueryService(); + + public void readyForEvents(); + + public Pool getDefaultPool(); + + public DistributedSystem getDistributedSystem(); + + public Region getRegion(String path); + + public Set> rootRegions(); + + public void close(); + + public void close(boolean keepalive); + + public boolean isClosed(); +} diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java new file mode 100644 index 00000000..a669c43d --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/client/GemfireDataSourcePostProcessor.java @@ -0,0 +1,67 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanFactoryPostProcessor; +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; +import org.springframework.data.gemfire.function.execution.GemfireFunctionOperations; +import org.springframework.data.gemfire.function.execution.GemfireOnServersFunctionTemplate; +import org.springframework.data.gemfire.repository.support.ListRegionsOnServerFunction; + +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.ClientRegionFactory; +import com.gemstone.gemfire.cache.client.ClientRegionShortcut; + +/** + * @author David Turanski + * + */ +public class GemfireDataSourcePostProcessor implements BeanFactoryPostProcessor { + private static Log logger = LogFactory.getLog(GemfireDataSourcePostProcessor.class); + private final ClientCache cache; + + public GemfireDataSourcePostProcessor(ClientCache cache) { + this.cache = cache; + } + /* (non-Javadoc) + * @see org.springframework.beans.factory.config.BeanFactoryPostProcessor#postProcessBeanFactory(org.springframework.beans.factory.config.ConfigurableListableBeanFactory) + */ + @Override + public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException { + createClientRegions(beanFactory); + + } + + private void createClientRegions(ConfigurableListableBeanFactory beanFactory) { + GemfireFunctionOperations template = new GemfireOnServersFunctionTemplate(cache); + Iterable regionNames = template.executeAndExtract(new ListRegionsOnServerFunction()); + + ClientRegionFactory clientRegionFactory = null; + if (regionNames !=null && regionNames.iterator().hasNext()) { + clientRegionFactory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY); + } + + for (String regionName: regionNames) { + if (logger.isDebugEnabled()) { + logger.debug("creating client region for " + regionName); + beanFactory.registerSingleton(regionName, + clientRegionFactory.create(regionName)); + } + } + + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireLocatorDataSource.java b/src/main/java/org/springframework/data/gemfire/client/GemfireLocatorDataSource.java new file mode 100644 index 00000000..3a235c3b --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/client/GemfireLocatorDataSource.java @@ -0,0 +1,48 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import java.net.InetSocketAddress; +import java.util.List; +import java.util.Properties; + +import com.gemstone.gemfire.cache.client.ClientCacheFactory; + +/** + * @author David Turanski + * + */ +public class GemfireLocatorDataSource extends AbstractGemfireDataSource { + + public GemfireLocatorDataSource(ClientCacheFactory clientCacheFactory) { + super(clientCacheFactory); + } + + public GemfireLocatorDataSource(String host, int port, Properties properties) { + super(host, port, properties); + } + + public GemfireLocatorDataSource(List remoteConnections, Properties properties) { + super(remoteConnections, properties); + } + + /* (non-Javadoc) + * @see org.springframework.data.gemfire.client.AbstractGemfireDataSource#addRemoteConnection(com.gemstone.gemfire.cache.client.ClientCacheFactory, java.lang.String, int) + */ + @Override + protected void addRemoteConnection(ClientCacheFactory clientCacheFactory, String host, int port) { + clientCacheFactory.addPoolLocator(host, port); + } + + +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/client/GemfireServerDataSource.java b/src/main/java/org/springframework/data/gemfire/client/GemfireServerDataSource.java new file mode 100644 index 00000000..7ad783c9 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/client/GemfireServerDataSource.java @@ -0,0 +1,46 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import java.net.InetSocketAddress; +import java.util.List; +import java.util.Properties; + +import com.gemstone.gemfire.cache.client.ClientCacheFactory; + +/** + * @author David Turanski + * + */ +public class GemfireServerDataSource extends AbstractGemfireDataSource { + + public GemfireServerDataSource(ClientCacheFactory clientCacheFactory) { + super(clientCacheFactory); + } + + public GemfireServerDataSource(String host, int port, Properties properties) { + super(host, port, properties); + } + + public GemfireServerDataSource(List remoteConnections, Properties properties) { + super(remoteConnections, properties); + } + + /* (non-Javadoc) + * @see org.springframework.data.gemfire.client.AbstractGemfireDataSource#addRemoteConnection(com.gemstone.gemfire.cache.client.ClientCacheFactory, java.lang.String, int) + */ + @Override + protected void addRemoteConnection(ClientCacheFactory clientCacheFactory, String host, int port) { + clientCacheFactory.addPoolServer(host, port); + } +} \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java b/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java index cd1048d4..78daac6e 100644 --- a/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireDataNamespaceHandler.java @@ -37,5 +37,6 @@ class GemfireDataNamespaceHandler extends NamespaceHandlerSupport { RepositoryConfigurationExtension extension = new GemfireRepositoryConfigurationExtension(); registerBeanDefinitionParser("repositories", new RepositoryBeanDefinitionParser(extension)); registerBeanDefinitionParser("function-executions", new FunctionExecutionBeanDefinitionParser()); + registerBeanDefinitionParser("datasource", new GemfireDataSourceParser()); } } \ No newline at end of file diff --git a/src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java b/src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java new file mode 100644 index 00000000..3e247b5a --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/config/GemfireDataSourceParser.java @@ -0,0 +1,66 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.config; + +import javax.management.Attribute; + +import org.springframework.beans.MutablePropertyValues; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.AbstractBeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionReaderUtils; +import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; +import org.springframework.beans.factory.xml.ParserContext; +import org.springframework.data.gemfire.client.GemfireDataSourcePostProcessor; +import org.springframework.util.Assert; +import org.w3c.dom.Attr; +import org.w3c.dom.Element; + +/** + * @author David Turanski + * + */ +public class GemfireDataSourceParser extends AbstractBeanDefinitionParser { + + /* (non-Javadoc) + * @see org.springframework.beans.factory.xml.AbstractBeanDefinitionParser#parseInternal(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext) + */ + @Override + protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { + + AbstractBeanDefinition poolDefinition = (AbstractBeanDefinition) new PoolParser().parse(element, parserContext); + MutablePropertyValues poolProps = poolDefinition.getPropertyValues(); + + poolProps.add("name", GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME); + + parserContext.getRegistry().registerBeanDefinition(GemfireConstants.DEFAULT_GEMFIRE_POOL_NAME,poolDefinition); + + AbstractBeanDefinition clientCacheDefinition = (AbstractBeanDefinition)new ClientCacheParser().parse(element, parserContext); + + MutablePropertyValues props = clientCacheDefinition.getPropertyValues(); + + props.add("pool", poolDefinition); + + clientCacheDefinition.setPropertyValues(props); + + parserContext.getRegistry().registerBeanDefinition(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME,clientCacheDefinition); + + System.out.println("registered " + GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME+ ":" + clientCacheDefinition.getBeanClassName()); + + BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GemfireDataSourcePostProcessor.class); + builder.addConstructorArgReference(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME); + BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), parserContext.getRegistry()); + return null; + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/repository/support/ListRegionsOnServerFunction.java b/src/main/java/org/springframework/data/gemfire/repository/support/ListRegionsOnServerFunction.java new file mode 100644 index 00000000..86cbbcdd --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/repository/support/ListRegionsOnServerFunction.java @@ -0,0 +1,78 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.repository.support; + +import java.util.ArrayList; +import java.util.List; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.execute.Function; +import com.gemstone.gemfire.cache.execute.FunctionContext; + +/** + * @author David Turanski + * + */ +@SuppressWarnings("serial") +public class ListRegionsOnServerFunction implements Function { + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#hasResult() + */ + @Override + public boolean hasResult() { + return true; + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#execute(com.gemstone.gemfire.cache.execute.FunctionContext) + */ + @Override + public void execute(FunctionContext context) { + Cache cache = CacheFactory.getAnyInstance(); + List regionNames = new ArrayList(); + for (Region region: cache.rootRegions()) { + regionNames.add(region.getName()); + } + context.getResultSender().lastResult(regionNames); + } + + + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#getId() + */ + @Override + public String getId() { + return this.getClass().getName(); + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#optimizeForWrite() + */ + @Override + public boolean optimizeForWrite() { + return false; + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#isHA() + */ + @Override + public boolean isHA() { + return false; + } + +} diff --git a/src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java b/src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java new file mode 100644 index 00000000..b447f6c8 --- /dev/null +++ b/src/main/java/org/springframework/data/gemfire/support/ListRegionsOnServerFunction.java @@ -0,0 +1,77 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.support; + +import java.util.ArrayList; +import java.util.List; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.CacheFactory; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.execute.Function; +import com.gemstone.gemfire.cache.execute.FunctionContext; + +/** + * @author David Turanski + * + */ +@SuppressWarnings("serial") +public class ListRegionsOnServerFunction implements Function { + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#execute(com.gemstone.gemfire.cache.execute.FunctionContext) + */ + @Override + public void execute(FunctionContext functionContext) { + Cache cache = CacheFactory.getAnyInstance(); + List regionNames = new ArrayList(); + for (Region region: cache.rootRegions()) { + regionNames.add(region.getName()); + } + + functionContext.getResultSender().lastResult(regionNames); + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#getId() + */ + @Override + public String getId() { + return this.getClass().getName(); + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#hasResult() + */ + @Override + public boolean hasResult() { + return true; + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#isHA() + */ + @Override + public boolean isHA() { + return false; + } + + /* (non-Javadoc) + * @see com.gemstone.gemfire.cache.execute.Function#optimizeForWrite() + */ + @Override + public boolean optimizeForWrite() { + return false; + } + +} diff --git a/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.3.xsd b/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.3.xsd index 51a2b7ae..c8568411 100644 --- a/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.3.xsd +++ b/src/main/resources/org/springframework/data/gemfire/config/spring-data-gemfire-1.3.xsd @@ -3,6 +3,7 @@ xmlns:tool="http://www.springframework.org/schema/tool" xmlns:repository="http://www.springframework.org/schema/data/repository" xmlns:context="http://www.springframework.org/schema/context" +xmlns:gfe="http://www.springframework.org/schema/gemfire" targetNamespace="http://www.springframework.org/schema/data/gemfire" elementFormDefault="qualified" attributeFormDefault="unqualified" version="1.3"> @@ -85,5 +86,58 @@ targetNamespace="http://www.springframework.org/schema/data/gemfire" elementForm - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceTest.java b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceTest.java new file mode 100644 index 00000000..8415ab9e --- /dev/null +++ b/src/test/java/org/springframework/data/gemfire/client/GemFireDataSourceTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. + */ +package org.springframework.data.gemfire.client; + +import static org.junit.Assert.*; + +import java.util.Arrays; +import java.util.List; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; +import org.springframework.data.gemfire.ForkUtil; +import org.springframework.data.gemfire.fork.SpringCacheServerProcess; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.gemstone.gemfire.cache.Cache; +import com.gemstone.gemfire.cache.Region; +import com.gemstone.gemfire.cache.client.ClientCache; +import com.gemstone.gemfire.cache.client.Pool; + +/** + * @author David Turanski + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration("/org/springframework/data/gemfire/client/datasource-client.xml") +public class GemFireDataSourceTest { + @Autowired + ApplicationContext ctx; + + @BeforeClass + public static void startUp() throws Exception { + ForkUtil.startCacheServer(SpringCacheServerProcess.class.getName() + " " + + "/org/springframework/data/gemfire/client/datasource-server.xml"); + } + + @SuppressWarnings("unused") + @Test + public void testServerDataSource() { + Cache cache = ctx.getBean("gemfireCache",Cache.class); + Pool pool = ctx.getBean("gemfirePool",Pool.class); + PoolFactoryBean pfb = ctx.getBean("&gemfirePool",PoolFactoryBean.class); + Region r1 = ctx.getBean("r1",Region.class); + r1.put("hello","world"); + assertEquals("world",r1.get("hello")); + + } + + @AfterClass + public static void cleanUp() { + ForkUtil.sendSignal(); + } + +} diff --git a/src/test/resources/org/springframework/data/gemfire/client/datasource-client.xml b/src/test/resources/org/springframework/data/gemfire/client/datasource-client.xml new file mode 100644 index 00000000..ffe8d874 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/client/datasource-client.xml @@ -0,0 +1,12 @@ + + + + + + + diff --git a/src/test/resources/org/springframework/data/gemfire/client/datasource-server.xml b/src/test/resources/org/springframework/data/gemfire/client/datasource-server.xml new file mode 100644 index 00000000..415bf4a5 --- /dev/null +++ b/src/test/resources/org/springframework/data/gemfire/client/datasource-server.xml @@ -0,0 +1,12 @@ + + + + + + + +