Clustering Made Easier Using Terracotta with Hibernate and/or Ehcache Cris J. Holdorph Software Architect Unicon, Inc. Jasig Conference San Diego, CA March 9, 2010 © Copyright Unicon, Inc., 2008.  Some rights reserved.  This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License. To view a copy of this license, visit  http://creativecommons.org/licenses/by-nc-sa/3.0/us/
Speaker Bio Michigan State University graduate
Java Developer since 1997
Unicon Employee since 1998 Cisco Networking Academy Program
uPortal
Sakai
Miscellaneous Professional Services http://www.unicon.net/blog/4
Agenda Technologies
Using Ehcache
Using Ehcache with Terracotta
Using Hibernate
Using Hibernate with 2cd level cache
Terracotta Server
Other Considerations
Technologies
Technologies Ehcache
Hibernate
Terracotta
Spring Framework
Ehcache What is it? Generic Caching Platform www.ehcache.org Latest stable release: 1.7.2 (2.0 in beta) Acquired by Terracotta in 2009 Greg Luck, Terracotta employee, Hibernate committer Gradually increased integration with Terracotta
Used by both uPortal and Sakai
Hibernate What is it? Object Relational Mapping for Data Persistence
JPA implementation www.hibernate.org Latest stable release: 3.3.2 Acquired by JBoss / RedHat
Used by both uPortal and Sakai
Terracotta What is it? Distributed Caching Platform
Clustered Caching Platform
Network Attached Memory www.terracotta.org Latest stable release: 3.2.0 Supported by Terracotta Tech
Open Source and Commercial
Unicon Partner
Many Terracotta employees are avid Twitter users
Spring Framework What is it? Dependency Injection Container
Multipurpose Java development libraries
And more... www.springframework.org Latest stable release: 3.0.0 Supported by Spring Source
Strong integration with Ehcache, Hibernate
Some integration with Terracotta
Used by both uPortal and Sakai
Using Ehcache
Sample Application Census Collect Web Application List View (choose  State  to limit display)
Form View Census View Web Application
Sample Application (screenshots)
Sample Application (screenshots)
pom.xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.5.8</version> </dependency>
ehcache.xml <ehcache> <diskStore path=&quot;java.io.tmpdir&quot; /> <defaultCache maxElementsInMemory=&quot;10&quot; eternal=&quot;false&quot; timeToIdleSeconds=&quot;120&quot; timeToLiveSeconds=&quot;300&quot; overflowToDisk=&quot;true&quot; /> <cache name=&quot;PEOPLE_CACHE&quot; maxElementsInMemory=&quot;2000&quot; eternal=&quot;false&quot; overflowToDisk=&quot;true&quot; timeToIdleSeconds=&quot;0&quot; timeToLiveSeconds=&quot;3600&quot; /> </ehcache>
CensusCollectServlet.java import net.sf.ehcache.Cache; import net.sf.ehcache.CacheManager; import net.sf.ehcache.Element; … private Cache peopleCache = null; … public void init(ServletConfig config) throws ServletException { super.init(config); CacheManager manager = new CacheManager(); peopleCache = manager.getCache(&quot;PEOPLE_CACHE&quot;); } ...
CensusCollectServlet.java ... Person person = null; Element element = peopleCache.get(ssn); if (person == null) { person = new Person(); } else { person = (Person)element.getValue(); } request.setAttribute(PERSON, person); ... peopleCache.put(new Element(ssn, person)); ...
Using Ehcache with RMI Replication
ehcache.xml <cacheManagerPeerProviderFactory class=&quot;net.sf.ehcache.distribution. RMICacheManagerPeerProviderFactory&quot; properties=&quot;hostName=fully_qualified_hostname_or_ip, peerDiscovery=automatic, multicastGroupAddress=230.0.0.1, multicastGroupPort=4446, timeToLive=32&quot;/> <cache name=&quot; PEOPLE_CACHE &quot; ...> <cacheEventListenerFactory class=&quot;net.sf.ehcache.distribution.RMICacheReplicatorFactory” properties=&quot;replicateAsynchronously=true, replicatePuts=true, replicatePutsViaCopy=false, replicateUpdates=true, replicateUpdatesViaCopy=true, replicateRemovals=true asynchronousReplicationIntervalMillis=1000&quot;/> </cache>
Using Ehcache with Terracotta
pom.xml <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-core</artifactId> <version>1.7.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-jdk14</artifactId> <version>1.5.8</version> </dependency> <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache-terracotta</artifactId> <version>1.8.0</version> </dependency>

Clustering Made Easier: Using Terracotta with Hibernate and/or EHCache