Grails With Terracotta: A Few Lines of Config
Join the DZone community and get the full member experience.Join For Free
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:
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:
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.