SlideShare a Scribd company logo
1 of 13
Download to read offline
@jongallimore | #TomEE
Cluster your application with
CDI and JCache
Jonathan Gallimore
@jongallimore
#TomEE
@jongallimore | #TomEE
CDI and JCache
•  What%is%CDI?%
•  What%is%JCache?%
•  Demo%1%using%Hazelcast%to%add%caching%to%a%Java%EE%
applica<on%
•  Other%approaches%
•  Q%and%A%
@jongallimore | #TomEE
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
@jongallimore | #TomEE
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”%);%
•  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
@jongallimore | #TomEE
JCache and Java EE
@jongallimore | #TomEE
Hazelcast as a JCache Provider
•  Hazelcast is a fully compliant implementation of Jcache
•  Very easy to add to your Java EE application
–  Add com.hazelcast:hazelcast:3.4.1 and javax.cache:cache-api:1.0.0 to your POM.xml
•  Add declarative configuration to hazelcast.xml on the application’s classpath
•  Use JCache or Hazelcast API directly
<cache%name="mycache">%
%%<key1type%class1name="java.lang.Object"%/>%
%%<value1type%class1name="java.lang.Object"%/>%
%%<sta<s<cs1enabled>true</sta<s<cs1enabled>%
%%<management1enabled>true</management1enabled>%
</cache>%
final%MutableConfigura<on<Object,%Object>%config%=%new%MutableConfigura<on<Object,%Object>()%
%%%%%%%%.setTypes(Object.class,%Object.class)%
%%%%%%%%.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Dura<on.ONE_HOUR))%
%%%%%%%%.setSta<s<csEnabled(true);%
%
cache%=%mgr.createCache("mycache",%config);%
@jongallimore | #TomEE
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
@jongallimore | #TomEE
@jongallimore | #TomEE
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
@jongallimore | #TomEE
Show me the code!
@jongallimore | #TomEE
Other 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%=%"META1INF/hazelcast.xml";%%%
%
%%ClassLoader%loader%=%Thread.currentThread().getContextClassLoader();%%%
%%URL%loca<on%=%loader.getResource(configFile);%%%
%
%%final%Config%config%=%new%Config();%%%
%%config.setConfigura<onUrl(loca<on);%%%
%%config.setInstanceName("ExampleInstance");%%%
%%%%
%%return%Hazelcast.newHazelcastInstance(config);%%%
}%%
@jongallimore | #TomEE
Other approaches
•  Session replication filter
–  http://hazelcast.com/use-cases/web-session-clustering/generic-web-session-replication/
–  Native version for Tomcat / Jetty for Enterprise users
•  POC to share state for Stateful EJBs in TomEE using Hazelcast
@jongallimore | #TomEE
Thank you!

More Related Content

More from Hazelcast

The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptHazelcast
 
JCache - It's finally here
JCache -  It's finally hereJCache -  It's finally here
JCache - It's finally hereHazelcast
 
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentSpeed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentHazelcast
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganHazelcast
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridHazelcast
 
WAN Replication: Hazelcast Enterprise Lightning Talk
WAN Replication: Hazelcast Enterprise Lightning TalkWAN Replication: Hazelcast Enterprise Lightning Talk
WAN Replication: Hazelcast Enterprise Lightning TalkHazelcast
 
JAAS Security Suite: Hazelcast Enterprise Lightning Talk
JAAS Security Suite: Hazelcast Enterprise Lightning TalkJAAS Security Suite: Hazelcast Enterprise Lightning Talk
JAAS Security Suite: Hazelcast Enterprise Lightning TalkHazelcast
 
Hazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast
 
Extreme Network Performance with Hazelcast on Torusware
Extreme Network Performance with Hazelcast on ToruswareExtreme Network Performance with Hazelcast on Torusware
Extreme Network Performance with Hazelcast on ToruswareHazelcast
 
Big Data, Simple and Fast: Addressing the Shortcomings of Hadoop
Big Data, Simple and Fast: Addressing the Shortcomings of HadoopBig Data, Simple and Fast: Addressing the Shortcomings of Hadoop
Big Data, Simple and Fast: Addressing the Shortcomings of HadoopHazelcast
 
JAXLondon - Squeezing Performance of IMDGs
JAXLondon - Squeezing Performance of IMDGsJAXLondon - Squeezing Performance of IMDGs
JAXLondon - Squeezing Performance of IMDGsHazelcast
 
OrientDB & Hazelcast: In-Memory Distributed Graph Database
 OrientDB & Hazelcast: In-Memory Distributed Graph Database OrientDB & Hazelcast: In-Memory Distributed Graph Database
OrientDB & Hazelcast: In-Memory Distributed Graph DatabaseHazelcast
 
How to Use HazelcastMQ for Flexible Messaging and More
 How to Use HazelcastMQ for Flexible Messaging and More How to Use HazelcastMQ for Flexible Messaging and More
How to Use HazelcastMQ for Flexible Messaging and MoreHazelcast
 
Devoxx UK 2014 High Performance In-Memory Java with Open Source
Devoxx UK 2014   High Performance In-Memory Java with Open SourceDevoxx UK 2014   High Performance In-Memory Java with Open Source
Devoxx UK 2014 High Performance In-Memory Java with Open SourceHazelcast
 
JSR107 State of the Union JavaOne 2013
JSR107  State of the Union JavaOne 2013JSR107  State of the Union JavaOne 2013
JSR107 State of the Union JavaOne 2013Hazelcast
 
Jfokus - Hazlecast
Jfokus - HazlecastJfokus - Hazlecast
Jfokus - HazlecastHazelcast
 
In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014Hazelcast
 
In-memory Data Management Trends & Techniques
In-memory Data Management Trends & TechniquesIn-memory Data Management Trends & Techniques
In-memory Data Management Trends & TechniquesHazelcast
 
How to Speed up your Database
How to Speed up your DatabaseHow to Speed up your Database
How to Speed up your DatabaseHazelcast
 
Hazelcast HUGL
Hazelcast HUGLHazelcast HUGL
Hazelcast HUGLHazelcast
 

More from Hazelcast (20)

The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScriptThe Power of the JVM: Applied Polyglot Projects with Java and JavaScript
The Power of the JVM: Applied Polyglot Projects with Java and JavaScript
 
JCache - It's finally here
JCache -  It's finally hereJCache -  It's finally here
JCache - It's finally here
 
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and SpeedmentSpeed Up Your Existing Relational Databases with Hazelcast and Speedment
Speed Up Your Existing Relational Databases with Hazelcast and Speedment
 
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorganShared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
Shared Memory Performance: Beyond TCP/IP with Ben Cotton, JPMorgan
 
Applying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data GridApplying Real-time SQL Changes in your Hazelcast Data Grid
Applying Real-time SQL Changes in your Hazelcast Data Grid
 
WAN Replication: Hazelcast Enterprise Lightning Talk
WAN Replication: Hazelcast Enterprise Lightning TalkWAN Replication: Hazelcast Enterprise Lightning Talk
WAN Replication: Hazelcast Enterprise Lightning Talk
 
JAAS Security Suite: Hazelcast Enterprise Lightning Talk
JAAS Security Suite: Hazelcast Enterprise Lightning TalkJAAS Security Suite: Hazelcast Enterprise Lightning Talk
JAAS Security Suite: Hazelcast Enterprise Lightning Talk
 
Hazelcast for Terracotta Users
Hazelcast for Terracotta UsersHazelcast for Terracotta Users
Hazelcast for Terracotta Users
 
Extreme Network Performance with Hazelcast on Torusware
Extreme Network Performance with Hazelcast on ToruswareExtreme Network Performance with Hazelcast on Torusware
Extreme Network Performance with Hazelcast on Torusware
 
Big Data, Simple and Fast: Addressing the Shortcomings of Hadoop
Big Data, Simple and Fast: Addressing the Shortcomings of HadoopBig Data, Simple and Fast: Addressing the Shortcomings of Hadoop
Big Data, Simple and Fast: Addressing the Shortcomings of Hadoop
 
JAXLondon - Squeezing Performance of IMDGs
JAXLondon - Squeezing Performance of IMDGsJAXLondon - Squeezing Performance of IMDGs
JAXLondon - Squeezing Performance of IMDGs
 
OrientDB & Hazelcast: In-Memory Distributed Graph Database
 OrientDB & Hazelcast: In-Memory Distributed Graph Database OrientDB & Hazelcast: In-Memory Distributed Graph Database
OrientDB & Hazelcast: In-Memory Distributed Graph Database
 
How to Use HazelcastMQ for Flexible Messaging and More
 How to Use HazelcastMQ for Flexible Messaging and More How to Use HazelcastMQ for Flexible Messaging and More
How to Use HazelcastMQ for Flexible Messaging and More
 
Devoxx UK 2014 High Performance In-Memory Java with Open Source
Devoxx UK 2014   High Performance In-Memory Java with Open SourceDevoxx UK 2014   High Performance In-Memory Java with Open Source
Devoxx UK 2014 High Performance In-Memory Java with Open Source
 
JSR107 State of the Union JavaOne 2013
JSR107  State of the Union JavaOne 2013JSR107  State of the Union JavaOne 2013
JSR107 State of the Union JavaOne 2013
 
Jfokus - Hazlecast
Jfokus - HazlecastJfokus - Hazlecast
Jfokus - Hazlecast
 
In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014In-memory No SQL- GIDS2014
In-memory No SQL- GIDS2014
 
In-memory Data Management Trends & Techniques
In-memory Data Management Trends & TechniquesIn-memory Data Management Trends & Techniques
In-memory Data Management Trends & Techniques
 
How to Speed up your Database
How to Speed up your DatabaseHow to Speed up your Database
How to Speed up your Database
 
Hazelcast HUGL
Hazelcast HUGLHazelcast HUGL
Hazelcast HUGL
 

Recently uploaded

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptrcbcrtm
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfFerryKemperman
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 

Recently uploaded (20)

Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
cpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.pptcpct NetworkING BASICS AND NETWORK TOOL.ppt
cpct NetworkING BASICS AND NETWORK TOOL.ppt
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Introduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdfIntroduction Computer Science - Software Design.pdf
Introduction Computer Science - Software Design.pdf
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 

Cluster your Application using CDI and JCache

  • 1. @jongallimore | #TomEE Cluster your application with CDI and JCache Jonathan Gallimore @jongallimore #TomEE
  • 2. @jongallimore | #TomEE CDI and JCache •  What%is%CDI?% •  What%is%JCache?% •  Demo%1%using%Hazelcast%to%add%caching%to%a%Java%EE% applica<on% •  Other%approaches% •  Q%and%A%
  • 3. @jongallimore | #TomEE 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. @jongallimore | #TomEE 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. •  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 @jongallimore | #TomEE JCache and Java EE
  • 6. @jongallimore | #TomEE Hazelcast as a JCache Provider •  Hazelcast is a fully compliant implementation of Jcache •  Very easy to add to your Java EE application –  Add com.hazelcast:hazelcast:3.4.1 and javax.cache:cache-api:1.0.0 to your POM.xml •  Add declarative configuration to hazelcast.xml on the application’s classpath •  Use JCache or Hazelcast API directly <cache%name="mycache">% %%<key1type%class1name="java.lang.Object"%/>% %%<value1type%class1name="java.lang.Object"%/>% %%<sta<s<cs1enabled>true</sta<s<cs1enabled>% %%<management1enabled>true</management1enabled>% </cache>% final%MutableConfigura<on<Object,%Object>%config%=%new%MutableConfigura<on<Object,%Object>()% %%%%%%%%.setTypes(Object.class,%Object.class)% %%%%%%%%.setExpiryPolicyFactory(AccessedExpiryPolicy.factoryOf(Dura<on.ONE_HOUR))% %%%%%%%%.setSta<s<csEnabled(true);% % cache%=%mgr.createCache("mycache",%config);%
  • 7. @jongallimore | #TomEE 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
  • 9. @jongallimore | #TomEE 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
  • 11. @jongallimore | #TomEE Other 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%=%"META1INF/hazelcast.xml";%%% % %%ClassLoader%loader%=%Thread.currentThread().getContextClassLoader();%%% %%URL%loca<on%=%loader.getResource(configFile);%%% % %%final%Config%config%=%new%Config();%%% %%config.setConfigura<onUrl(loca<on);%%% %%config.setInstanceName("ExampleInstance");%%% %%%% %%return%Hazelcast.newHazelcastInstance(config);%%% }%%
  • 12. @jongallimore | #TomEE Other approaches •  Session replication filter –  http://hazelcast.com/use-cases/web-session-clustering/generic-web-session-replication/ –  Native version for Tomcat / Jetty for Enterprise users •  POC to share state for Stateful EJBs in TomEE using Hazelcast