DZone
Java Zone
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
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Java Zone > 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 · Java Zone · Interview
Like (0)
Save
Tweet
11.78K 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

  • An Overview of 3 Java Embedded Databases
  • A Smarter Redis
  • Java: Why Core-to-Core Latency Matters
  • Modern REST API Design Principles and Rules

Comments

Java Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • 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:

DZone.com is powered by 

AnswerHub logo