2© 2014 Pivotal Software, Inc. All rights reserved. 2© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire API
Current and Future
John Blum - @john_blum
© 2015 - Pivotal Software, Inc.
3© 2014 Pivotal Software, Inc. All rights reserved.
Presenter
John Blum
Spring Data Team (formerly a GemFire
Engineer/Tech Lead)
Spring Data GemFire Project Lead
Apache Geode Committer
Responsibilities…
• Management & Monitoring (Gfsh)
• Management REST API
• Developer REST API
• Spring Data GemFire (v1.3.3 – current)
4© 2014 Pivotal Software, Inc. All rights reserved.
Agenda
 Spring Data GemFire API
– Configuration / Bootstrapping
– Data Access (DAO patterns)
– Function Execution
– Caching (JSR-107)
 Spring Data GemFire Future
– Spring Data Geode?
 Conclusion
 QA
5© 2014 Pivotal Software, Inc. All rights reserved.
“Simple things should be simple;
complex things should be possible”
– Alan Kay
6© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire (SDG)
Applies Spring's powerful, non-invasive programming model in a consistent
fashion to simplify configuration and development of Apache Geode applications.
Spring Ecosystem Integration…
– Spring Cache Abstraction / Transaction Management
– Spring Data Commons Repository Abstraction + REST
– Spring Integration (Inbound/Outbound Channel Adapters)
– Spring Session Data GemFire Adapter
– Spring XD (Sources & Sinks)
7© 2014 Pivotal Software, Inc. All rights reserved.
+ +
Apache Geode with Spring Data GemFire and Spring’s Cache
Abstraction is a JSR-107 (JCache) caching provider
8© 2014 Pivotal Software, Inc. All rights reserved.
GRAILS
Full-stack, Web
XD
Stream, Taps, Jobs
BOOT
Bootable, Minimal, Ops-Ready
Big,
Fast,
Flexible
Data Web,
Integration,
Batch
WEB
Controllers, REST,
WebSocket
INTEGRATION
Channels, Adapters,
Filters, Transformers
BATCH
Jobs, Steps,
Readers, Writers
BIG DATA
Ingestion, Export,
Orchestration, Hadoop
DATA
NON-RELATIONALRELATIONAL
CORE
GROOVYFRAMEWORK SECURITY REACTOR
9© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire Use Cases
 Configure & Bootstrap Apache Geode
– Replacement for cache.xml; Can be used with Cluster Configuration
 Build an Application Peer Cache (Cache)
– Embedded Cache
 Build an Application Cache Client (ClientCache)
– Client/Server
10© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire / Apache Geode Coordinates
<repository>
<id>spring-libs-snapshot</id>
<name>Spring Maven libs-snapshot Repository</name>
<url>https://repo.spring.io/libs-miletone</url>
</repository>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-gemfire</artifactId>
<version>1.7.0.APACHE-GEODE-EA-M1</version>
</dependency>
11© 2014 Pivotal Software, Inc. All rights reserved.
Spring-based Configuration
XML Java-based Configuration
12© 2014 Pivotal Software, Inc. All rights reserved.
Bootstrapping Apache Geode with Spring
@SpringBootApplication
@ImportResource("/spring-gemfire-context.xml")
public class SpringGemFireApplication {
public static void main(String[] args) {
SpringApplication.run(SpringGemFireApplication.class, args);
}
}
gfsh>start server -–name=Example --spring-xml-location=
<classpath-to-spring-application-context.xml>
13© 2014 Pivotal Software, Inc. All rights reserved.
Example
14© 2014 Pivotal Software, Inc. All rights reserved.
Data Access with Spring
Basic (Region) Data Access Object (DAO)…
@Repository
public class GolferDao extends DaoSupport {
@Resource(name = “Golfers”)
private Region<Long, Golfer> golfers;
…
}
15© 2014 Pivotal Software, Inc. All rights reserved.
Data Access with SDG GemfireTemplate
Advantages
 Simple, Convenient Data Access API (CRUD, OQL, Function)
 Protects developer from GemFire/Geode API changes
 Exception Translation into Spring DAO Exception Hierarchy
 Transaction Management
<bean id=“golfersTemplate” class=“org.springframework.data.gemfire.GemfireTemplate”
p:region-ref=“Golfers”/>
16© 2014 Pivotal Software, Inc. All rights reserved.
Data Access with Spring Data Repositories
Advantages
 Simple interface-based, Spring Data Repository definition (CRUD, Querying)
 Convention over Configuration (Querying)
 Portable
 Exception Translation & Transaction Management Support
public interface GolferRepository extends CrudRepository<Golfer, Long> {
List<Golfer> findByName(String name);
}
17© 2014 Pivotal Software, Inc. All rights reserved.
Example
18© 2014 Pivotal Software, Inc. All rights reserved.
Annotation-based Function Support
Spring Data GemFire introduces annotation support for Function implementation
and execution.
 Functions are implemented as POJO methods
 Functions are invoked using Object-Oriented method invocation.
SDG supports…
 @OnServer / @OnServers (from client only)
 @OnMember / @OnMembers (from peer only)
 @OnRegion (from either client or peer)
19© 2014 Pivotal Software, Inc. All rights reserved.
Annotation-based Function Implementation
package example.app.function;
@Component
class CustomerFunctions {
@GemfireFunction
public Customer update(Address address, PhoneNumber phoneNumber) { … }
@GemfireFunction(id = “MyFunction” HA=true)
public List<?> functionTwo(FunctionContext funcCtx, @Filter Set<?> keys, …) { … }
}
<gfe:annotation-driven/>
<!– optional when using <context:annotation-config> or <context:component-scan> -->
<bean class=“example.app.function.CustomerFunctions”/>
20© 2014 Pivotal Software, Inc. All rights reserved.
Annotation-based Function Execution
package example.app.function.executions;
@OnRegion(“Customers”)
interface CustomersFunctionExecution {
Customer update(Address address, PhoneNumber phoneNumber);
}
<gfe-data:function-executions base-package=“example.app.function.executions”/>
@Component
class ApplicationComponent {
@Autowired
private CustomersFunctionExecution customersFunction;
public Customer someMethod(Address address, PhoneNumber phoneNumber) {
return customersFunction.update(address, phoneNumber);
}
21© 2014 Pivotal Software, Inc. All rights reserved.
Example
22© 2014 Pivotal Software, Inc. All rights reserved.
Spring Cache Abstraction
Caching is useful in cases when an “expensive” operation (i.e. CPU, IO bound)
produces the same output given identical input; results can be reused.
Spring enables Declarative, Annotation-based Caching…
 @Cacheable – triggers cache population
 @CacheEvict – triggers cache eviction
 @CachePut – updates cache without interfering with method execution
 @Caching – groups multiple cache operations per method
 @CacheConfig – class-level cache-related settings
23© 2014 Pivotal Software, Inc. All rights reserved.
Spring Supports JSR-107 (JCache)
Spring JCache
@Cacheable @CacheResult
@CachePut @CachePut
@CacheEvict @CacheRemove
@CacheEvict(allEntries=true) @CacheRemoveAll
@CacheConfig @CacheDefaults
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-jsr-107
24© 2014 Pivotal Software, Inc. All rights reserved.
Apache Geode Caching Provider
@Configuration
@EnableCaching
@Import(GemFireConfiguration.class)
class ApplicationConfiguration {
@Bean
public CacheManager cacheManager(
Cache gemfireCache) {
GemfireCacheManager cacheManager =
new GemfireCacheManager();
cacheManager.setCache(gemfireCache);
return cacheManager;
}
}
<beans …
xmlns:cache=“http://www.springframework.org/schema/cach
e”…>
<gfe:cache properties-
ref="gemfireProperties"/>
<cache:annotation-driven/>
<bean id="cacheManager" class=
”o.s.data.gemfire.support.GemfireCacheManager"
p:cache-ref="gemfireCache"/>
25© 2014 Pivotal Software, Inc. All rights reserved.
Apache Geode Caching Example
@Service
class BookService {
@Autowired
private BookRepository bookRepository;
@Cacheable(value=“Books”, key=“#isbn”)
public Book findBook(String isbn, …) {
return bookRepository.findOne(isbn);
}
}
26© 2014 Pivotal Software, Inc. All rights reserved.
Example
27© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire Road Map
Spring Data Geode?
Planned…
• SGF-372 – Geode Off-Heap support
• SGF-401 – Geode-Spark Connector support
• SGF-402 – Geode-Lucene Connector support
• SGF-428 – Geode HDFS support
• SGF-451 – Context-Aware Repositories (Functions)
• SGF-452 – Function Execution from Repositories.
• SGF-453 – Annotation Support for Geode Callbacks (e.g. CacheListener)
28© 2014 Pivotal Software, Inc. All rights reserved.
Conclusion
29© 2014 Pivotal Software, Inc. All rights reserved.
Apache Geode References
 Project Page - http://geode.incubator.apache.org
 Contribute - http://geode.incubator.apache.org/contribute/
– Ideas - https://cwiki.apache.org/confluence/display/GEODE/How+to+Contribute
 Community Events - http://geode.incubator.apache.org/community/
 Documentation - http://geode.incubator.apache.org/docs/
– Docs Project - https://github.com/project-geode/docs
 Source Code - https://github.com/apache/incubator-geode
 JIRA - https://issues.apache.org/jira/browse/GEODE
 StackOverflow - http://stackoverflow.com/questions/tagged/gemfire+and+geode
30© 2014 Pivotal Software, Inc. All rights reserved.
Spring Data GemFire References
 Project Page - http://projects.spring.io/spring-data/
 Documentation –
– Reference Guide - http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/
– API - http://docs.spring.io/spring-data-gemfire/docs/current/api/
– Spring IO Guides - http://spring.io/guides
– Spring GemFire Examples –
 Source Code - https://github.com/spring-projects/spring-data-gemfire
 Examples - https://github.com/spring-projects/spring-gemfire-examples
 JIRA – https://jira.spring.io/browse/SGF
 StackOverflow - http://stackoverflow.com/questions/tagged/spring-data-gemfire
31© 2014 Pivotal Software, Inc. All rights reserved.
Other Spring GemFire/Geode Examples
 Effective Application Development with GemFire/Geode using Spring Data GemFire –
SpringOne2GX-2014 Dallas TX.
– Slides: https://github.com/jxblum/effective-spring-gemfire/blob/master/EffectiveApplicationDevelopmentWithGemfireUsingSpringDataGemFire.pdf
– Source Code: https://github.com/jxblum/effective-spring-gemfire
 Building Highly-Scalable Spring Applications with Apache Geode – SpringOne2GX-2015
Washington D.C.
– Slides: http://www.slideshare.net/john_blum/building-highly-scalable-spring-applications-using-inmemory-data-grids
– Source Code: https://github.com/jxblum/scalable-spring-gemfire
 Spring – GemFire/Geode Using Cluster Configuration Examples
– Source Code: https://github.com/jxblum/spring-gemfire-clusterconfiguration-examples
 GemFire or Geode Client/Server Configuration with Spring Examples
– Source Code: https://github.com/jxblum/pivotal-gemfire-clientserver-examples
Join the Apache Geode Community!
• Check out: http://geode.incubator.apache.org
• Subscribe: user-subscribe@geode.incubator.apache.org
• Download: http://geode.incubator.apache.org/releases/
33© 2014 Pivotal Software, Inc. All rights reserved. 33© 2014 Pivotal Software, Inc. All rights reserved.
Q&A
Any questions…
34© 2014 Pivotal Software, Inc. All rights reserved. 34© 2014 Pivotal Software, Inc. All rights reserved.
Thank You
#GeodeSummit - Spring Data GemFire API Current and Future

#GeodeSummit - Spring Data GemFire API Current and Future

  • 2.
    2© 2014 PivotalSoftware, Inc. All rights reserved. 2© 2014 Pivotal Software, Inc. All rights reserved. Spring Data GemFire API Current and Future John Blum - @john_blum © 2015 - Pivotal Software, Inc.
  • 3.
    3© 2014 PivotalSoftware, Inc. All rights reserved. Presenter John Blum Spring Data Team (formerly a GemFire Engineer/Tech Lead) Spring Data GemFire Project Lead Apache Geode Committer Responsibilities… • Management & Monitoring (Gfsh) • Management REST API • Developer REST API • Spring Data GemFire (v1.3.3 – current)
  • 4.
    4© 2014 PivotalSoftware, Inc. All rights reserved. Agenda  Spring Data GemFire API – Configuration / Bootstrapping – Data Access (DAO patterns) – Function Execution – Caching (JSR-107)  Spring Data GemFire Future – Spring Data Geode?  Conclusion  QA
  • 5.
    5© 2014 PivotalSoftware, Inc. All rights reserved. “Simple things should be simple; complex things should be possible” – Alan Kay
  • 6.
    6© 2014 PivotalSoftware, Inc. All rights reserved. Spring Data GemFire (SDG) Applies Spring's powerful, non-invasive programming model in a consistent fashion to simplify configuration and development of Apache Geode applications. Spring Ecosystem Integration… – Spring Cache Abstraction / Transaction Management – Spring Data Commons Repository Abstraction + REST – Spring Integration (Inbound/Outbound Channel Adapters) – Spring Session Data GemFire Adapter – Spring XD (Sources & Sinks)
  • 7.
    7© 2014 PivotalSoftware, Inc. All rights reserved. + + Apache Geode with Spring Data GemFire and Spring’s Cache Abstraction is a JSR-107 (JCache) caching provider
  • 8.
    8© 2014 PivotalSoftware, Inc. All rights reserved. GRAILS Full-stack, Web XD Stream, Taps, Jobs BOOT Bootable, Minimal, Ops-Ready Big, Fast, Flexible Data Web, Integration, Batch WEB Controllers, REST, WebSocket INTEGRATION Channels, Adapters, Filters, Transformers BATCH Jobs, Steps, Readers, Writers BIG DATA Ingestion, Export, Orchestration, Hadoop DATA NON-RELATIONALRELATIONAL CORE GROOVYFRAMEWORK SECURITY REACTOR
  • 9.
    9© 2014 PivotalSoftware, Inc. All rights reserved. Spring Data GemFire Use Cases  Configure & Bootstrap Apache Geode – Replacement for cache.xml; Can be used with Cluster Configuration  Build an Application Peer Cache (Cache) – Embedded Cache  Build an Application Cache Client (ClientCache) – Client/Server
  • 10.
    10© 2014 PivotalSoftware, Inc. All rights reserved. Spring Data GemFire / Apache Geode Coordinates <repository> <id>spring-libs-snapshot</id> <name>Spring Maven libs-snapshot Repository</name> <url>https://repo.spring.io/libs-miletone</url> </repository> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-gemfire</artifactId> <version>1.7.0.APACHE-GEODE-EA-M1</version> </dependency>
  • 11.
    11© 2014 PivotalSoftware, Inc. All rights reserved. Spring-based Configuration XML Java-based Configuration
  • 12.
    12© 2014 PivotalSoftware, Inc. All rights reserved. Bootstrapping Apache Geode with Spring @SpringBootApplication @ImportResource("/spring-gemfire-context.xml") public class SpringGemFireApplication { public static void main(String[] args) { SpringApplication.run(SpringGemFireApplication.class, args); } } gfsh>start server -–name=Example --spring-xml-location= <classpath-to-spring-application-context.xml>
  • 13.
    13© 2014 PivotalSoftware, Inc. All rights reserved. Example
  • 14.
    14© 2014 PivotalSoftware, Inc. All rights reserved. Data Access with Spring Basic (Region) Data Access Object (DAO)… @Repository public class GolferDao extends DaoSupport { @Resource(name = “Golfers”) private Region<Long, Golfer> golfers; … }
  • 15.
    15© 2014 PivotalSoftware, Inc. All rights reserved. Data Access with SDG GemfireTemplate Advantages  Simple, Convenient Data Access API (CRUD, OQL, Function)  Protects developer from GemFire/Geode API changes  Exception Translation into Spring DAO Exception Hierarchy  Transaction Management <bean id=“golfersTemplate” class=“org.springframework.data.gemfire.GemfireTemplate” p:region-ref=“Golfers”/>
  • 16.
    16© 2014 PivotalSoftware, Inc. All rights reserved. Data Access with Spring Data Repositories Advantages  Simple interface-based, Spring Data Repository definition (CRUD, Querying)  Convention over Configuration (Querying)  Portable  Exception Translation & Transaction Management Support public interface GolferRepository extends CrudRepository<Golfer, Long> { List<Golfer> findByName(String name); }
  • 17.
    17© 2014 PivotalSoftware, Inc. All rights reserved. Example
  • 18.
    18© 2014 PivotalSoftware, Inc. All rights reserved. Annotation-based Function Support Spring Data GemFire introduces annotation support for Function implementation and execution.  Functions are implemented as POJO methods  Functions are invoked using Object-Oriented method invocation. SDG supports…  @OnServer / @OnServers (from client only)  @OnMember / @OnMembers (from peer only)  @OnRegion (from either client or peer)
  • 19.
    19© 2014 PivotalSoftware, Inc. All rights reserved. Annotation-based Function Implementation package example.app.function; @Component class CustomerFunctions { @GemfireFunction public Customer update(Address address, PhoneNumber phoneNumber) { … } @GemfireFunction(id = “MyFunction” HA=true) public List<?> functionTwo(FunctionContext funcCtx, @Filter Set<?> keys, …) { … } } <gfe:annotation-driven/> <!– optional when using <context:annotation-config> or <context:component-scan> --> <bean class=“example.app.function.CustomerFunctions”/>
  • 20.
    20© 2014 PivotalSoftware, Inc. All rights reserved. Annotation-based Function Execution package example.app.function.executions; @OnRegion(“Customers”) interface CustomersFunctionExecution { Customer update(Address address, PhoneNumber phoneNumber); } <gfe-data:function-executions base-package=“example.app.function.executions”/> @Component class ApplicationComponent { @Autowired private CustomersFunctionExecution customersFunction; public Customer someMethod(Address address, PhoneNumber phoneNumber) { return customersFunction.update(address, phoneNumber); }
  • 21.
    21© 2014 PivotalSoftware, Inc. All rights reserved. Example
  • 22.
    22© 2014 PivotalSoftware, Inc. All rights reserved. Spring Cache Abstraction Caching is useful in cases when an “expensive” operation (i.e. CPU, IO bound) produces the same output given identical input; results can be reused. Spring enables Declarative, Annotation-based Caching…  @Cacheable – triggers cache population  @CacheEvict – triggers cache eviction  @CachePut – updates cache without interfering with method execution  @Caching – groups multiple cache operations per method  @CacheConfig – class-level cache-related settings
  • 23.
    23© 2014 PivotalSoftware, Inc. All rights reserved. Spring Supports JSR-107 (JCache) Spring JCache @Cacheable @CacheResult @CachePut @CachePut @CacheEvict @CacheRemove @CacheEvict(allEntries=true) @CacheRemoveAll @CacheConfig @CacheDefaults http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#cache-jsr-107
  • 24.
    24© 2014 PivotalSoftware, Inc. All rights reserved. Apache Geode Caching Provider @Configuration @EnableCaching @Import(GemFireConfiguration.class) class ApplicationConfiguration { @Bean public CacheManager cacheManager( Cache gemfireCache) { GemfireCacheManager cacheManager = new GemfireCacheManager(); cacheManager.setCache(gemfireCache); return cacheManager; } } <beans … xmlns:cache=“http://www.springframework.org/schema/cach e”…> <gfe:cache properties- ref="gemfireProperties"/> <cache:annotation-driven/> <bean id="cacheManager" class= ”o.s.data.gemfire.support.GemfireCacheManager" p:cache-ref="gemfireCache"/>
  • 25.
    25© 2014 PivotalSoftware, Inc. All rights reserved. Apache Geode Caching Example @Service class BookService { @Autowired private BookRepository bookRepository; @Cacheable(value=“Books”, key=“#isbn”) public Book findBook(String isbn, …) { return bookRepository.findOne(isbn); } }
  • 26.
    26© 2014 PivotalSoftware, Inc. All rights reserved. Example
  • 27.
    27© 2014 PivotalSoftware, Inc. All rights reserved. Spring Data GemFire Road Map Spring Data Geode? Planned… • SGF-372 – Geode Off-Heap support • SGF-401 – Geode-Spark Connector support • SGF-402 – Geode-Lucene Connector support • SGF-428 – Geode HDFS support • SGF-451 – Context-Aware Repositories (Functions) • SGF-452 – Function Execution from Repositories. • SGF-453 – Annotation Support for Geode Callbacks (e.g. CacheListener)
  • 28.
    28© 2014 PivotalSoftware, Inc. All rights reserved. Conclusion
  • 29.
    29© 2014 PivotalSoftware, Inc. All rights reserved. Apache Geode References  Project Page - http://geode.incubator.apache.org  Contribute - http://geode.incubator.apache.org/contribute/ – Ideas - https://cwiki.apache.org/confluence/display/GEODE/How+to+Contribute  Community Events - http://geode.incubator.apache.org/community/  Documentation - http://geode.incubator.apache.org/docs/ – Docs Project - https://github.com/project-geode/docs  Source Code - https://github.com/apache/incubator-geode  JIRA - https://issues.apache.org/jira/browse/GEODE  StackOverflow - http://stackoverflow.com/questions/tagged/gemfire+and+geode
  • 30.
    30© 2014 PivotalSoftware, Inc. All rights reserved. Spring Data GemFire References  Project Page - http://projects.spring.io/spring-data/  Documentation – – Reference Guide - http://docs.spring.io/spring-data-gemfire/docs/current/reference/html/ – API - http://docs.spring.io/spring-data-gemfire/docs/current/api/ – Spring IO Guides - http://spring.io/guides – Spring GemFire Examples –  Source Code - https://github.com/spring-projects/spring-data-gemfire  Examples - https://github.com/spring-projects/spring-gemfire-examples  JIRA – https://jira.spring.io/browse/SGF  StackOverflow - http://stackoverflow.com/questions/tagged/spring-data-gemfire
  • 31.
    31© 2014 PivotalSoftware, Inc. All rights reserved. Other Spring GemFire/Geode Examples  Effective Application Development with GemFire/Geode using Spring Data GemFire – SpringOne2GX-2014 Dallas TX. – Slides: https://github.com/jxblum/effective-spring-gemfire/blob/master/EffectiveApplicationDevelopmentWithGemfireUsingSpringDataGemFire.pdf – Source Code: https://github.com/jxblum/effective-spring-gemfire  Building Highly-Scalable Spring Applications with Apache Geode – SpringOne2GX-2015 Washington D.C. – Slides: http://www.slideshare.net/john_blum/building-highly-scalable-spring-applications-using-inmemory-data-grids – Source Code: https://github.com/jxblum/scalable-spring-gemfire  Spring – GemFire/Geode Using Cluster Configuration Examples – Source Code: https://github.com/jxblum/spring-gemfire-clusterconfiguration-examples  GemFire or Geode Client/Server Configuration with Spring Examples – Source Code: https://github.com/jxblum/pivotal-gemfire-clientserver-examples
  • 32.
    Join the ApacheGeode Community! • Check out: http://geode.incubator.apache.org • Subscribe: user-subscribe@geode.incubator.apache.org • Download: http://geode.incubator.apache.org/releases/
  • 33.
    33© 2014 PivotalSoftware, Inc. All rights reserved. 33© 2014 Pivotal Software, Inc. All rights reserved. Q&A Any questions…
  • 34.
    34© 2014 PivotalSoftware, Inc. All rights reserved. 34© 2014 Pivotal Software, Inc. All rights reserved. Thank You

Editor's Notes

  • #6 Misconceptions about Spring… Spring is a Web Application Framework Spring’s programming model is unique and Spring uses it’s own conventions Built on fundamental OO principles (POJO) Software Design Patterns (IoC/DI, AOP) and… Open Standards (OSS) Apache Geode is a complex technology… Too many configuration options and settings. Inconsistent behavior between XML configuration (i.e. cache.xml) and API.