Skip to content

Commit 94af046

Browse files
committed
Add starter and sample for Apache Geode.
Closes gh-5438.
1 parent cb2ad7f commit 94af046

File tree

12 files changed

+567
-0
lines changed

12 files changed

+567
-0
lines changed

spring-boot-dependencies/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<spring-amqp.version>1.6.0.M1</spring-amqp.version>
136136
<spring-cloud-connectors.version>1.2.1.RELEASE</spring-cloud-connectors.version>
137137
<spring-batch.version>3.0.6.RELEASE</spring-batch.version>
138+
<spring-data-geode.version>1.7.0.APACHE-GEODE-EA-M1</spring-data-geode.version>
138139
<spring-data-releasetrain.version>Hopper-RC1</spring-data-releasetrain.version>
139140
<spring-hateoas.version>0.19.0.RELEASE</spring-hateoas.version>
140141
<spring-integration.version>4.3.0.M1</spring-integration.version>
@@ -147,6 +148,7 @@
147148
<spring-security-jwt.version>1.0.3.RELEASE</spring-security-jwt.version>
148149
<spring-security-oauth.version>2.0.9.RELEASE</spring-security-oauth.version>
149150
<spring-session.version>1.1.0.RELEASE</spring-session.version>
151+
<spring-shell.version>1.1.0.RELEASE</spring-shell.version>
150152
<spring-social.version>1.1.4.RELEASE</spring-social.version>
151153
<spring-social-facebook.version>2.0.3.RELEASE</spring-social-facebook.version>
152154
<spring-social-linkedin.version>1.0.2.RELEASE</spring-social-linkedin.version>
@@ -303,6 +305,11 @@
303305
<artifactId>spring-boot-starter-data-gemfire</artifactId>
304306
<version>1.4.0.BUILD-SNAPSHOT</version>
305307
</dependency>
308+
<dependency>
309+
<groupId>org.springframework.boot</groupId>
310+
<artifactId>spring-boot-starter-data-geode</artifactId>
311+
<version>1.4.0.BUILD-SNAPSHOT</version>
312+
</dependency>
306313
<dependency>
307314
<groupId>org.springframework.boot</groupId>
308315
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -1994,6 +2001,11 @@
19942001
<artifactId>spring-session-data-redis</artifactId>
19952002
<version>${spring-session.version}</version>
19962003
</dependency>
2004+
<dependency>
2005+
<groupId>org.springframework.shell</groupId>
2006+
<artifactId>spring-shell</artifactId>
2007+
<version>${spring-shell.version}</version>
2008+
</dependency>
19972009
<dependency>
19982010
<groupId>org.springframework.social</groupId>
19992011
<artifactId>spring-social-config</artifactId>

spring-boot-samples/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
<module>spring-boot-sample-data-couchbase</module>
3737
<module>spring-boot-sample-data-elasticsearch</module>
3838
<module>spring-boot-sample-data-gemfire</module>
39+
<module>spring-boot-sample-data-geode</module>
3940
<module>spring-boot-sample-data-jpa</module>
4041
<module>spring-boot-sample-data-mongodb</module>
4142
<module>spring-boot-sample-data-redis</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
apachegeode-maven-dependency-exclusions.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<parent>
5+
<!-- Your own application should inherit from spring-boot-starter-parent -->
6+
<groupId>org.springframework.boot</groupId>
7+
<artifactId>spring-boot-samples</artifactId>
8+
<version>1.4.0.BUILD-SNAPSHOT</version>
9+
</parent>
10+
<artifactId>spring-boot-sample-data-geode</artifactId>
11+
<name>Spring Boot Data Geode Sample</name>
12+
<description>Spring Boot Data Geode Sample</description>
13+
<url>http://projects.spring.io/spring-boot/</url>
14+
<organization>
15+
<name>Pivotal Software, Inc.</name>
16+
<url>http://www.spring.io</url>
17+
</organization>
18+
<properties>
19+
<main.basedir>${basedir}/../..</main.basedir>
20+
</properties>
21+
<dependencies>
22+
<dependency>
23+
<groupId>org.springframework.boot</groupId>
24+
<artifactId>spring-boot-starter</artifactId>
25+
</dependency>
26+
<dependency>
27+
<groupId>org.springframework.boot</groupId>
28+
<artifactId>spring-boot-starter-data-geode</artifactId>
29+
</dependency>
30+
<dependency>
31+
<groupId>org.springframework.boot</groupId>
32+
<artifactId>spring-boot-starter-test</artifactId>
33+
<scope>test</scope>
34+
</dependency>
35+
<dependency>
36+
<groupId>org.springframework.shell</groupId>
37+
<artifactId>spring-shell</artifactId>
38+
<scope>runtime</scope>
39+
</dependency>
40+
</dependencies>
41+
<build>
42+
<plugins>
43+
<plugin>
44+
<groupId>org.springframework.boot</groupId>
45+
<artifactId>spring-boot-maven-plugin</artifactId>
46+
</plugin>
47+
</plugins>
48+
</build>
49+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.data.geode;
18+
19+
import java.util.Properties;
20+
21+
import org.springframework.beans.factory.annotation.Autowired;
22+
import org.springframework.beans.factory.annotation.Qualifier;
23+
import org.springframework.boot.SpringApplication;
24+
import org.springframework.boot.autoconfigure.SpringBootApplication;
25+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
26+
import org.springframework.context.ApplicationContext;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.data.gemfire.CacheFactoryBean;
29+
import org.springframework.data.gemfire.GemfireTemplate;
30+
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
31+
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
32+
33+
import com.gemstone.gemfire.cache.Cache;
34+
import com.gemstone.gemfire.cache.CacheLoader;
35+
import com.gemstone.gemfire.cache.CacheLoaderException;
36+
import com.gemstone.gemfire.cache.LoaderHelper;
37+
import com.gemstone.gemfire.cache.RegionAttributes;
38+
39+
import sample.data.geode.config.SampleDataGeodeApplicationProperties;
40+
import sample.data.geode.service.Calculator;
41+
import sample.data.geode.service.factory.CalculatorFactory;
42+
43+
/**
44+
* SampleDataGeodeApplication class is a Spring Boot, Apache Geode peer cache application using Geode
45+
* to perform and store mathematical calculations.
46+
*
47+
* @author John Blum
48+
* @see org.springframework.boot.SpringApplication
49+
* @see org.springframework.boot.autoconfigure.SpringBootApplication
50+
* @see org.springframework.boot.context.properties.ConfigurationProperties
51+
* @see org.springframework.context.ApplicationContext
52+
* @see org.springframework.context.annotation.Bean
53+
* @see org.springframework.data.gemfire.CacheFactoryBean
54+
* @see org.springframework.data.gemfire.GemfireTemplate
55+
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
56+
* @see com.gemstone.gemfire.cache.Cache
57+
* @see com.gemstone.gemfire.cache.CacheLoader
58+
* @see sample.data.geode.service.Calculator
59+
* @see sample.data.geode.service.factory.CalculatorFactory
60+
* @since 1.4.0
61+
*/
62+
@SpringBootApplication
63+
@EnableConfigurationProperties(SampleDataGeodeApplicationProperties.class)
64+
@SuppressWarnings("unused")
65+
public class SampleDataGeodeApplication {
66+
67+
protected static final String CALCULATIONS_REGION_NAME = "Calculations";
68+
69+
public static void main(final String[] args) {
70+
SpringApplication.run(SampleDataGeodeApplication.class, args);
71+
}
72+
73+
@Autowired
74+
SampleDataGeodeApplicationProperties applicationProperties;
75+
76+
@Bean
77+
Properties gemfireProperties() {
78+
Properties gemfireProperties = new Properties();
79+
80+
gemfireProperties.setProperty("name", SampleDataGeodeApplication.class.getSimpleName());
81+
gemfireProperties.setProperty("mcast-port", "0");
82+
gemfireProperties.setProperty("locators", "");
83+
gemfireProperties.setProperty("log-level", applicationProperties.getLogLevel());
84+
85+
return gemfireProperties;
86+
}
87+
88+
@Bean
89+
CacheFactoryBean gemfireCache() {
90+
CacheFactoryBean gemfireCache = new CacheFactoryBean();
91+
92+
gemfireCache.setClose(true);
93+
gemfireCache.setProperties(gemfireProperties());
94+
95+
return gemfireCache;
96+
}
97+
98+
@Bean(name = CALCULATIONS_REGION_NAME)
99+
PartitionedRegionFactoryBean<Long, Long> calculationsRegion(Cache gemfireCache,
100+
RegionAttributes<Long, Long> calculationsRegionAttributes,
101+
@Qualifier("calculationsRegionLoader") CacheLoader<Long, Long> calculationsLoader) {
102+
103+
PartitionedRegionFactoryBean<Long, Long> calculationsRegion =
104+
new PartitionedRegionFactoryBean<Long, Long>();
105+
106+
calculationsRegion.setAttributes(calculationsRegionAttributes);
107+
calculationsRegion.setCache(gemfireCache);
108+
calculationsRegion.setCacheLoader(calculationsLoader);
109+
calculationsRegion.setClose(false);
110+
calculationsRegion.setName(CALCULATIONS_REGION_NAME);
111+
calculationsRegion.setPersistent(false);
112+
113+
return calculationsRegion;
114+
}
115+
116+
@Bean
117+
@SuppressWarnings("unchecked")
118+
RegionAttributesFactoryBean calculationsRegionAttributes() {
119+
RegionAttributesFactoryBean calculationsRegionAttributes =
120+
new RegionAttributesFactoryBean();
121+
122+
calculationsRegionAttributes.setKeyConstraint(Long.class);
123+
calculationsRegionAttributes.setKeyConstraint(Long.class);
124+
125+
return calculationsRegionAttributes;
126+
}
127+
128+
@Bean
129+
CacheLoader calculationsRegionLoader(@Qualifier("calculatorResolver") Calculator<Long, Long> calculator) {
130+
return new CacheLoader<Long, Long>() {
131+
@Override public Long load(LoaderHelper<Long, Long> loaderHelper) throws CacheLoaderException {
132+
Long operand = loaderHelper.getKey();
133+
return calculator.calculate(operand);
134+
}
135+
136+
@Override public void close() {
137+
}
138+
};
139+
}
140+
141+
@Bean
142+
GemfireTemplate calculationsRegionTemplate(Cache gemfireCache) {
143+
return new GemfireTemplate(gemfireCache.getRegion(CALCULATIONS_REGION_NAME));
144+
}
145+
146+
@Bean
147+
@SuppressWarnings("unchecked")
148+
Calculator<Long, Long> calculatorResolver(ApplicationContext context) {
149+
return context.getBean(applicationProperties.getCalculator(), Calculator.class);
150+
}
151+
152+
@Bean
153+
Calculator<Long, Long> addition() {
154+
return CalculatorFactory.addition();
155+
}
156+
157+
@Bean
158+
Calculator<Long, Long> factorial() {
159+
return CalculatorFactory.factorial();
160+
}
161+
162+
@Bean
163+
Calculator<Long, Long> multiplication() {
164+
return CalculatorFactory.multiplication();
165+
}
166+
167+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.data.geode.config;
18+
19+
import org.springframework.boot.context.properties.ConfigurationProperties;
20+
import org.springframework.util.StringUtils;
21+
22+
/**
23+
* The SampleDataGeodeApplicationProperties class...
24+
*
25+
* @author John Blum
26+
* @since 1.0.0
27+
*/
28+
@ConfigurationProperties(prefix = "sample.data.geode")
29+
@SuppressWarnings("unused")
30+
public class SampleDataGeodeApplicationProperties {
31+
32+
protected static final String DEFAULT_CALCULATOR = "factorial";
33+
protected static final String DEFAULT_LOG_LEVEL = "config";
34+
35+
private String calculator;
36+
private String logLevel;
37+
38+
protected String defaultIfEmpty(String value, String defaultValue) {
39+
return (StringUtils.hasText(value) ? value : defaultValue);
40+
}
41+
42+
public String getCalculator() {
43+
return defaultIfEmpty(calculator, DEFAULT_CALCULATOR);
44+
}
45+
46+
public void setCalculator(String calculator) {
47+
this.calculator = calculator;
48+
}
49+
50+
public String getLogLevel() {
51+
return defaultIfEmpty(logLevel, DEFAULT_LOG_LEVEL);
52+
}
53+
54+
public void setLogLevel(String logLevel) {
55+
this.logLevel = logLevel;
56+
}
57+
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2010-2013 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package sample.data.geode.service;
18+
19+
/**
20+
* The Calculator interface represents a mathematical computation of an operand with itself.
21+
*
22+
* @author John Blum
23+
* @since 1.4.0
24+
*/
25+
public interface Calculator<S, T> {
26+
27+
/**
28+
* Calculates the value of the operand with itself.
29+
*
30+
* @param operand the operand to use in the calculation.
31+
* @return the result of the operand calculated with itself.
32+
*/
33+
T calculate(S operand);
34+
35+
}

0 commit comments

Comments
 (0)