Skip to content

Commit 10b59c1

Browse files
committed
Add starter and sample for Apache Geode.
Closes gh-5438.
1 parent d0eedd2 commit 10b59c1

File tree

11 files changed

+540
-0
lines changed

11 files changed

+540
-0
lines changed

spring-boot-dependencies/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<freemarker.version>2.3.25-incubating</freemarker.version>
7474
<elasticsearch.version>2.4.0</elasticsearch.version>
7575
<gemfire.version>8.2.0</gemfire.version>
76+
<geode.version>1.0.0-incubating</geode.version>
7677
<glassfish-el.version>3.0.0</glassfish-el.version>
7778
<gradle.version>2.9</gradle.version>
7879
<groovy.version>2.4.7</groovy.version>
@@ -148,6 +149,7 @@
148149
<spring-amqp.version>1.6.4.BUILD-SNAPSHOT</spring-amqp.version>
149150
<spring-cloud-connectors.version>1.2.3.RELEASE</spring-cloud-connectors.version>
150151
<spring-batch.version>3.0.7.RELEASE</spring-batch.version>
152+
<spring-data-geode.version>1.0.0.INCUBATING-RELEASE</spring-data-geode.version>
151153
<spring-data-releasetrain.version>Ingalls-M1</spring-data-releasetrain.version>
152154
<spring-hateoas.version>0.21.0.RELEASE</spring-hateoas.version>
153155
<spring-integration.version>4.3.5.BUILD-SNAPSHOT</spring-integration.version>
@@ -326,6 +328,11 @@
326328
<artifactId>spring-boot-starter-data-gemfire</artifactId>
327329
<version>2.0.0.BUILD-SNAPSHOT</version>
328330
</dependency>
331+
<dependency>
332+
<groupId>org.springframework.boot</groupId>
333+
<artifactId>spring-boot-starter-data-geode</artifactId>
334+
<version>2.0.0.BUILD-SNAPSHOT</version>
335+
</dependency>
329336
<dependency>
330337
<groupId>org.springframework.boot</groupId>
331338
<artifactId>spring-boot-starter-data-jpa</artifactId>
@@ -674,6 +681,11 @@
674681
<artifactId>gemfire</artifactId>
675682
<version>${gemfire.version}</version>
676683
</dependency>
684+
<dependency>
685+
<groupId>org.apache.geode</groupId>
686+
<artifactId>geode-core</artifactId>
687+
<version>${geode.version}</version>
688+
</dependency>
677689
<dependency>
678690
<groupId>com.github.ben-manes.caffeine</groupId>
679691
<artifactId>caffeine</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-neo4j</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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>2.0.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-configuration-processor</artifactId>
25+
<optional>true</optional>
26+
</dependency>
27+
<dependency>
28+
<groupId>org.springframework.boot</groupId>
29+
<artifactId>spring-boot-starter-data-geode</artifactId>
30+
</dependency>
31+
<dependency>
32+
<groupId>org.springframework.boot</groupId>
33+
<artifactId>spring-boot-starter-test</artifactId>
34+
<scope>test</scope>
35+
</dependency>
36+
</dependencies>
37+
<build>
38+
<plugins>
39+
<plugin>
40+
<groupId>org.springframework.boot</groupId>
41+
<artifactId>spring-boot-maven-plugin</artifactId>
42+
</plugin>
43+
</plugins>
44+
</build>
45+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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 org.apache.geode.cache.CacheLoader;
20+
import org.apache.geode.cache.CacheLoaderException;
21+
import org.apache.geode.cache.GemFireCache;
22+
import org.apache.geode.cache.LoaderHelper;
23+
import org.apache.geode.cache.RegionAttributes;
24+
import org.springframework.beans.factory.annotation.Autowired;
25+
import org.springframework.beans.factory.annotation.Qualifier;
26+
import org.springframework.boot.SpringApplication;
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
29+
import org.springframework.context.ApplicationContext;
30+
import org.springframework.context.annotation.Bean;
31+
import org.springframework.data.gemfire.GemfireTemplate;
32+
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
33+
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
34+
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;
35+
36+
import sample.data.geode.config.SampleDataGeodeApplicationProperties;
37+
import sample.data.geode.service.Calculator;
38+
import sample.data.geode.service.factory.CalculatorFactory;
39+
40+
/**
41+
* SampleDataGeodeApplication class is a Spring Boot, Apache Geode peer cache application
42+
* using Apache Geode to perform and store mathematical calculations.
43+
*
44+
* @author John Blum
45+
* @see org.springframework.boot.SpringApplication
46+
* @see org.springframework.boot.autoconfigure.SpringBootApplication
47+
* @see org.springframework.boot.context.properties.ConfigurationProperties
48+
* @see org.springframework.context.ApplicationContext
49+
* @see org.springframework.context.annotation.Bean
50+
* @see org.springframework.data.gemfire.CacheFactoryBean
51+
* @see org.springframework.data.gemfire.GemfireTemplate
52+
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
53+
* @see org.apache.geode.cache.Cache
54+
* @see org.apache.geode.cache.CacheLoader
55+
* @see sample.data.geode.service.Calculator
56+
* @see sample.data.geode.service.factory.CalculatorFactory
57+
* @since 1.5.0
58+
*/
59+
@SpringBootApplication
60+
@PeerCacheApplication(name = "SampleDataGeodeApplication", logLevel = "config")
61+
@EnableConfigurationProperties(SampleDataGeodeApplicationProperties.class)
62+
@SuppressWarnings("unused")
63+
public class SampleDataGeodeApplication {
64+
65+
protected static final String CALCULATIONS_REGION_NAME = "Calculations";
66+
67+
public static void main(final String[] args) {
68+
SpringApplication.run(SampleDataGeodeApplication.class, args);
69+
}
70+
71+
@Autowired
72+
SampleDataGeodeApplicationProperties applicationProperties;
73+
74+
@Bean(CALCULATIONS_REGION_NAME)
75+
PartitionedRegionFactoryBean<Long, Long> calculationsRegion(GemFireCache gemfireCache,
76+
RegionAttributes<Long, Long> calculationsRegionAttributes,
77+
@Qualifier("calculationsRegionLoader") CacheLoader<Long, Long> calculationsLoader) {
78+
79+
PartitionedRegionFactoryBean<Long, Long> calculationsRegion =
80+
new PartitionedRegionFactoryBean<Long, Long>();
81+
82+
calculationsRegion.setAttributes(calculationsRegionAttributes);
83+
calculationsRegion.setCache(gemfireCache);
84+
calculationsRegion.setCacheLoader(calculationsLoader);
85+
calculationsRegion.setClose(false);
86+
calculationsRegion.setPersistent(false);
87+
88+
return calculationsRegion;
89+
}
90+
91+
@Bean
92+
@SuppressWarnings("unchecked")
93+
RegionAttributesFactoryBean calculationsRegionAttributes() {
94+
RegionAttributesFactoryBean calculationsRegionAttributes =
95+
new RegionAttributesFactoryBean();
96+
97+
calculationsRegionAttributes.setKeyConstraint(Long.class);
98+
calculationsRegionAttributes.setValueConstraint(Long.class);
99+
100+
return calculationsRegionAttributes;
101+
}
102+
103+
@Bean
104+
CacheLoader calculationsRegionLoader(
105+
@Qualifier("calculatorResolver") Calculator<Long, Long> calculator) {
106+
107+
return new CacheLoader<Long, Long>() {
108+
@Override
109+
public Long load(LoaderHelper<Long, Long> loaderHelper)
110+
throws CacheLoaderException {
111+
112+
Long operand = loaderHelper.getKey();
113+
114+
return calculator.calculate(operand);
115+
}
116+
117+
@Override
118+
public void close() {
119+
}
120+
};
121+
}
122+
123+
@Bean
124+
GemfireTemplate calculationsRegionTemplate(GemFireCache gemfireCache) {
125+
return new GemfireTemplate(gemfireCache.getRegion(CALCULATIONS_REGION_NAME));
126+
}
127+
128+
@Bean
129+
@SuppressWarnings("unchecked")
130+
Calculator<Long, Long> calculatorResolver(ApplicationContext context) {
131+
return context.getBean(applicationProperties.getCalculator(), Calculator.class);
132+
}
133+
134+
@Bean
135+
Calculator<Long, Long> addition() {
136+
return CalculatorFactory.addition();
137+
}
138+
139+
@Bean
140+
Calculator<Long, Long> factorial() {
141+
return CalculatorFactory.factorial();
142+
}
143+
144+
@Bean
145+
Calculator<Long, Long> multiplication() {
146+
return CalculatorFactory.multiplication();
147+
}
148+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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 {@link SampleDataGeodeApplicationProperties} class encapsulates properties
24+
* used to configure the {@link sample.data.geode.SampleDataGeodeApplication}.
25+
*
26+
* @author John Blum
27+
* @see org.springframework.boot.context.properties.ConfigurationProperties
28+
* @since 1.5.0
29+
*/
30+
@ConfigurationProperties(prefix = "sample.data.geode")
31+
@SuppressWarnings("unused")
32+
public class SampleDataGeodeApplicationProperties {
33+
34+
protected static final String DEFAULT_CALCULATOR = "factorial";
35+
36+
private String calculator;
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 {@link Calculator} interface represents a mathematical computation
21+
* of an operand with itself.
22+
*
23+
* @author John Blum
24+
* @since 1.5.0
25+
*/
26+
public interface Calculator<S, T> {
27+
28+
/**
29+
* Calculates the value of the operand with itself.
30+
*
31+
* @param operand the operand to used in the calculation.
32+
* @return the result of the operand calculated with itself.
33+
*/
34+
T calculate(S operand);
35+
36+
}

0 commit comments

Comments
 (0)