High-Performance Java EE with JCache and CDI Steve Millidge - Founder Payara Jaromir Hamala – Hazelcast @payara_fish
What are we going to talk about?
Pizza Architecture Projected 50K Users JAX-RS Mobile Interface PizzaStoreConnector (3rd Party API) Wet String Protocol PizzaStoreBackEnd (3rd Party Application)
Pizza Store Model Customer Address Order Store Pizza OrderItem
Pizza Connector Code
Pizza Connector Problems • High Latency • Multiple API round trips – Over Wet String • Wrong Data Model • Simply won’t scale to user volumes • Too costly to rewrite Recognize the Problem!
How do you speed it up? JCACHE JavaTM Temporary Caching API
Quick Cache Code
Beers All Round
What Just Happened?
JCACHE • Standard Java API for Caching – JSR107 • API and CDI binding • Supported by Many Cache Providers • Built in to Payara – Uses Hazelcast
Caching Concepts Caching • CachingProvider Provider – Retrieves and closes Cache Cache Managers Manager • CacheManager Cache – Creates and destroys caches Entry • Cache – Contains Objects in Key Key Value Pairs Value
Magic Behind @CacheResult • CDI Interceptor provided by Payara • Obtains CacheManager from CachingProvider • Creates Cache Name (Based on Method) • Looks up Cache in CacheManager • Takes Method Parameter Values and creates Cache Key • Does Cache.get before invoking method • If not in cache invokes method and does cache.put on the result.
Further CDI • @CacheResult – Caches the result of a method call • @CachePut – Cache a specific method parameter • @CacheRemove – Removes a cache entry based on parameters • @CacheRemoveAll – Removes all entries in the cache
What is Hazelcast • Distributed implementation of j.u.Colections inside a single jar • Distributed computing Swiss Army Knife • JCache Implementation And Much More!
What is Payara Micro • Small Footprint GlassFish based Runtime • Supports Java WAR deployments • Embeds JCache Support • Auto clusters using Hazelcast • Fully Embeddable API java –jar payara-micro.jar –deploy test.war
Payara Micro and Hazelcast • Embeds Hazelcast for Session Persistence • Enables Java EE developers to use JSR107 of raw Hazelcast api • Provides CDI annotations for Hazelcast • Supports Full Hazelcast API
Summary • Using JCache on Payara is simple • Hazelcast api is built in • JCache and CDI are built in • Build micro-services with distributed caching on Payara Embedded • Hazelcast Provides Performance, Resilience and Scalability