Skip to content

Add starter and sample for Apache Geode. #5445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions spring-boot-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<freemarker.version>2.3.25-incubating</freemarker.version>
<elasticsearch.version>2.4.1</elasticsearch.version>
<gemfire.version>8.2.0</gemfire.version>
<geode.version>1.0.0-incubating</geode.version>
<glassfish-el.version>3.0.0</glassfish-el.version>
<gradle.version>2.9</gradle.version>
<groovy.version>2.4.7</groovy.version>
Expand Down Expand Up @@ -147,6 +148,7 @@
<spring-amqp.version>1.6.4.BUILD-SNAPSHOT</spring-amqp.version>
<spring-cloud-connectors.version>1.2.3.RELEASE</spring-cloud-connectors.version>
<spring-batch.version>3.0.7.RELEASE</spring-batch.version>
<spring-data-geode.version>1.0.0.INCUBATING-RELEASE</spring-data-geode.version>
<spring-data-releasetrain.version>Ingalls-M1</spring-data-releasetrain.version>
<spring-hateoas.version>0.21.0.RELEASE</spring-hateoas.version>
<spring-integration.version>5.0.0.BUILD-SNAPSHOT</spring-integration.version>
Expand Down Expand Up @@ -324,6 +326,11 @@
<artifactId>spring-boot-starter-data-gemfire</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-geode</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
Expand Down Expand Up @@ -672,6 +679,17 @@
<artifactId>gemfire</artifactId>
<version>${gemfire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.geode</groupId>
<artifactId>geode-core</artifactId>
<version>${geode.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.shiro</groupId>
<artifactId>shiro-core</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
Expand Down
1 change: 1 addition & 0 deletions spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<module>spring-boot-sample-data-couchbase</module>
<module>spring-boot-sample-data-elasticsearch</module>
<module>spring-boot-sample-data-gemfire</module>
<module>spring-boot-sample-data-geode</module>
<module>spring-boot-sample-data-jpa</module>
<module>spring-boot-sample-data-mongodb</module>
<module>spring-boot-sample-data-neo4j</module>
Expand Down
45 changes: 45 additions & 0 deletions spring-boot-samples/spring-boot-sample-data-geode/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<!-- Your own application should inherit from spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-samples</artifactId>
<version>2.0.0.BUILD-SNAPSHOT</version>
</parent>
<artifactId>spring-boot-sample-data-geode</artifactId>
<name>Spring Boot Data Geode Sample</name>
<description>Spring Boot Data Geode Sample</description>
<url>http://projects.spring.io/spring-boot/</url>
<organization>
<name>Pivotal Software, Inc.</name>
<url>http://www.spring.io</url>
</organization>
<properties>
<main.basedir>${basedir}/../..</main.basedir>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-geode</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/*
* Copyright 2010-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 sample.data.geode;

import org.apache.geode.cache.CacheLoader;
import org.apache.geode.cache.CacheLoaderException;
import org.apache.geode.cache.GemFireCache;
import org.apache.geode.cache.LoaderHelper;
import org.apache.geode.cache.RegionAttributes;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.data.gemfire.GemfireTemplate;
import org.springframework.data.gemfire.PartitionedRegionFactoryBean;
import org.springframework.data.gemfire.RegionAttributesFactoryBean;
import org.springframework.data.gemfire.config.annotation.PeerCacheApplication;

import sample.data.geode.config.SampleDataGeodeApplicationProperties;
import sample.data.geode.service.Calculator;
import sample.data.geode.service.factory.CalculatorFactory;

/**
* SampleDataGeodeApplication class is a Spring Boot, Apache Geode peer cache application
* using Apache Geode to perform and store mathematical calculations.
*
* @author John Blum
* @see org.springframework.boot.SpringApplication
* @see org.springframework.boot.autoconfigure.SpringBootApplication
* @see org.springframework.boot.context.properties.ConfigurationProperties
* @see org.springframework.context.ApplicationContext
* @see org.springframework.context.annotation.Bean
* @see org.springframework.data.gemfire.CacheFactoryBean
* @see org.springframework.data.gemfire.GemfireTemplate
* @see org.springframework.data.gemfire.PartitionedRegionFactoryBean
* @see org.apache.geode.cache.Cache
* @see org.apache.geode.cache.CacheLoader
* @see sample.data.geode.service.Calculator
* @see sample.data.geode.service.factory.CalculatorFactory
* @since 1.5.0
*/
@SpringBootApplication
@PeerCacheApplication(name = "SampleDataGeodeApplication", logLevel = "config")
@EnableConfigurationProperties(SampleDataGeodeApplicationProperties.class)
@SuppressWarnings("unused")
public class SampleDataGeodeApplication {

protected static final String CALCULATIONS_REGION_NAME = "Calculations";

public static void main(final String[] args) {
SpringApplication.run(SampleDataGeodeApplication.class, args);
}

@Autowired
SampleDataGeodeApplicationProperties applicationProperties;

@Bean(CALCULATIONS_REGION_NAME)
PartitionedRegionFactoryBean<Long, Long> calculationsRegion(GemFireCache gemfireCache,
RegionAttributes<Long, Long> calculationsRegionAttributes,
@Qualifier("calculationsRegionLoader") CacheLoader<Long, Long> calculationsLoader) {

PartitionedRegionFactoryBean<Long, Long> calculationsRegion =
new PartitionedRegionFactoryBean<Long, Long>();

calculationsRegion.setAttributes(calculationsRegionAttributes);
calculationsRegion.setCache(gemfireCache);
calculationsRegion.setCacheLoader(calculationsLoader);
calculationsRegion.setClose(false);
calculationsRegion.setPersistent(false);

return calculationsRegion;
}

@Bean
@SuppressWarnings("unchecked")
RegionAttributesFactoryBean calculationsRegionAttributes() {
RegionAttributesFactoryBean calculationsRegionAttributes =
new RegionAttributesFactoryBean();

calculationsRegionAttributes.setKeyConstraint(Long.class);
calculationsRegionAttributes.setValueConstraint(Long.class);

return calculationsRegionAttributes;
}

@Bean
CacheLoader calculationsRegionLoader(
@Qualifier("calculatorResolver") Calculator<Long, Long> calculator) {

return new CacheLoader<Long, Long>() {
@Override
public Long load(LoaderHelper<Long, Long> loaderHelper)
throws CacheLoaderException {

Long operand = loaderHelper.getKey();

return calculator.calculate(operand);
}

@Override
public void close() {
}
};
}

@Bean
GemfireTemplate calculationsRegionTemplate(GemFireCache gemfireCache) {
return new GemfireTemplate(gemfireCache.getRegion(CALCULATIONS_REGION_NAME));
}

@Bean
@SuppressWarnings("unchecked")
Calculator<Long, Long> calculatorResolver(ApplicationContext context) {
return context.getBean(applicationProperties.getCalculator(), Calculator.class);
}

@Bean
Calculator<Long, Long> addition() {
return CalculatorFactory.addition();
}

@Bean
Calculator<Long, Long> factorial() {
return CalculatorFactory.factorial();
}

@Bean
Calculator<Long, Long> multiplication() {
return CalculatorFactory.multiplication();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2010-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 sample.data.geode.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.util.StringUtils;

/**
* The {@link SampleDataGeodeApplicationProperties} class encapsulates properties
* used to configure the {@link sample.data.geode.SampleDataGeodeApplication}.
*
* @author John Blum
* @see org.springframework.boot.context.properties.ConfigurationProperties
* @since 1.5.0
*/
@ConfigurationProperties(prefix = "sample.data.geode")
@SuppressWarnings("unused")
public class SampleDataGeodeApplicationProperties {

protected static final String DEFAULT_CALCULATOR = "factorial";

private String calculator;

protected String defaultIfEmpty(String value, String defaultValue) {
return (StringUtils.hasText(value) ? value : defaultValue);
}

public String getCalculator() {
return defaultIfEmpty(calculator, DEFAULT_CALCULATOR);
}

public void setCalculator(String calculator) {
this.calculator = calculator;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2010-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 sample.data.geode.service;

/**
* The {@link Calculator} interface represents a mathematical computation
* of an operand with itself.
*
* @author John Blum
* @since 1.5.0
*/
public interface Calculator<S, T> {

/**
* Calculates the value of the operand with itself.
*
* @param operand the operand to used in the calculation.
* @return the result of the operand calculated with itself.
*/
T calculate(S operand);

}
Loading