SlideShare a Scribd company logo
1 of 14
Jonathan Gallimore | Tomitribe
Cluster your application
with JCache and CDI
CDI and JCache
• What is CDI?
• What is JCache?
• Demo - using Hazelcast to add caching
to a Java EE application
• Other approaches
• Questions
What is CDI
• Contexts and Dependency Injection
• Introduced in Java EE 6 (both Web & Full Profile)
• Integrated with other specifications in Java EE (EJB, JAX-RS,
Servlets, JSF…)
• Provides the bean lifecycle management and typesafe injection
• Largely annotation-based
• Uses
– Injection (with scoping, names, qualifiers, stereotypes and alternatives)
– Producers (factory methods)
– Interceptors
– Observers
• Can be extended with portable extensions
JCache
• JSR-107 - https://github.com/jsr107
• Hazelcast implements the JCache specification as of version
3.3.1 (released October ‘14)
• Basic concepts
– Caching provider
– CacheManager
– Cache
– Entry
CachingProvider cachingProvider = Caching.getCachingProvider();
CacheManager cacheManager = cachingProvider.getCacheManager();
Cache<Object, Object> cache = cacheManager
.getCache( "default", Object.class, Object.class );
cache.put( “world”, “Hello, world” );
JCache and Java EE
• Can be included in Java EE applications
• Add javax.cache api and implementation jars in WEB-INF/lib
• You can use JCache in the same way a Java SE application
would use it
• JSR-107 provides standard annotations for caching, but these
are not yet implemented by containers. Hopefully this will be
part of Java EE 8
• CDI can provide dependency injection and interceptors for
JCache
Hazelcast
• Hazelcast is a fully compliant implementation of JCache
• Very easy to add to your Java EE application
– Add com.hazelcast:hazelcast:3.5.3 and javax.cache:cache-api:1.0.0 to your POM.xml
• Add hazelcast.xml to the classpath
• Or use JCache / Hazelcast API directly
<cache name="mycache">
<key-type class-name="java.lang.Object" />
<value-type class-name="java.lang.Object" />
<statistics-enabled>true</statistics-enabled>
<management-enabled>true</management-enabled>
</cache>
final MutableConfiguration<Object, Object> config = new MutableConfiguration<Object, Object>()
.setTypes(Object.class, Object.class)
.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_HOUR))
.setStatisticsEnabled(true);
cache = mgr.createCache("mycache", config);
What is TomEE?
• Tomcat + Java EE = TomEE
• Pronounced “Tommy”
• Java EE 6 Web Profile certified
• Java EE 7 in progress
• Built from All-Apache Components
• What we’ve all been building ourselves
– ... for years
TomEE Goals
• Be simple
• Avoid complexity and making users work
• Be Tomcat
• Should work with Tomcat tools and apps
• Be Certified
• Drop-in replacement for any Java EE Web
Profile server
Show me the code!
Alternative Approaches?
• Use Hazelcast directly as opposed to using the JCache API
– Non-portable, but, exposes a lot more functionality in Hazelcast
– Can still use CDI Producers and create your own interceptors
@Produces
@Singleton
@Hazelcast
public HazelcastInstance createHazelcastInstance() {
final String configFile = "META-INF/hazelcast.xml";
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL location = loader.getResource(configFile);
final Config config = new Config();
config.setConfigurationUrl(location);
config.setInstanceName("ExampleInstance");
return Hazelcast.newHazelcastInstance(config);
}
Alternative Approaches?
• Session replication filter
– http://hazelcast.com/use-cases/web-session-clustering/generic-web-
session-replication/
– Native version for Tomcat / Jetty for Enterprise users
Questions?
Thank you!

More Related Content

What's hot

Supercharge JavaEE applications using JCache
Supercharge JavaEE applications using JCacheSupercharge JavaEE applications using JCache
Supercharge JavaEE applications using JCachePayara
 
MySQL Usability Guidelines
MySQL Usability GuidelinesMySQL Usability Guidelines
MySQL Usability GuidelinesMorgan Tocker
 
Securing your database servers from external attacks
Securing your database servers from external attacksSecuring your database servers from external attacks
Securing your database servers from external attacksAlkin Tezuysal
 
MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server DefaultsMorgan Tocker
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Barney Hanlon
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issuesOm Vikram Thapa
 
MySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMorgan Tocker
 
JSR107 Come, Code, Cache, Compute!
JSR107 Come, Code, Cache, Compute! JSR107 Come, Code, Cache, Compute!
JSR107 Come, Code, Cache, Compute! Payara
 
Course Tech 2013, Ron Carswell, Using Virtualization in the Classroom
Course Tech 2013, Ron Carswell, Using Virtualization in the ClassroomCourse Tech 2013, Ron Carswell, Using Virtualization in the Classroom
Course Tech 2013, Ron Carswell, Using Virtualization in the ClassroomCengage Learning
 
Silverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsSilverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsBrettTasker
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance TuningMark Swarbrick
 
01 upgrade to my sql8
01 upgrade to my sql8 01 upgrade to my sql8
01 upgrade to my sql8 Ted Wennmark
 
Web session replication with Hazelcast
Web session replication with HazelcastWeb session replication with Hazelcast
Web session replication with HazelcastEmrah Kocaman
 

What's hot (20)

Supercharge JavaEE applications using JCache
Supercharge JavaEE applications using JCacheSupercharge JavaEE applications using JCache
Supercharge JavaEE applications using JCache
 
MySQL NoSQL APIs
MySQL NoSQL APIsMySQL NoSQL APIs
MySQL NoSQL APIs
 
MySQL Usability Guidelines
MySQL Usability GuidelinesMySQL Usability Guidelines
MySQL Usability Guidelines
 
JavaCro'14 - Using WildFly core to build high performance web server – Tomaž ...
JavaCro'14 - Using WildFly core to build high performance web server – Tomaž ...JavaCro'14 - Using WildFly core to build high performance web server – Tomaž ...
JavaCro'14 - Using WildFly core to build high performance web server – Tomaž ...
 
Securing your database servers from external attacks
Securing your database servers from external attacksSecuring your database servers from external attacks
Securing your database servers from external attacks
 
MySQL Server Defaults
MySQL Server DefaultsMySQL Server Defaults
MySQL Server Defaults
 
Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014Next Generation DevOps in Drupal: DrupalCamp London 2014
Next Generation DevOps in Drupal: DrupalCamp London 2014
 
Hazelcast
HazelcastHazelcast
Hazelcast
 
Understanding MySql locking issues
Understanding MySql locking issuesUnderstanding MySql locking issues
Understanding MySql locking issues
 
MySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big DataMySQL: From Single Instance to Big Data
MySQL: From Single Instance to Big Data
 
KubeCon_NA_2021
KubeCon_NA_2021KubeCon_NA_2021
KubeCon_NA_2021
 
JSR107 Come, Code, Cache, Compute!
JSR107 Come, Code, Cache, Compute! JSR107 Come, Code, Cache, Compute!
JSR107 Come, Code, Cache, Compute!
 
MySQL Security
MySQL SecurityMySQL Security
MySQL Security
 
Course Tech 2013, Ron Carswell, Using Virtualization in the Classroom
Course Tech 2013, Ron Carswell, Using Virtualization in the ClassroomCourse Tech 2013, Ron Carswell, Using Virtualization in the Classroom
Course Tech 2013, Ron Carswell, Using Virtualization in the Classroom
 
Silverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applicationsSilverstripe at scale - design & architecture for silverstripe applications
Silverstripe at scale - design & architecture for silverstripe applications
 
MySQL Manchester TT - Performance Tuning
MySQL Manchester TT  - Performance TuningMySQL Manchester TT  - Performance Tuning
MySQL Manchester TT - Performance Tuning
 
Caching in asp.net mvc
Caching in asp.net mvcCaching in asp.net mvc
Caching in asp.net mvc
 
Alejandro Zuno Data Backup English
Alejandro Zuno Data Backup EnglishAlejandro Zuno Data Backup English
Alejandro Zuno Data Backup English
 
01 upgrade to my sql8
01 upgrade to my sql8 01 upgrade to my sql8
01 upgrade to my sql8
 
Web session replication with Hazelcast
Web session replication with HazelcastWeb session replication with Hazelcast
Web session replication with Hazelcast
 

Similar to Cluster your application using CDI and JCache - Jonathan Gallimore

Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16Comsysto Reply GmbH
 
Arquillian in a nutshell
Arquillian in a nutshellArquillian in a nutshell
Arquillian in a nutshellBrockhaus Group
 
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...In-Memory Computing Summit
 
Using JCache to speed up your apps
Using JCache to speed up your appsUsing JCache to speed up your apps
Using JCache to speed up your appsVassilis Bekiaris
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpikeos890
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEduardo Pelegri-Llopart
 
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKitAtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKitWojciech Seliga
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1Sam Brannen
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...elliando dias
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroOndrej Mihályi
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroPayara
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroPayara
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Leejaxconf
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)Jen Wong
 
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCDevelopment of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCInfinIT - Innovationsnetværket for it
 
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...Payara
 
Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)Trisha Gee
 

Similar to Cluster your application using CDI and JCache - Jonathan Gallimore (20)

Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16Caching and JCache with Greg Luck 18.02.16
Caching and JCache with Greg Luck 18.02.16
 
Arquillian in a nutshell
Arquillian in a nutshellArquillian in a nutshell
Arquillian in a nutshell
 
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
IMC Summit 2016 Breakout - Greg Luck - How to Speed Up Your Application Using...
 
Using JCache to speed up your apps
Using JCache to speed up your appsUsing JCache to speed up your apps
Using JCache to speed up your apps
 
Arquillian in a nutshell
Arquillian in a nutshellArquillian in a nutshell
Arquillian in a nutshell
 
Apache DeltaSpike
Apache DeltaSpikeApache DeltaSpike
Apache DeltaSpike
 
Ehcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage PatternsEhcache Architecture, Features And Usage Patterns
Ehcache Architecture, Features And Usage Patterns
 
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKitAtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
AtlasCamp 2012 - Testing JIRA plugins smarter with TestKit
 
Spring Framework 4.1
Spring Framework 4.1Spring Framework 4.1
Spring Framework 4.1
 
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
Distributed Caching Using the JCACHE API and ehcache, Including a Case Study ...
 
Java Caching
Java CachingJava Caching
Java Caching
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Elastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara MicroElastic and Cloud-ready Applications with Payara Micro
Elastic and Cloud-ready Applications with Payara Micro
 
Cookies
CookiesCookies
Cookies
 
Writing Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason LeeWriting Plugged-in Java EE Apps: Jason Lee
Writing Plugged-in Java EE Apps: Jason Lee
 
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
More on Fitnesse and Continuous Integration (Silicon Valley code camp 2012)
 
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUCDevelopment of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
Development of Java tools using SWT and WALA af Hans Søndergaard, ViaUC
 
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...
10 Strategies for Developing Reliable Jakarta EE & MicroProfile Applications ...
 
Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)Java 8 in Anger (QCon London)
Java 8 in Anger (QCon London)
 

More from JAXLondon_Conference

Cassandra and Spark - Tim Berglund
Cassandra and Spark - Tim BerglundCassandra and Spark - Tim Berglund
Cassandra and Spark - Tim BerglundJAXLondon_Conference
 
All change! How the new Economics of Cloud will make you think differently ab...
All change! How the new Economics of Cloud will make you think differently ab...All change! How the new Economics of Cloud will make you think differently ab...
All change! How the new Economics of Cloud will make you think differently ab...JAXLondon_Conference
 
The Unit Test is dead. Long live the Unit Test! - Colin Vipurs
The Unit Test is dead. Long live the Unit Test! - Colin VipursThe Unit Test is dead. Long live the Unit Test! - Colin Vipurs
The Unit Test is dead. Long live the Unit Test! - Colin VipursJAXLondon_Conference
 
Stop guessing, start testing – mobile testing done right - Timo Euteneuer
Stop guessing, start testing – mobile testing done right - Timo EuteneuerStop guessing, start testing – mobile testing done right - Timo Euteneuer
Stop guessing, start testing – mobile testing done right - Timo EuteneuerJAXLondon_Conference
 
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJava Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJAXLondon_Conference
 
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJava Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJAXLondon_Conference
 
Smoothing the continuous delivery path – a tale of two teams - Lyndsay Prewer
Smoothing the continuous delivery path – a tale of two teams - Lyndsay PrewerSmoothing the continuous delivery path – a tale of two teams - Lyndsay Prewer
Smoothing the continuous delivery path – a tale of two teams - Lyndsay PrewerJAXLondon_Conference
 
VC from the inside - a techie's perspective - Adrian Colyer
VC from the inside - a techie's perspective - Adrian ColyerVC from the inside - a techie's perspective - Adrian Colyer
VC from the inside - a techie's perspective - Adrian ColyerJAXLondon_Conference
 
Use your type system; write less code - Samir Talwar
Use your type system; write less code - Samir TalwarUse your type system; write less code - Samir Talwar
Use your type system; write less code - Samir TalwarJAXLondon_Conference
 
Thinking fast and slow with software development - Daniel Bryant
Thinking fast and slow with software development - Daniel BryantThinking fast and slow with software development - Daniel Bryant
Thinking fast and slow with software development - Daniel BryantJAXLondon_Conference
 
The java memory model and the mutability matrix of pain - Jamie Allen
The java memory model and the mutability matrix of pain - Jamie AllenThe java memory model and the mutability matrix of pain - Jamie Allen
The java memory model and the mutability matrix of pain - Jamie AllenJAXLondon_Conference
 
The art of shifting perspectives - Rachel Davies
The art of shifting perspectives - Rachel DaviesThe art of shifting perspectives - Rachel Davies
The art of shifting perspectives - Rachel DaviesJAXLondon_Conference
 
Spring Boot in the Web Tier - Dave Syer
Spring Boot in the Web Tier - Dave SyerSpring Boot in the Web Tier - Dave Syer
Spring Boot in the Web Tier - Dave SyerJAXLondon_Conference
 
Microservices from dream to reality in an hour - Dr. Holly Cummins
Microservices from dream to reality in an hour - Dr. Holly CumminsMicroservices from dream to reality in an hour - Dr. Holly Cummins
Microservices from dream to reality in an hour - Dr. Holly CumminsJAXLondon_Conference
 
Love your architecture - Alexander von Zitzewitz
Love your architecture - Alexander von ZitzewitzLove your architecture - Alexander von Zitzewitz
Love your architecture - Alexander von ZitzewitzJAXLondon_Conference
 
Java vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJava vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJAXLondon_Conference
 
Java generics past, present and future - Raoul-Gabriel Urma, Richard Warburton
Java generics past, present and future - Raoul-Gabriel Urma, Richard WarburtonJava generics past, present and future - Raoul-Gabriel Urma, Richard Warburton
Java generics past, present and future - Raoul-Gabriel Urma, Richard WarburtonJAXLondon_Conference
 
Java 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen ColebourneJava 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen ColebourneJAXLondon_Conference
 
Intuitions for scaling data centric architectures - Benjamin Stopford
Intuitions for scaling data centric architectures - Benjamin StopfordIntuitions for scaling data centric architectures - Benjamin Stopford
Intuitions for scaling data centric architectures - Benjamin StopfordJAXLondon_Conference
 

More from JAXLondon_Conference (20)

Cassandra and Spark - Tim Berglund
Cassandra and Spark - Tim BerglundCassandra and Spark - Tim Berglund
Cassandra and Spark - Tim Berglund
 
All change! How the new Economics of Cloud will make you think differently ab...
All change! How the new Economics of Cloud will make you think differently ab...All change! How the new Economics of Cloud will make you think differently ab...
All change! How the new Economics of Cloud will make you think differently ab...
 
The Unit Test is dead. Long live the Unit Test! - Colin Vipurs
The Unit Test is dead. Long live the Unit Test! - Colin VipursThe Unit Test is dead. Long live the Unit Test! - Colin Vipurs
The Unit Test is dead. Long live the Unit Test! - Colin Vipurs
 
Stop guessing, start testing – mobile testing done right - Timo Euteneuer
Stop guessing, start testing – mobile testing done right - Timo EuteneuerStop guessing, start testing – mobile testing done right - Timo Euteneuer
Stop guessing, start testing – mobile testing done right - Timo Euteneuer
 
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJava Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
 
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel UrmaJava Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
Java Generics Past, Present and Future - Richard Warburton, Raoul-Gabriel Urma
 
Smoothing the continuous delivery path – a tale of two teams - Lyndsay Prewer
Smoothing the continuous delivery path – a tale of two teams - Lyndsay PrewerSmoothing the continuous delivery path – a tale of two teams - Lyndsay Prewer
Smoothing the continuous delivery path – a tale of two teams - Lyndsay Prewer
 
VC from the inside - a techie's perspective - Adrian Colyer
VC from the inside - a techie's perspective - Adrian ColyerVC from the inside - a techie's perspective - Adrian Colyer
VC from the inside - a techie's perspective - Adrian Colyer
 
Use your type system; write less code - Samir Talwar
Use your type system; write less code - Samir TalwarUse your type system; write less code - Samir Talwar
Use your type system; write less code - Samir Talwar
 
Thinking fast and slow with software development - Daniel Bryant
Thinking fast and slow with software development - Daniel BryantThinking fast and slow with software development - Daniel Bryant
Thinking fast and slow with software development - Daniel Bryant
 
The java memory model and the mutability matrix of pain - Jamie Allen
The java memory model and the mutability matrix of pain - Jamie AllenThe java memory model and the mutability matrix of pain - Jamie Allen
The java memory model and the mutability matrix of pain - Jamie Allen
 
The art of shifting perspectives - Rachel Davies
The art of shifting perspectives - Rachel DaviesThe art of shifting perspectives - Rachel Davies
The art of shifting perspectives - Rachel Davies
 
Spring Boot in the Web Tier - Dave Syer
Spring Boot in the Web Tier - Dave SyerSpring Boot in the Web Tier - Dave Syer
Spring Boot in the Web Tier - Dave Syer
 
Microservices from dream to reality in an hour - Dr. Holly Cummins
Microservices from dream to reality in an hour - Dr. Holly CumminsMicroservices from dream to reality in an hour - Dr. Holly Cummins
Microservices from dream to reality in an hour - Dr. Holly Cummins
 
Love your architecture - Alexander von Zitzewitz
Love your architecture - Alexander von ZitzewitzLove your architecture - Alexander von Zitzewitz
Love your architecture - Alexander von Zitzewitz
 
Lambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter Lawrey
 
Java vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris BaileyJava vs. Java Script for enterprise web applications - Chris Bailey
Java vs. Java Script for enterprise web applications - Chris Bailey
 
Java generics past, present and future - Raoul-Gabriel Urma, Richard Warburton
Java generics past, present and future - Raoul-Gabriel Urma, Richard WarburtonJava generics past, present and future - Raoul-Gabriel Urma, Richard Warburton
Java generics past, present and future - Raoul-Gabriel Urma, Richard Warburton
 
Java 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen ColebourneJava 8 best practices - Stephen Colebourne
Java 8 best practices - Stephen Colebourne
 
Intuitions for scaling data centric architectures - Benjamin Stopford
Intuitions for scaling data centric architectures - Benjamin StopfordIntuitions for scaling data centric architectures - Benjamin Stopford
Intuitions for scaling data centric architectures - Benjamin Stopford
 

Recently uploaded

cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningVitsRangannavar
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutionsmonugehlot87
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 

Recently uploaded (20)

Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
cybersecurity notes for mca students for learning
cybersecurity notes for mca students for learningcybersecurity notes for mca students for learning
cybersecurity notes for mca students for learning
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
buds n tech IT solutions
buds n  tech IT                solutionsbuds n  tech IT                solutions
buds n tech IT solutions
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 

Cluster your application using CDI and JCache - Jonathan Gallimore

  • 1. Jonathan Gallimore | Tomitribe Cluster your application with JCache and CDI
  • 2. CDI and JCache • What is CDI? • What is JCache? • Demo - using Hazelcast to add caching to a Java EE application • Other approaches • Questions
  • 3. What is CDI • Contexts and Dependency Injection • Introduced in Java EE 6 (both Web & Full Profile) • Integrated with other specifications in Java EE (EJB, JAX-RS, Servlets, JSF…) • Provides the bean lifecycle management and typesafe injection • Largely annotation-based • Uses – Injection (with scoping, names, qualifiers, stereotypes and alternatives) – Producers (factory methods) – Interceptors – Observers • Can be extended with portable extensions
  • 4. JCache • JSR-107 - https://github.com/jsr107 • Hazelcast implements the JCache specification as of version 3.3.1 (released October ‘14) • Basic concepts – Caching provider – CacheManager – Cache – Entry CachingProvider cachingProvider = Caching.getCachingProvider(); CacheManager cacheManager = cachingProvider.getCacheManager(); Cache<Object, Object> cache = cacheManager .getCache( "default", Object.class, Object.class ); cache.put( “world”, “Hello, world” );
  • 5. JCache and Java EE • Can be included in Java EE applications • Add javax.cache api and implementation jars in WEB-INF/lib • You can use JCache in the same way a Java SE application would use it • JSR-107 provides standard annotations for caching, but these are not yet implemented by containers. Hopefully this will be part of Java EE 8 • CDI can provide dependency injection and interceptors for JCache
  • 6. Hazelcast • Hazelcast is a fully compliant implementation of JCache • Very easy to add to your Java EE application – Add com.hazelcast:hazelcast:3.5.3 and javax.cache:cache-api:1.0.0 to your POM.xml • Add hazelcast.xml to the classpath • Or use JCache / Hazelcast API directly <cache name="mycache"> <key-type class-name="java.lang.Object" /> <value-type class-name="java.lang.Object" /> <statistics-enabled>true</statistics-enabled> <management-enabled>true</management-enabled> </cache> final MutableConfiguration<Object, Object> config = new MutableConfiguration<Object, Object>() .setTypes(Object.class, Object.class) .setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Duration.ONE_HOUR)) .setStatisticsEnabled(true); cache = mgr.createCache("mycache", config);
  • 7. What is TomEE? • Tomcat + Java EE = TomEE • Pronounced “Tommy” • Java EE 6 Web Profile certified • Java EE 7 in progress • Built from All-Apache Components • What we’ve all been building ourselves – ... for years
  • 8.
  • 9. TomEE Goals • Be simple • Avoid complexity and making users work • Be Tomcat • Should work with Tomcat tools and apps • Be Certified • Drop-in replacement for any Java EE Web Profile server
  • 10. Show me the code!
  • 11. Alternative Approaches? • Use Hazelcast directly as opposed to using the JCache API – Non-portable, but, exposes a lot more functionality in Hazelcast – Can still use CDI Producers and create your own interceptors @Produces @Singleton @Hazelcast public HazelcastInstance createHazelcastInstance() { final String configFile = "META-INF/hazelcast.xml"; ClassLoader loader = Thread.currentThread().getContextClassLoader(); URL location = loader.getResource(configFile); final Config config = new Config(); config.setConfigurationUrl(location); config.setInstanceName("ExampleInstance"); return Hazelcast.newHazelcastInstance(config); }
  • 12. Alternative Approaches? • Session replication filter – http://hazelcast.com/use-cases/web-session-clustering/generic-web- session-replication/ – Native version for Tomcat / Jetty for Enterprise users

Editor's Notes

  1. I’m Jon Gallimore from Tomitribe, I’m a software engineer working with Apache TomEE. In this presentation I’ll show you how you can use Jcache with CDI to easily add caching to a Java EE application. I’ll start with a very quick introduction to CDI (which could be a session in itself) and an introduction to Jcache. Then I’ll run through a demo showing how to add caching to an existing Java EE application running in Apache TomEE using Hazelcast as the caching provider. Finally, we’ll wrap up looking at some alternative approaches and answering any questions.
  2. CDI – is short for Contexts and Dependency Injection and was introduced into Java EE in version 6, in both the web and full profile. For those of you that are unfamiliar, in Java EE 6, the functionality was split into two profiles in EE 6 – the full profile that includes everything, and the web profile which is a much cut-down version of Java EE which removes some of the older, less used APIs and keeps the APIs most commonly used in Java webapps, including EJB lite, JPA, Servlets and CDI. Although a more recent addition, CDI is well integrated with the rest of Java EE and can be used seamlessly with EJBs, JAX-RS etc). CDI essentially provides lifecycle management and typesafe injection of beans. Common usages of CDI are DI, producers (these are much like factory methods), interceptors (which allows you to change parameters or the method result or even avoid invoking the method altogether. Observers are a great feature of CDI, allowing events to be fired from one bean, and observed by another. For the most part, CDI is annotation based with very little XML configuration. Additional configuration is usually provided by creating new annotations. One of the really great things about CDI is that it can extended, and this can be achieved by extending the Extension interface. This essentially gives you hook into the container that allows you to manipulate the beans in the container. In the demo, I’ll show you a small library that implements a CDI extension that sets up the CacheManager so it can be injected. This CDI extension mechanism is portable between CDI containers, so extending CDI in this way does not restrict you to a particular application server. CDI is quite a big topic, and if you’re new to it, and want to get into it more, have a look at the TomEE examples. There are a number of simple examples showing each CDI concept individually complete with unit tests. Alex Soto has also got some great videos on his YouTube channel.
  3. Jcache is the standard Java caching specification. Completed last year, it was one of the longest running JSRs. Like a lot of specifications, there are a number of different implementations, and to use Jcache in your application, you need to include the jcache api JAR and the implementation jars for the specific implementation you wish to use. There are essentially 4 key concepts in Jcache: Caching provider – the implementation if Jcache being used. Can orchestrate multiple cache managers Caching manager – looks after zero of more named caches Cache – holds zero of more entries (data) Entry – abstraction of a key-value pair The slide shows the basic “hello world” equivalent for Jcache. We pick up the default cache provider from the classpath, get the cache manager, obtain a named cache (called “default”) and add some data.
  4. At this point, you can probably appreciate that you can add Jcache to your existing Java EE application by adding the necessary libraries and using it in a Java SE way. However, this will require you to manage everything yourself, and will also make for a pretty terrible demo for me. Fortunately, the Jcache specification provides a number of annotations that can be added to methods to trigger cache operations. The intention is that these will be implemented by the application servers, as opposed to each individual Jcache provider. Jcache is not part of Java EE 7, but hopefully will be in a future version of Java EE. However, if that doesn’t meet your “right-now” urges, no problem – you can use these annotations today and you should be able to switch over to the server provided annotations when they become available with minimal code changes.
  5. Hazelcast fully implements the Jcache specification as of late last year. It provides a huge range of functionality beyond caching, including a in-memory data grid and map/reduce functionality. Hazelcast implements caching from the ground-up as opposed to just adding a wrapper on top of its existing functionality. As you’d expect, the cache data is replicated across nodes, so there is no interruption to the cache if one of the noded drops out. Very easy to add to your application – just add the necessary jars. 3.5.3 is the latest version which I’ll be using here. Configuration can be provided within hazelcast.xml on the classpath, or configure programmatically.
  6. Just for those of you that have not come across TomEE before…
  7. There are a number of flavours of TomEE, each with a set of components. Note that we use JAX-RS here, but that is not part of the webprofile in EE6 (it is in 7).
  8. Ok, enough talk, lets look at the code. - Demo the existing app Add the libraries (talk about the tomitribe lib) Add hazelcast.xml Create a producer Add the annotation Inject into the bean Show the cache annotations Cache key producer Demonstrate with the cache
  9. Opens up more of the Hazelcast API.
  10. If your application stores state in a session, Hazelcast provide a session replication filter.