DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Software Design and Architecture
  3. Cloud Architecture
  4. Grails With Terracotta: A Few Lines of Config

Grails With Terracotta: A Few Lines of Config

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
May. 05, 10 · Interview
Like (0)
Save
Tweet
Share
12.08K Views

Join the DZone community and get the full member experience.

Join For Free
Dave Klein, the author of "Grails: A Quick-Start Guide" and Mike Allen, the Terracotta Product Manager, recently presented a seminar entitled "Clustering and Scaling Grails Apps: A Simple Approach."  Using an example application from "Grails: A Quick Start Guide," Klien shows us how to get a Grails application running with Terracotta and cluster a Grails app with Web Sessions Express.  Allen explains that Terracotta is known for scaling apps out to multiple nodes without overloading the database or losing application data consistency between nodes.  Grails already uses many of the technologies that Terracotta implements, including Quartz, Ehcache, and Hibernate.  For this reason, Allen says a lot of Grails users loved the Ehcache 2.0 beta (codenamed 'Darwin').  With each of those tools, newly released versions of Terracotta (3.2.1) and Ehcache (2.0) are now pluggable by config only.  Terracotta runs transparently behind Grails' core tools (Hibernate Ehcache, and Quartz), which are used to rapidly build web apps.  Klein thinks that tools like Terracotta and Grails are great because there are low barriers to entry.  When he first encountered Terracotta, he was impressed with how easy it is to use with Grails. 

Klein walks through the steps for running Grails with Terracotta.  First, he copies the Terracotta .jar into his Tomcat libraries.  After that he only needs to create one configuration file.  Klien starts by creating a context.xml file in his META-INF directory.  Next he finds the application, called Tekdays.  It's a web application for organizing and finding technology events.  Klien starts by checking out the Tekdays source code from the final chapter of his book and updating it to the most recent version of Grails.  He first shows how to integrate web sessions express from Terracotta using a few lines of XML config:

As an alternative to the tcConfigUrl, you can also drop the "Url" and put a file name in there.

Next, he modifies a few classes in his application and makes them serializable.  First is SecurityFilters.groovy:
Before:


After:



He also modifies TekUser.groovy.  In a previous blog, Klien says he modified all the domain classes, but only these two classes are really necessary for this example:
Before:


After:


TekUser.groovy gets stored in the session, so as you cluster things you want that to be available.  As you do more things, it might make more sense to modify all the domain classes.

That's all the config required!  Next you'll build your WAR.  Klien had one already prepared and started up his Tomcat servers next.  



On the two Tomcat instances, Klien showed that an entry's data in Tekdays was saved as he changed from one instance to the other, showing how the failover would work.  

If you want to cache your domain class using Ehcache, all you have to do is add a mapping block:

Obviously, Klein says that there are more options, but for the most part, running a Grails app with Terracotta is a simple process.  Check out the web seminar to see how Klein uses the Quartz job scheduler and other options.
Grail (web browser) Web application app Ehcache Express Data consistency Job scheduler cluster Session (web analytics) Apache Tomcat

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • How Chat GPT-3 Changed the Life of Young DevOps Engineers
  • Kubernetes-Native Development With Quarkus and Eclipse JKube
  • Java REST API Frameworks
  • How To Select Multiple Checkboxes in Selenium WebDriver Using Java

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: