Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/JPA/Ehcache"

m (Purpose)
m
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
=Integrating EclipseLink with Terracotta Network Attached Memory=
+
<!--=Integrating EclipseLink with EhCache Network Attached Memory=
<div style="border: 3px red solid;" align="center" ><font color="red">DISCLAIMER: This page reflects investigation into how EclipseLink users can integrate with Terracotta ehcache. It does NOT imply any formal certification that EclipseLink supports the Terracotta API at this time.</font></div>  
+
<div style="border: 3px red solid;" align="center" ><font color="red">DISCLAIMER: This page reflects investigation into how EclipseLink users can integrate with ehcache. It does NOT imply any formal certification that EclipseLink supports the EhCache API at this time.</font></div>  
 
__TOC__
 
__TOC__
  
Line 8: Line 8:
  
 
==Summary==
 
==Summary==
*This document in progress as of 20100326 details how to integrate [http://www.eclipselink.org EclipseLink] with [http://ehcache.org Ehcache].  We will explore both the Ehcache open source version as well as the commercial [http://www.terracotta.org/ Terracotta Inc.] version - (via a TIM - Terracotta Integration Module) into the [http://www.terracotta.org/ Terracotta Inc.] Network Attached Memory ([http://www.theserverside.com/news/thread.tss?thread_id=34294 Distributed JVM-aware ''transparent'' Cache]).
+
*This document in progress as of 20100326 details how to integrate [http://www.eclipselink.org EclipseLink] with [http://ehcache.org Ehcache].  We will explore the Ehcache open source version - see ([http://www.theserverside.com/news/thread.tss?thread_id=34294 Distributed JVM-aware ''transparent'' Cache]).
*The goal of this investigation is to define and publish a procedure on using '''EclipseLink''' as the '''JPA''' provider in a distributed memory application based on '''Terracotta Inc.''' Caching API.
+
*The goal of this investigation is to define and publish a procedure on using '''EclipseLink''' as the '''JPA''' provider in a distributed memory application based on the '''EhCache''' Caching API.
*The motivation of this work is in learning and leveraging '''ehcache'' from ''Terracotta Inc.'' and details/issues of the technical space surrounding distributing caching in general as described in the paper on the new Java5 memory model by [http://portal.acm.org/author_page.cfm?id=81100057068&query=%28Author%3A81100057068%29%20&querydisp=%28Author%3A81100057068%29%20&role=Author&perpage=10&start=21&srt=meta%5Fpublished%5Fdate%20dsc&short=0&source_disp=&since_month=&since_year=&before_month=&before_year=&coll=GUIDE&dl=GUIDE&termshow=matchboolean&range_query=&CFID=82106317&CFTOKEN=18944184 William Pugh] - [http://portal.acm.org/citation.cfm?doid=1040305.1040336 The Java Memory Model].
+
*The motivation of this work is in learning and leveraging the '''ehcache''' 2nd level cache API, and investigating details/issues of the technical space surrounding distributing caching in general as described in the paper on the new Java5 memory model by [http://portal.acm.org/author_page.cfm?id=81100057068&query=%28Author%3A81100057068%29%20&querydisp=%28Author%3A81100057068%29%20&role=Author&perpage=10&start=21&srt=meta%5Fpublished%5Fdate%20dsc&short=0&source_disp=&since_month=&since_year=&before_month=&before_year=&coll=GUIDE&dl=GUIDE&termshow=matchboolean&range_query=&CFID=82106317&CFTOKEN=18944184 William Pugh] - [http://portal.acm.org/citation.cfm?doid=1040305.1040336 The Java Memory Model].
 
*I am interested in the following...
 
*I am interested in the following...
 
**Use as a JVM bridge, or JVM agnostic application (IE: Mixed J9, SUN, JRockit implementations)
 
**Use as a JVM bridge, or JVM agnostic application (IE: Mixed J9, SUN, JRockit implementations)
Line 22: Line 22:
 
*We will attempt to keep all software open-source if possible.
 
*We will attempt to keep all software open-source if possible.
 
====Setup Cluster====
 
====Setup Cluster====
*We are using 3 P4-630 32 bit machines and 1 Corei7 64 bit machine.
+
*We are using 2 P4-630 32 bit machines, 1 E8400 and 1 Core i7 64 bit machine.
 +
*Our cluster similations will run on an existing set of 4 machines of varying capability that run on a private subnet accessible from the dual networked PC1 via remote desktop
 +
=====PC1:xps435: Windows 7 64-bit 8 core Intel i7-920=====
 +
*192.168.0.194
 +
=====PC2:mfobrien-pc2: Windows XP 32-bit 2 core Intel E8400=====
 +
*192.168.0.191
 +
=====PC3:beowulf5: Windows XP 32-bit 2 core Intel P630=====
 +
*192.168.0.165
 +
=====PC4:beowulf6: Windows XP 32-bit 2 core Intel P630=====
 +
*192.168.0.166
 +
 
 
====Install Eclipse EE====
 
====Install Eclipse EE====
 
*We are using Eclipse 3.5 Galileo EE edition (32 bit).
 
*We are using Eclipse 3.5 Galileo EE edition (32 bit).
Line 32: Line 42:
 
====Install JPA provider====
 
====Install JPA provider====
 
*We will be using EclipseLink 2.0 (the JEE6 RI) that is shipped with GlassFish.
 
*We will be using EclipseLink 2.0 (the JEE6 RI) that is shipped with GlassFish.
====Install Terracotta====
+
====Install EhCache====
*Download [http://www.terracotta.org/dl/oss-download-catalog Terracotta 3.2.1 open source version] or use your own enterprise version of Terracotta
+
-->
 +
<!--*Download [http://www.terracotta.org/dl/oss-download-catalog Terracotta 3.2.1 open source version] or use your own enterprise version of Terracotta
 
*I installed to '''c:/opt/terracotta321''' by running the executable ''terracotta-3.2.1-installer.jar''.
 
*I installed to '''c:/opt/terracotta321''' by running the executable ''terracotta-3.2.1-installer.jar''.
 
*Follow instructions in ''INSTALL.TXT''.
 
*Follow instructions in ''INSTALL.TXT''.
Line 41: Line 52:
 
*You should see the following screen...
 
*You should see the following screen...
 
[[Image:Terracotta_321_developer_console_cap.JPG]]
 
[[Image:Terracotta_321_developer_console_cap.JPG]]
 
+
-->
 +
<!--
 
==Design Issues==
 
==Design Issues==
 
==Open Issues==
 
==Open Issues==
 +
==Other Distributed Caches==
 +
*We will investigate other various levels of networking scenarios that link our distributed JVM nodes.
 +
===Base Case 1: Custom Distributed RMI===
 +
*Using RMI via for example the '''t3''' protocol is not recommended for production enterprise applications - we describe a simple use case here only for historical reference.
 +
====EE Distributed Session Bean====
 +
*Deploy this on each of your WebLogic servers
 +
<source lang="java">
 +
@Stateful(mappedName="ejb/Node")
 +
@Local
 +
public class Node implements NodeRemote, NodeLocal {
 +
    private int transition;
 +
    private int state;
 +
       
 +
    public void setState(int aState) {
 +
        System.out.println("_Distributed: new state: " + aState);
 +
        state = aState;
 +
    }
 +
   
 +
    public int getState() {
 +
        return state;
 +
    }
 +
   
 +
    public int getAdjacent(int offsetX, int offsetY) {
 +
        return 1;       
 +
    }
 +
}
 +
 +
@Remote
 +
public interface NodeRemote {
 +
    //####<15-Sep-2010 1:21:15 o'clock PM EDT> <Info> <EJB> <xps435> <AdminServer> <[STANDBY] ExecuteThread: '5' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1284571275760> <BEA-010009>
 +
    //<EJB Deployed EJB with JNDI name org_eclipse_persistence_example_distributed_ClientEARorg_eclipse_persistence_example_distributed_ClientEJB_jarNode_Home.>
 +
    public void setState(int state);
 +
    public int getState();
 +
    public int getAdjacent(int offsetX, int offsetY);
 +
}
 +
 +
</source>
 +
====SE client====
 +
*Run this on one of the servers or a separate SE JVM
 +
<source lang="java">
 +
package org.eclipse.persistence.jmx;
 +
 +
import java.util.ArrayList;
 +
import java.util.HashMap;
 +
import java.util.Hashtable;
 +
import java.util.List;
 +
import java.util.Map;
 +
 +
import javax.naming.Context;
 +
import javax.naming.InitialContext;
 +
import javax.rmi.PortableRemoteObject;
 +
 +
import org.eclipse.persistence.example.distributed.NodeRemote;
 +
 +
/**
 +
* This class tests RMI connections to multiple WebLogic servers running on
 +
* remote JVM's.  It is intended for experimental concurrency investigations only.
 +
* @author mfobrien 20100916
 +
*
 +
*/
 +
public class JNDIClient {
 +
    public static final List<String> serverNames = new ArrayList<String>();
 +
   
 +
    private Map<String, Hashtable<String, String>> contextMap = new HashMap<String, Hashtable<String, String>>();
 +
    private Map<String, Context> rmiContextMap = new HashMap<String, Context>();   
 +
    private Map<String, NodeRemote> remoteObjects = new HashMap<String, NodeRemote>();   
 +
    private Map<String, Integer> stateToSet = new HashMap<String, Integer>();
 +
    private static Map<String, String>  serverIPMap = new HashMap<String, String>();
 +
   
 +
    private static final String CONTEXT_FACTORY_NAME = "weblogic.jndi.WLInitialContextFactory";
 +
    private static final String SESSION_BEAN_REMOTE_NAME = "ejb/Node#org.eclipse.persistence.example.distributed.NodeRemote";
 +
    //private String sessionBeanRemoteName = "java:comp/env/ejb/Node"; // EE only
 +
    //private String sessionBeanRemoteName = "org_eclipse_persistence_example_distributed_ClientEARorg_eclipse_persistence_example_distributed_ClientEJB_jarNode_Home" ;
 +
 +
    /**
 +
    * For each server add the name key and corresponding RMI URL
 +
    */
 +
    static {
 +
        // Beowulf5 on Cat6 1Gb/Sec
 +
        serverNames.add("beowulf5");
 +
        serverIPMap.put("beowulf5", "t3://192.168.0.165:7001");
 +
        // Beowulf6 on Cat6 1Gb/Sec
 +
        serverNames.add("beowulf6");
 +
        serverIPMap.put("beowulf6", "t3://192.168.0.166:7001");
 +
    }
 +
 +
    public JNDIClient() {
 +
    }
 +
   
 +
    public void connect() {
 +
        /**
 +
        * Note: only import weblogic.jar and naming.jar
 +
        */
 +
        // For JNDI we are forced to use Hashtable instead of HashMap
 +
        // populate the hashtables
 +
        for(String aServer : serverNames) {
 +
            Hashtable<String, String> aTable =  new Hashtable<String, String>();
 +
            contextMap.put(aServer,aTable);
 +
            aTable.put(Context.INITIAL_CONTEXT_FACTORY,CONTEXT_FACTORY_NAME);
 +
            aTable.put(Context.PROVIDER_URL, serverIPMap.get(aServer));
 +
        }
 +
 +
        /**
 +
        * Setup and connect to RMI Objects
 +
        */
 +
        try {           
 +
            // Establish RMI connections to the session beans
 +
            for(String aServer : serverNames) {
 +
                Context aContext = new InitialContext(contextMap.get(aServer));
 +
                rmiContextMap.put(aServer, aContext);
 +
                System.out.println("Context for " + aServer + " : " + aContext);
 +
                // For qualified name look for weblogic log "EJB Deployed EJB with JNDI name"
 +
                Object aRemoteReference = aContext.lookup(SESSION_BEAN_REMOTE_NAME);       
 +
                System.out.println("Remote Object: " + aRemoteReference);       
 +
                NodeRemote aNode = (NodeRemote) PortableRemoteObject.narrow(aRemoteReference, NodeRemote.class);
 +
                remoteObjects.put(aServer, aNode);
 +
                System.out.println("Narrowed Session Bean: " + aNode);       
 +
                // initialize state list
 +
                stateToSet.put(aServer, new Integer(0));
 +
            }
 +
           
 +
            NodeRemote aNode;
 +
            StringBuffer aBuffer = new StringBuffer();         
 +
            // Endlessly generate RMI requests
 +
            for(;;) {
 +
                // Send messages to entire grid in parallel
 +
                for(String remoteServer : remoteObjects.keySet()) {
 +
                    aNode = remoteObjects.get(remoteServer);
 +
                    // increment server's pending state
 +
                    stateToSet.put(remoteServer, stateToSet.get(remoteServer).intValue() + 1);
 +
                    aNode.setState(stateToSet.get(remoteServer));
 +
                    aBuffer = new StringBuffer("State from: ");
 +
                    aBuffer.append(remoteServer);
 +
                    aBuffer.append(" = ");
 +
                    aBuffer.append(aNode.getState());                 
 +
                    System.out.println(aBuffer.toString());
 +
                }
 +
            }
 +
        } catch (Exception e) {
 +
            e.printStackTrace();
 +
        }
 +
    }
 +
   
 +
    public static void main(String[] args) {
 +
        JNDIClient client = new JNDIClient();
 +
        client.connect();
 +
    }
 +
}
 +
</source>
 +
 +
===OTS 1: EclipseLink Cache Coordination===
 +
===OTS 2: TopLink Grid (uses Coherence)===
 +
*We will investigate using Oracle Coherence as a distributed 2nd level cache.  Before we start we will verify the Coherence install that ships with certain versions of WebLogic (before using it from our JPA application).
 +
====Coherence Quickstart====
 +
*Here we verify Coherence 3.6 by installing and running the Coherence example installed as an option in the WebLogic server 11gR1 install.
 +
=====Distributed Coherence Cache Example - 4 caches=====
 +
*In the following image we see the messaging that occurs '''out-of-the-box''' via cache discovery when running Coherence on multiple distributed JVM's on different machines.
 +
**We start the nodes in the following order 192.168.0.'''194''',192.168.0.'''191''',192.168.0.'''166''',192.168.0.'''165''',
 +
*See '''$WEBLOGIC_HOME\coherence_3.6\examples\java\bin'''
 +
*[[Image:Coherence_4_caches_infinite_message_loop_3_57.JPG]]
  
 
==References==
 
==References==
 +
*[http://bugs.eclipse.org/219683 219683]: Design and Implement Interception points in EclipseLink - In EclipseLink 1.0 (2008)
 
*[http://www.oracle.com/technology/products/ias/toplink/tl_grid.html Oracle TopLink Grid - A Coherence based distributed shared (L2) cache that integrates with EclipseLink JPA]
 
*[http://www.oracle.com/technology/products/ias/toplink/tl_grid.html Oracle TopLink Grid - A Coherence based distributed shared (L2) cache that integrates with EclipseLink JPA]
 
*[http://forums.java.net/jive/message.jspa?messageID=370411 Terracotta + GlassFish + EclipseLink]
 
*[http://forums.java.net/jive/message.jspa?messageID=370411 Terracotta + GlassFish + EclipseLink]
Line 53: Line 226:
 
*[http://forums.terracotta.org/forums/posts/list/2227.page Terracotta forum post - integration request 20090614] Spring EclipseLink
 
*[http://forums.terracotta.org/forums/posts/list/2227.page Terracotta forum post - integration request 20090614] Spring EclipseLink
 
*[http://forums.terracotta.org/forums/posts/list/2230.page Terracotta forum post - integration request 20090616] Custom ClassLoader
 
*[http://forums.terracotta.org/forums/posts/list/2230.page Terracotta forum post - integration request 20090616] Custom ClassLoader
*[https://jira.terracotta.org/jira/browse/CDV-1088 Eclipselink coordinated cache integration] - 20081221 New TIM (Terracotta Integration Module)
+
-->
*[http://old.nabble.com/Eclipselink-coordinated-cache-integration-with-Terracotta.-td21116004.html EclipseLink coordinated cache integration with Terracotta 20081221] - request
+
<!--*[https://jira.terracotta.org/jira/browse/CDV-1088 Eclipselink coordinated cache integration] - 20081221 New TIM (Terracotta Integration Module)-->
 +
<!--*[http://old.nabble.com/Eclipselink-coordinated-cache-integration-with-Terracotta.-td21116004.html EclipseLink coordinated cache integration with Terracotta 20081221] - request
 
*See Chapter 6 p.131 of [http://books.google.com/books?id=HhvDpoLaGCoC&pg=PA131&lpg=PA131&dq=terracotta+toplink&source=bl&ots=Bn30silGwT&sig=asQWRbM7f7xg-vlKfic5guRpMQ4&hl=en&ei=_CKtS_6eE4_esgPhi6S6DA&sa=X&oi=book_result&ct=result&resnum=8&ved=0CCUQ6AEwBw#v=onepage&q=terracotta%20toplink&f=false "Terracotta - Cluster the JVM for Spring, Hibernate and POJO Scalability"] - available from Apress.
 
*See Chapter 6 p.131 of [http://books.google.com/books?id=HhvDpoLaGCoC&pg=PA131&lpg=PA131&dq=terracotta+toplink&source=bl&ots=Bn30silGwT&sig=asQWRbM7f7xg-vlKfic5guRpMQ4&hl=en&ei=_CKtS_6eE4_esgPhi6S6DA&sa=X&oi=book_result&ct=result&resnum=8&ved=0CCUQ6AEwBw#v=onepage&q=terracotta%20toplink&f=false "Terracotta - Cluster the JVM for Spring, Hibernate and POJO Scalability"] - available from Apress.
  
 
==External Documentation==
 
==External Documentation==
* [http://www.terracotta.org/documentation/ga/product-documentation Terracotta 3.2.1 Documentation]
+
-->
* [http://www.terracotta.org/documentation/ga/product-documentation-12.html#394977848_pgfId-998335 Clustering Spring Framework with Terracotta]
+
<!--* [http://www.terracotta.org/documentation/ga/product-documentation Terracotta 3.2.1 Documentation]-->
 +
<!--* [http://www.terracotta.org/documentation/ga/product-documentation-12.html#394977848_pgfId-998335 Clustering Spring Framework with Terracotta]
 
* [http://www.terracotta.org/documentation/ga/product-documentation-5.html#50491436_87896 Terracotta Distributed Ehcache for Hibernate Express Installation]
 
* [http://www.terracotta.org/documentation/ga/product-documentation-5.html#50491436_87896 Terracotta Distributed Ehcache for Hibernate Express Installation]
 +
-->

Latest revision as of 21:34, 2 November 2010


Back to the top