added support for gfe-data:datasource
This commit is contained in:
@@ -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<InetSocketAddress> 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<InetSocketAddress> getLocators() {
|
||||
return cache.getDefaultPool().getLocators();
|
||||
}
|
||||
|
||||
|
||||
public List<InetSocketAddress> 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<InetSocketAddress> getCurrentServers() {
|
||||
return cache.getCurrentServers();
|
||||
}
|
||||
|
||||
|
||||
public Pool getDefaultPool() {
|
||||
return cache.getDefaultPool();
|
||||
}
|
||||
|
||||
public DistributedSystem getDistributedSystem() {
|
||||
return cache.getDistributedSystem();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public <K, V> Region<K, V> getRegion(String path) {
|
||||
return cache.getRegion(path);
|
||||
}
|
||||
|
||||
|
||||
public Set<Region<?, ?>> rootRegions() {
|
||||
return cache.rootRegions();
|
||||
}
|
||||
|
||||
|
||||
public void close() {
|
||||
cache.close();
|
||||
}
|
||||
|
||||
|
||||
public boolean isClosed() {
|
||||
return cache.isClosed();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void createClientRegions() {
|
||||
GemfireFunctionOperations template = new GemfireOnServersFunctionTemplate(cache);
|
||||
Iterable<String> 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 <K, V> Region<K, V> getRegion(String path);
|
||||
|
||||
public Set<Region<?, ?>> rootRegions();
|
||||
|
||||
public void close();
|
||||
|
||||
public void close(boolean keepalive);
|
||||
|
||||
public boolean isClosed();
|
||||
}
|
||||
@@ -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<String> 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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<InetSocketAddress> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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<InetSocketAddress> 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);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> regionNames = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<String> regionNames = new ArrayList<String>();
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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">
|
||||
<xsd:import namespace="http://www.springframework.org/schema/beans"/>
|
||||
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
|
||||
@@ -85,5 +86,58 @@ targetNamespace="http://www.springframework.org/schema/data/gemfire" elementForm
|
||||
</xsd:annotation>
|
||||
<xsd:union memberTypes="xsd:string"/>
|
||||
</xsd:simpleType>
|
||||
<!-- -->
|
||||
<!-- DataSource -->
|
||||
|
||||
<xsd:element name="datasource">
|
||||
<xsd:annotation>
|
||||
<xsd:documentation><![CDATA[
|
||||
Defines a connection from a Cache client to a set of GemFire Cache Servers.
|
||||
]]></xsd:documentation>
|
||||
</xsd:annotation>
|
||||
<xsd:complexType>
|
||||
<xsd:choice minOccurs="1" maxOccurs="1">
|
||||
<xsd:element name="locator" type="gfe:connectionType"
|
||||
minOccurs="1" maxOccurs="unbounded" />
|
||||
<xsd:element name="server" type="gfe:connectionType"
|
||||
minOccurs="1" maxOccurs="unbounded" />
|
||||
</xsd:choice>
|
||||
|
||||
<xsd:attribute name="free-connection-timeout"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="idle-timeout" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="load-conditioning-interval"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="max-connections" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="min-connections" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="multi-user-authentication"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="ping-interval" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="pr-single-hop-enabled"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="read-timeout" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="retry-attempts" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="server-group" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="socket-buffer-size" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="statistic-interval" type="xsd:string"
|
||||
use="optional" />
|
||||
<xsd:attribute name="subscription-ack-interval"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="subscription-enabled"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="subscription-message-tracking-timeout"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="subscription-redundancy"
|
||||
type="xsd:string" use="optional" />
|
||||
<xsd:attribute name="thread-local-connections"
|
||||
type="xsd:string" use="optional" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
|
||||
@@ -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<Object,Object> r1 = ctx.getBean("r1",Region.class);
|
||||
r1.put("hello","world");
|
||||
assertEquals("world",r1.get("hello"));
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanUp() {
|
||||
ForkUtil.sendSignal();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
default-lazy-init="true"
|
||||
xmlns:gfe-data="http://www.springframework.org/schema/data/gemfire"
|
||||
xsi:schemaLocation="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-1.3.xsd">
|
||||
|
||||
<gfe-data:datasource >
|
||||
<gfe-data:server host="localhost" port="40404"/>
|
||||
</gfe-data:datasource>
|
||||
</beans>
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:gfe="http://www.springframework.org/schema/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" default-lazy-init="true">
|
||||
|
||||
<gfe:cache/>
|
||||
<gfe:cache-server/>
|
||||
<gfe:replicated-region id="r1"/>
|
||||
<gfe:replicated-region id="r2"/>
|
||||
</beans>
|
||||
Reference in New Issue
Block a user