high-performance java ee with jcache and cdi -...
TRANSCRIPT
![Page 1: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/1.jpg)
@payara_fish
High-Performance Java EE with JCache and CDI
Steve Millidge - Founder Payara
Jaromir Hamala – Hazelcast
![Page 2: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/2.jpg)
@payara_fish
What are we going to talk about?
![Page 3: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/3.jpg)
@payara_fish
Imagine!
![Page 4: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/4.jpg)
@payara_fish
Pizza Architecture
PizzaStoreConnector(3rd Party API)
PizzaStoreBackEnd(3rd Party Application)
Wet StringProtocol
JAX-RSMobile
Interface
Projected 50K Users
![Page 5: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/5.jpg)
@payara_fish
Pizza Store Model
Customer
Address
Order
OrderItemPizza
Store
![Page 6: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/6.jpg)
@payara_fish
Pizza Connector Code
![Page 7: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/7.jpg)
@payara_fish
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!
![Page 8: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/8.jpg)
@payara_fish
How do you speed it up?
JCACHE JavaTM Temporary Caching API
![Page 9: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/9.jpg)
@payara_fish
Quick Cache Code
![Page 10: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/10.jpg)
@payara_fish
Beers All Round
![Page 11: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/11.jpg)
@payara_fish
What Just Happened?
![Page 12: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/12.jpg)
@payara_fish
JCACHE
• Standard Java API for Caching
– JSR107
• API and CDI binding
• Supported by Many Cache Providers
• Built in to Payara
– Uses Hazelcast
![Page 13: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/13.jpg)
@payara_fish
Caching Concepts
Caching Provider
Cache Manager
Cache
Entry
Key
Value
• CachingProvider
– Retrieves and closes Cache Managers
• CacheManager
– Creates and destroys caches
• Cache
– Contains Objects in Key Value Pairs
![Page 14: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/14.jpg)
@payara_fish
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.
![Page 15: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/15.jpg)
@payara_fish
CachingProvider cp = Caching.getCachingProvider();
CacheManager cm = cp.getCacheManager();
MutableConfiguration<String, Stock> config
= new MutableConfiguration<>();
config.setStoreByValue(true)
.setTypes(String.class,String.class)
.setManagementEnabled(true)
.setStatisticsEnabled(true);
Cache<String, String> cache = cm.createCache(“PizzaCache",
config);
String key = createKey();
Cache.put(“Key”,methodCall())
![Page 16: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/16.jpg)
@payara_fish
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
![Page 17: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/17.jpg)
@payara_fish
What is Hazelcast
• Distributed implementation of j.u.Colections inside a single jar
• Distributed computing Swiss Army Knife
• JCache Implementation
And Much More!
![Page 18: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/18.jpg)
@payara_fish
What is Payara Micro
• Small Footprint GlassFish based Runtime
• Supports Java WAR deployments
• Embeds JCache Support
• Auto clusters using Hazelcast
• Fully Embeddable APIjava –jar payara-micro.jar –deploy test.war
![Page 19: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/19.jpg)
@payara_fish
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
![Page 20: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/20.jpg)
@payara_fish
Payara CDI Extensions
@NamedCache(cacheName = "cache”)
@Inject Cache
@Inject CacheManager
@Inject HazelcastInstance
![Page 21: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/21.jpg)
@payara_fish
Clustering Demo
![Page 22: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/22.jpg)
@payara_fish
Beyond the Specification
![Page 23: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/23.jpg)
@payara_fish
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
![Page 24: High-Performance Java EE with JCache and CDI - Huihoodocs.huihoo.com/...High-Performance-Java-EE-with-JCache-and-CDI.pdf · @payara_fish High-Performance Java EE with JCache and CDI](https://reader031.vdocuments.site/reader031/viewer/2022022013/5b2c0f467f8b9a6d188bb78c/html5/thumbnails/24.jpg)
@payara_fish
More Info• http://www.payara.co
– Payara information and downloads
• https://github.com/payara/Payara– Payara Development
• http://www.hazelcast.com• GET Hazelcast
• https://github.com/smillidge/JCacheWebinar• Code from this talk
• https://github.com/payara/Payara-Examples/tree/master/JCache-Examples
• Further JCache on Payara Examples