SlideShare a Scribd company logo
1 of 17
Persist and Replay Runtime Data
Using Apache Java Caching
System and Javassist
https://bitbucket.org/wishcoder/jcs.
marketdata.replay/wiki/Home
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Persist and Replay Runtime Data
• The ability to persist data created at runtime is
useful when application states and data are
required to be replayed multiple times to
investigate application issues.
• This article demonstrates how to persist
runtime data to disk and load disk persisted
data to replay in new JVM instances.
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Apache JCS and Javassist
• JCS is a distributed caching system written in
Java. Indexed Disk Auxiliary Cache is used to
persist data on disk. JCS only persist
Serializable java objects.
• Javassist (Java Programming Assistant) makes
Java bytecode manipulation simple. Javassist
is used to dynamically set values for transient
fields that are not persisted due to transient
nature.
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Maven Dependencies
<properties>
<org.javassist-version>3.19.0-GA</org.javassist-version>
<jcs-version>1.3</jcs-version>
</properties>
<dependencies>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${org.javassist-version}</version>
</dependency>
<dependency>
<groupId>jcs</groupId>
<artifactId>jcs</artifactId>
<version>${jcs-version}</version>
</dependency>
</dependencies>
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Log4j Settings for JCS
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d [%t] %C{1} %p - %m%n"/>
</layout>
</appender>
<logger name="org.apache.jcs">
<!– DEBUG level in dev mode will enable useful logs from JCS jar ->
<!– DON’T PUT THIS IN PRODUCTION ENVIRONMENT ->
<level value="DEBUG"/>
<appender-ref ref="CONSOLE"/>
</logger>
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Setup JCS - DEFAULT CACHE REGION
Properties props = new Properties();
props.put("jcs.default", "DC");
props.put("jcs.default.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes");
props.put("jcs.default.cacheattributes.MaxObjects", 1000);
props.put("jcs.default.cacheattributes.MemoryCacheName",
"org.apache.jcs.engine.memory.lru.LRUMemoryCache");
props.put("jcs.default.cacheattributes.DiskUsagePatternName", "UPDATE");
props.put("jcs.default.elementattributes", "org.apache.jcs.engine.ElementAttributes");
props.put("jcs.default.elementattributes.IsSpool", "true");
props.put("jcs.region.elementattributes.IsEternal", "false");
props.put("jcs.default.elementattributes.IsLateral", "false");
props.put("jcs.default.elementattributes.IsRemote", "false");
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Setup JCS - AUXILARY/DISK CACHE
props.put("jcs.auxiliary.DC", "org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory");
props.put("jcs.auxiliary.DC.attributes",
"org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes");
props.put("jcs.auxiliary.DC.attributes.DiskPath", “C:TradeCache”);
props.put("jcs.auxiliary.DC.attributes.MaxPurgatorySize", "10000000"); // 10000000
// If the maximum key size is less than 0, no limit will be placed on
// the number of keys. By default, the max key size is 5000.
props.put("jcs.auxiliary.DC.attributes.MaxKeySize", "-1");
// Use Thread Pool for disk operation
props.put("jcs.auxiliary.DC.attributes.EventQueueType", "POOLED");
props.put("jcs.auxiliary.DC.attributes.EventQueuePoolName", "disk_cache_event_queue");
// Disk Cache Event Queue Pool
props.put("thread_pool.disk_cache_event_queue.useBoundary", "false");
props.put("thread_pool.remote_cache_client.maximumPoolSize", "15");
props.put("thread_pool.disk_cache_event_queue.minimumPoolSize", "1");
props.put("thread_pool.disk_cache_event_queue.keepAliveTime", "3500");
props.put("thread_pool.disk_cache_event_queue.startUpSize", "1");
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Setup JCS – CUSTOM DATA CACHE REGION
props.put("jcs.region.marketdata_cache", "DC");
props.put("jcs.region.marketdata_cache.cacheattributes",
"org.apache.jcs.engine.CompositeCacheAttributes");
props.put("jcs.region.marketdata_cache.cacheattributes.MaxObjects", maxObjectInMemory);
props.put("jcs.region.marketdata_cache.cacheattributes.MemoryCacheName",
"org.apache.jcs.engine.memory.lru.LRUMemoryCache");
props.put("jcs.region.marketdata_cache.cacheattributes.DiskUsagePatternName", "UPDATE");
props.put("jcs.region.marketdata_cache.elementattributes",
"org.apache.jcs.engine.ElementAttributes");
props.put("jcs.region.marketdata_cache.elementattributes.IsEternal", "false");
props.put("jcs.region.marketdata_cache.elementattributes.IsLateral", "false");
props.put("jcs.region.marketdata_cache.elementattributes.IsRemote", "false");
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Initialize and use JCS
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(props )
CacheAccess cCache = JCS.getInstance(“marketdata_cache”);
• Write
cCache.put(Object name, Object obj);
• Read
Object obj = cCache.get(name);
• Persist Cache To Disk
// marketdata_cache.data and marketdata_cache.key files generated
cCache.dispose();
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
JCS - Load Data From Cache
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(props )
CacheAccess cCache = JCS.getInstance(“marketdata_cache”);
• Read
Object obj = cCache.get(name);
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Javassist – Inject Transient Data
Javassist (Java Programming Assistant) makes
Java bytecode manipulation simple. Javassist is
used to dynamically set values for transient
fields that are not persisted due to transient
nature.
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Javassist – Helper Class
CacheReplayHelper .java
https://bitbucket.org/wishcoder/jcs.marketdata.replay/raw/de77eb8afaa818d21b1ac4bd1f0c
90bc99521cd4/jcs.marketdata.replay/trade.common/src/main/java/com/wishcoder/samples/j
cs/trade/common/cache/CacheReplayHelper.java
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Javassist – Dynamically Add Setter Method
List<CtMethod> setterMethods = new ArrayList<CtMethod>();
CtClass sourceClass =
ClassPool.getDefault().get("com.wishcoder.samples.jcs.trade.common.data.TickEvent");
CtMethod setSourceMethod = getCacheManager().getMethod(sourceClass,
"setSource", "source",
"com.wishcoder.samples.jcs.trade.common.data.User");
setterMethods.add(setTickBookMethod);
CacheReplayHelper.addSetterMethods(sourceClass, setterMethods);
Class<?>[] userObject = new Class[1];
userObject[0] =
Class.forName("com.wishcoder.samples.jcs.trade.common.data.User");
HashMap<String, Class<?>[]> parameterMap = new HashMap<String,
Class<?>[]>();
parameterMap.put("setSource", userObject);
CacheReplayHelper.prepareNonSerializeSetters("com.wishcoder.samples.jcs.trade.common.data.TickEv
ent",
parameterMap);
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Javassist – Set Transient Data
• Read object from JCS Cache:
CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance();
ccm.configure(props )
CacheAccess cCache = JCS.getInstance(“marketdata_cache”);
Object cachedObject = cCache.get(name);
• Initialize object that need to be injected in cached object
User user = new User(‘1’, ‘Name’);
• Inject Transient data in cached object
cachedObject = CacheReplayHelper.setNonSerializeSetter(cachedObject ,
"setSource", user );
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Wiki and Source Repository
https://bitbucket.org/wishcoder/jcs.marketdata.replay/wiki/Home
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Useful Links
• Log4J
• Java
• Java MigLayout
• Javassist
• Apache Java Caching System - JCS
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
Questions?
Ajay Singh | message4ajay@gmail.com
LinkedIn - https://www.linkedin.com/in/ajaysinghonline
Bitbucket - https://bitbucket.org/wishcoder
Slideshare - http://www.slideshare.net/ajaysingh672
Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder

More Related Content

What's hot

Managing a shared_mysql_farm_phpday2011
Managing a shared_mysql_farm_phpday2011Managing a shared_mysql_farm_phpday2011
Managing a shared_mysql_farm_phpday2011
Combell NV
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldos
mfrancis
 

What's hot (20)

Managing a shared_mysql_farm_phpday2011
Managing a shared_mysql_farm_phpday2011Managing a shared_mysql_farm_phpday2011
Managing a shared_mysql_farm_phpday2011
 
Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!Varnish Cache and its usage in the real world!
Varnish Cache and its usage in the real world!
 
Apache ignite - a do-it-all key-value db?
Apache ignite - a do-it-all key-value db?Apache ignite - a do-it-all key-value db?
Apache ignite - a do-it-all key-value db?
 
RESS – Responsive Webdesign and Server Side Components
RESS – Responsive Webdesign and Server Side ComponentsRESS – Responsive Webdesign and Server Side Components
RESS – Responsive Webdesign and Server Side Components
 
인피니스팬 데이터그리드 플랫폼
인피니스팬 데이터그리드 플랫폼인피니스팬 데이터그리드 플랫폼
인피니스팬 데이터그리드 플랫폼
 
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und HibernateEffiziente Datenpersistierung mit JPA 2.1 und Hibernate
Effiziente Datenpersistierung mit JPA 2.1 und Hibernate
 
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
 
Intro To jQuery In Drupal
Intro To jQuery In DrupalIntro To jQuery In Drupal
Intro To jQuery In Drupal
 
Hppg
HppgHppg
Hppg
 
Django Multi-DB in Anger
Django Multi-DB in AngerDjango Multi-DB in Anger
Django Multi-DB in Anger
 
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
Thijs Feryn - Leverage HTTP to deliver cacheable websites - Codemotion Berlin...
 
Modularized Persistence - B Zsoldos
Modularized Persistence - B ZsoldosModularized Persistence - B Zsoldos
Modularized Persistence - B Zsoldos
 
Eh cache in Kaunas JUG
Eh cache in Kaunas JUGEh cache in Kaunas JUG
Eh cache in Kaunas JUG
 
Running ms sql stored procedures in mule
Running ms sql stored procedures in muleRunning ms sql stored procedures in mule
Running ms sql stored procedures in mule
 
Articulo java web
Articulo java webArticulo java web
Articulo java web
 
Drupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in DrupalDrupal.js: Best Practices for Managing Javascript in Drupal
Drupal.js: Best Practices for Managing Javascript in Drupal
 
Opencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJSOpencast Admin UI - Introduction to developing using AngularJS
Opencast Admin UI - Introduction to developing using AngularJS
 
Bootstrap 3 Cheat Sheet PDF Reference
Bootstrap 3 Cheat Sheet PDF ReferenceBootstrap 3 Cheat Sheet PDF Reference
Bootstrap 3 Cheat Sheet PDF Reference
 
HPPG - high performance photo gallery
HPPG - high performance photo galleryHPPG - high performance photo gallery
HPPG - high performance photo gallery
 
Practical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second WednesdayPractical Responsive Images - from Second Wednesday
Practical Responsive Images - from Second Wednesday
 

Viewers also liked

MyStuC - Application for you highlighting features
MyStuC - Application for you highlighting featuresMyStuC - Application for you highlighting features
MyStuC - Application for you highlighting features
Sumit Sethi
 
Open letter to the Minister of Justice and the Minister of Health, Welfare an...
Open letter to the Minister of Justice and the Minister of Health, Welfare an...Open letter to the Minister of Justice and the Minister of Health, Welfare an...
Open letter to the Minister of Justice and the Minister of Health, Welfare an...
drs Sandra Irene Veenstra, AMI grad
 

Viewers also liked (15)

TreeLookbook
TreeLookbookTreeLookbook
TreeLookbook
 
MyStuC - Application for you highlighting features
MyStuC - Application for you highlighting featuresMyStuC - Application for you highlighting features
MyStuC - Application for you highlighting features
 
Ley 1341 de 2009
Ley 1341 de 2009Ley 1341 de 2009
Ley 1341 de 2009
 
El año viejo Ecuador
El año viejo Ecuador El año viejo Ecuador
El año viejo Ecuador
 
juwel(1)
juwel(1)juwel(1)
juwel(1)
 
Vía aérea dificil 51
Vía aérea dificil 51Vía aérea dificil 51
Vía aérea dificil 51
 
Global tobacco epidemic through the European lens
Global tobacco epidemic through the European lensGlobal tobacco epidemic through the European lens
Global tobacco epidemic through the European lens
 
Democracia
DemocraciaDemocracia
Democracia
 
Installation and configuration of IBM Cloud Orchestrator v2.5
Installation and configuration of IBM Cloud Orchestrator v2.5Installation and configuration of IBM Cloud Orchestrator v2.5
Installation and configuration of IBM Cloud Orchestrator v2.5
 
Innovators program raleigh 2016 keynote
Innovators program raleigh 2016   keynoteInnovators program raleigh 2016   keynote
Innovators program raleigh 2016 keynote
 
Open letter to the Minister of Justice and the Minister of Health, Welfare an...
Open letter to the Minister of Justice and the Minister of Health, Welfare an...Open letter to the Minister of Justice and the Minister of Health, Welfare an...
Open letter to the Minister of Justice and the Minister of Health, Welfare an...
 
Bstructure p2
Bstructure p2Bstructure p2
Bstructure p2
 
A Carrier Roadmap for Monetizing Next Generation Wi-Fi
A Carrier Roadmap for Monetizing Next Generation Wi-FiA Carrier Roadmap for Monetizing Next Generation Wi-Fi
A Carrier Roadmap for Monetizing Next Generation Wi-Fi
 
CV v1
CV v1CV v1
CV v1
 
ประวัติส่วนตัวพระมหาพงษ์ศักดิ์ ญาณวีโร
ประวัติส่วนตัวพระมหาพงษ์ศักดิ์ ญาณวีโรประวัติส่วนตัวพระมหาพงษ์ศักดิ์ ญาณวีโร
ประวัติส่วนตัวพระมหาพงษ์ศักดิ์ ญาณวีโร
 

Similar to Java - Persist and Replay Runtime Data

Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
Bob Paulin
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
Spiffy
 

Similar to Java - Persist and Replay Runtime Data (20)

Scalable Integration with JBoss Fuse
Scalable Integration with JBoss FuseScalable Integration with JBoss Fuse
Scalable Integration with JBoss Fuse
 
Spring data requery
Spring data requerySpring data requery
Spring data requery
 
JCache Using JCache
JCache Using JCacheJCache Using JCache
JCache Using JCache
 
The new static resources framework
The new static resources frameworkThe new static resources framework
The new static resources framework
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Distributed caching and computing v3.7
Distributed caching and computing v3.7Distributed caching and computing v3.7
Distributed caching and computing v3.7
 
Whats new in ASP.NET 4.0
Whats new in ASP.NET 4.0Whats new in ASP.NET 4.0
Whats new in ASP.NET 4.0
 
Best practices para publicar un WebSite con SharePoint Server 2010
Best practices para publicar un WebSite con SharePoint Server 2010Best practices para publicar un WebSite con SharePoint Server 2010
Best practices para publicar un WebSite con SharePoint Server 2010
 
Think Distributed: The Hazelcast Way
Think Distributed: The Hazelcast WayThink Distributed: The Hazelcast Way
Think Distributed: The Hazelcast Way
 
Azure Day Reloaded 2019 - ARM Template workshop
Azure Day Reloaded 2019 - ARM Template workshopAzure Day Reloaded 2019 - ARM Template workshop
Azure Day Reloaded 2019 - ARM Template workshop
 
Build Your Own CMS with Apache Sling
Build Your Own CMS with Apache SlingBuild Your Own CMS with Apache Sling
Build Your Own CMS with Apache Sling
 
Integrating React.js Into a PHP Application
Integrating React.js Into a PHP ApplicationIntegrating React.js Into a PHP Application
Integrating React.js Into a PHP Application
 
DjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling DisqusDjangoCon 2010 Scaling Disqus
DjangoCon 2010 Scaling Disqus
 
ASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin LauASP.NET Overview - Alvin Lau
ASP.NET Overview - Alvin Lau
 
Building low latency java applications with ehcache
Building low latency java applications with ehcacheBuilding low latency java applications with ehcache
Building low latency java applications with ehcache
 
Rails3 asset-pipeline
Rails3 asset-pipelineRails3 asset-pipeline
Rails3 asset-pipeline
 
Built-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIsBuilt-in query caching for all PHP MySQL extensions/APIs
Built-in query caching for all PHP MySQL extensions/APIs
 
Rich Portlet Development in uPortal
Rich Portlet Development in uPortalRich Portlet Development in uPortal
Rich Portlet Development in uPortal
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
Azure appfabric caching intro and tips
Azure appfabric caching intro and tipsAzure appfabric caching intro and tips
Azure appfabric caching intro and tips
 

Recently uploaded

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 

Recently uploaded (20)

AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!State of the Smart Building Startup Landscape 2024!
State of the Smart Building Startup Landscape 2024!
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Vector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptxVector Search @ sw2con for slideshare.pptx
Vector Search @ sw2con for slideshare.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Design and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data ScienceDesign and Development of a Provenance Capture Platform for Data Science
Design and Development of a Provenance Capture Platform for Data Science
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 

Java - Persist and Replay Runtime Data

  • 1. Persist and Replay Runtime Data Using Apache Java Caching System and Javassist https://bitbucket.org/wishcoder/jcs. marketdata.replay/wiki/Home Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 2. Persist and Replay Runtime Data • The ability to persist data created at runtime is useful when application states and data are required to be replayed multiple times to investigate application issues. • This article demonstrates how to persist runtime data to disk and load disk persisted data to replay in new JVM instances. Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 3. Apache JCS and Javassist • JCS is a distributed caching system written in Java. Indexed Disk Auxiliary Cache is used to persist data on disk. JCS only persist Serializable java objects. • Javassist (Java Programming Assistant) makes Java bytecode manipulation simple. Javassist is used to dynamically set values for transient fields that are not persisted due to transient nature. Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 5. Log4j Settings for JCS <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender"> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d [%t] %C{1} %p - %m%n"/> </layout> </appender> <logger name="org.apache.jcs"> <!– DEBUG level in dev mode will enable useful logs from JCS jar -> <!– DON’T PUT THIS IN PRODUCTION ENVIRONMENT -> <level value="DEBUG"/> <appender-ref ref="CONSOLE"/> </logger> Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 6. Setup JCS - DEFAULT CACHE REGION Properties props = new Properties(); props.put("jcs.default", "DC"); props.put("jcs.default.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes"); props.put("jcs.default.cacheattributes.MaxObjects", 1000); props.put("jcs.default.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache"); props.put("jcs.default.cacheattributes.DiskUsagePatternName", "UPDATE"); props.put("jcs.default.elementattributes", "org.apache.jcs.engine.ElementAttributes"); props.put("jcs.default.elementattributes.IsSpool", "true"); props.put("jcs.region.elementattributes.IsEternal", "false"); props.put("jcs.default.elementattributes.IsLateral", "false"); props.put("jcs.default.elementattributes.IsRemote", "false"); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 7. Setup JCS - AUXILARY/DISK CACHE props.put("jcs.auxiliary.DC", "org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory"); props.put("jcs.auxiliary.DC.attributes", "org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes"); props.put("jcs.auxiliary.DC.attributes.DiskPath", “C:TradeCache”); props.put("jcs.auxiliary.DC.attributes.MaxPurgatorySize", "10000000"); // 10000000 // If the maximum key size is less than 0, no limit will be placed on // the number of keys. By default, the max key size is 5000. props.put("jcs.auxiliary.DC.attributes.MaxKeySize", "-1"); // Use Thread Pool for disk operation props.put("jcs.auxiliary.DC.attributes.EventQueueType", "POOLED"); props.put("jcs.auxiliary.DC.attributes.EventQueuePoolName", "disk_cache_event_queue"); // Disk Cache Event Queue Pool props.put("thread_pool.disk_cache_event_queue.useBoundary", "false"); props.put("thread_pool.remote_cache_client.maximumPoolSize", "15"); props.put("thread_pool.disk_cache_event_queue.minimumPoolSize", "1"); props.put("thread_pool.disk_cache_event_queue.keepAliveTime", "3500"); props.put("thread_pool.disk_cache_event_queue.startUpSize", "1"); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 8. Setup JCS – CUSTOM DATA CACHE REGION props.put("jcs.region.marketdata_cache", "DC"); props.put("jcs.region.marketdata_cache.cacheattributes", "org.apache.jcs.engine.CompositeCacheAttributes"); props.put("jcs.region.marketdata_cache.cacheattributes.MaxObjects", maxObjectInMemory); props.put("jcs.region.marketdata_cache.cacheattributes.MemoryCacheName", "org.apache.jcs.engine.memory.lru.LRUMemoryCache"); props.put("jcs.region.marketdata_cache.cacheattributes.DiskUsagePatternName", "UPDATE"); props.put("jcs.region.marketdata_cache.elementattributes", "org.apache.jcs.engine.ElementAttributes"); props.put("jcs.region.marketdata_cache.elementattributes.IsEternal", "false"); props.put("jcs.region.marketdata_cache.elementattributes.IsLateral", "false"); props.put("jcs.region.marketdata_cache.elementattributes.IsRemote", "false"); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 9. Initialize and use JCS CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance(); ccm.configure(props ) CacheAccess cCache = JCS.getInstance(“marketdata_cache”); • Write cCache.put(Object name, Object obj); • Read Object obj = cCache.get(name); • Persist Cache To Disk // marketdata_cache.data and marketdata_cache.key files generated cCache.dispose(); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 10. JCS - Load Data From Cache CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance(); ccm.configure(props ) CacheAccess cCache = JCS.getInstance(“marketdata_cache”); • Read Object obj = cCache.get(name); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 11. Javassist – Inject Transient Data Javassist (Java Programming Assistant) makes Java bytecode manipulation simple. Javassist is used to dynamically set values for transient fields that are not persisted due to transient nature. Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 12. Javassist – Helper Class CacheReplayHelper .java https://bitbucket.org/wishcoder/jcs.marketdata.replay/raw/de77eb8afaa818d21b1ac4bd1f0c 90bc99521cd4/jcs.marketdata.replay/trade.common/src/main/java/com/wishcoder/samples/j cs/trade/common/cache/CacheReplayHelper.java Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 13. Javassist – Dynamically Add Setter Method List<CtMethod> setterMethods = new ArrayList<CtMethod>(); CtClass sourceClass = ClassPool.getDefault().get("com.wishcoder.samples.jcs.trade.common.data.TickEvent"); CtMethod setSourceMethod = getCacheManager().getMethod(sourceClass, "setSource", "source", "com.wishcoder.samples.jcs.trade.common.data.User"); setterMethods.add(setTickBookMethod); CacheReplayHelper.addSetterMethods(sourceClass, setterMethods); Class<?>[] userObject = new Class[1]; userObject[0] = Class.forName("com.wishcoder.samples.jcs.trade.common.data.User"); HashMap<String, Class<?>[]> parameterMap = new HashMap<String, Class<?>[]>(); parameterMap.put("setSource", userObject); CacheReplayHelper.prepareNonSerializeSetters("com.wishcoder.samples.jcs.trade.common.data.TickEv ent", parameterMap); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 14. Javassist – Set Transient Data • Read object from JCS Cache: CompositeCacheManager ccm = CompositeCacheManager.getUnconfiguredInstance(); ccm.configure(props ) CacheAccess cCache = JCS.getInstance(“marketdata_cache”); Object cachedObject = cCache.get(name); • Initialize object that need to be injected in cached object User user = new User(‘1’, ‘Name’); • Inject Transient data in cached object cachedObject = CacheReplayHelper.setNonSerializeSetter(cachedObject , "setSource", user ); Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 15. Wiki and Source Repository https://bitbucket.org/wishcoder/jcs.marketdata.replay/wiki/Home Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 16. Useful Links • Log4J • Java • Java MigLayout • Javassist • Apache Java Caching System - JCS Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder
  • 17. Questions? Ajay Singh | message4ajay@gmail.com LinkedIn - https://www.linkedin.com/in/ajaysinghonline Bitbucket - https://bitbucket.org/wishcoder Slideshare - http://www.slideshare.net/ajaysingh672 Ajay Singh | message4ajay@gmail.com | LinkedIn - https://www.linkedin.com/in/ajaysinghonline | Bitbucket - https://bitbucket.org/wishcoder