Hi all,
I have finally got it to work on weblogic 10.3. In this post I am going to give a detailed picture of what I did to get cache coordination through EclipseLink to work in an ejb application running on Oracle Weblogic 10.3.
Weblogic Configurations:
The admin server of weblogic runs on 7001 port. I created 2 managed servers through the weblogic console called server1 and server2. I created a machine called Machine0 and linked both server1 and server2 to Machine0 all in the console. Weblogic console also allows you to create a cluster, but it did NOT work for me when I created a cluster and associated server1 and server2 with the cluster. I created a datasource and attached it to server1 and server2. The main thing to remember here is that you create 2 managed servers and do not associate them with any cluster and just run them independently.
EclipseLink Configurations:
With an ejb app I had used annotations in my business objects (POJOS) and I had a persistence.xml file so I could not use a sessions.xml file to specify cache coordination settings. I created a custom session customizer by implementing SessionCustomizer. The code of my custom session customizer is as follows:
public class EclipseLinkSessionCustomizer implements SessionCustomizer {
public void customize(Session session) throws Exception {
RemoteCommandManager rcm = new RemoteCommandManager((DatabaseSessionImpl)session);
((DatabaseSessionImpl)session).setShouldPropagateChanges(true);
((DatabaseSessionImpl)session).setCommandManager(rcm);
rcm.setShouldPropagateAsynchronously(false);
((DatabaseSessionImpl)session).getCommandManager().getDiscoveryManager().setAnnouncementDelay(1000);
((DatabaseSessionImpl)session).getCommandManager().getDiscoveryManager().setMulticastGroupAddress("226.10.12.64");
((DatabaseSessionImpl)session).getCommandManager().getDiscoveryManager().setMulticastPort(3121);
((DatabaseSessionImpl)session).getCommandManager().getDiscoveryManager().setPacketTimeToLive(5);
rcm.getTransportManager().setNamingServiceType(TransportManager.JNDI_NAMING_SERVICE);
rcm.setUrl("t3://$HOST:7011"); // Use port 7011 for server1 and 7021 for server2
rcm.getTransportManager().setUserName("weblogic");
rcm.getTransportManager().setPassword("weblogic");
rcm.getTransportManager().setInitialContextFactoryName("weblogic.jndi.WLInitialContextFactory");
rcm.getTransportManager().setShouldRemoveConnectionOnError(true);
rcm.setServerPlatform(((org.eclipse.persistence.sessions.DatabaseSession)session).getServerPlatform());
rcm.initialize();
try {
Thread.sleep(2000);
} catch(Exception ex) {
ex.printStackTrace();
}
}
}
persistence.xml:
<?xml version="1.0" encoding="windows-1252" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="default" transaction-type="JTA">
<provider>
org.eclipse.persistence.jpa.PersistenceProvider
</provider>
<jta-data-source>BasicDS</jta-data-source>
<class>
com.talapala.library.objects.User
</class>
<class>
com.talapala.library.objects.Book
</class>
<class>
com.talapala.library.objects.Genre
</class>
<class>
com.talapala.library.objects.UserAccount
</class>
<properties>
<property name="eclipselink.target-server" value="WebLogic"/>
<property name="eclipselink.validate-existence" value="true"/>
<property name="eclipselink.logging.level" value="FINEST"/>
<property name="eclipselink.target-database" value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
<property name="javax.persistence.jtaDataSource" value="java:/app/jdbc/BasicDS"/>
<property name="eclipselink.application-location" value="."/>
<property name="eclipselink.ddl-generation.output-mode" value="both"/>
<property name="eclipselink.jdbc.driver" value="oracle.jdbc.OracleDriver"/>
<property name="eclipselink.jdbc.url" value="jdbc:oracle:thin:@10.178.139.99:1521:XE"/>
<property name="eclipselink.session.customizer" value="com.talapala.library.eclipselink.EclipseLinkSessionCustomizer"/>
</properties>
</persistence-unit>
</persistence>
I created 2 ears one which i deployed in server1 and another in server2. Please note that the only change in the 2 ears is the port number changes in the custom session customizer file (7011 for server1 and 7021 for server2).
I started my application from server1 in one web browser window and did an operation which queries the db gets an object changes something in the object and persists it back in the db. I opened another browser window stated app from server 2 and did the same operation. In the server logs of server 1 and server2 you can see the cache coordination messages as follows:
[EL Finer]: 2008.12.11 13:05:26.953--ServerSession(5286698)--Thread(Thread[Thread-12,5,Pooled Threads])--RCM service announcement received from Service[TopLinkCommandChannel, 4be734db-b016-485d-80e0-acde8a485699, t3://10.178.139.99:7021]
[EL Finest]: 2008.12.11 13:05:26.953--ServerSession(5286698)--Thread(Thread[Thread-12,5,Pooled Threads])--Looking up remote connection in JNDI under name 4be734db-b016-485d-80e0-acde8a485699 at URL t3://10.178.139.99:7021
[EL Finest]: 2008.12.11 13:05:26.953--ServerSession(5286698)--Thread(Thread[Thread-12,5,Pooled Threads])--Remote context properties: {java.naming.provider.url=t3://10.178.139.99:7021, java.naming.factory.initial=weblogic.jndi.WLInitialContextFactory, java.naming.security.principal=weblogic, dedicated.connection=true, java.naming.security.credentials=F44034A2DD8158AE77C605B1A51E3B46}
[EL Finest]: 2008.12.11 13:05:27.094--ServerSession(5286698)--Thread(Thread[Thread-12,5,Pooled Threads])--Received remote connection from Service[TopLinkCommandChannel, 4be734db-b016-485d-80e0-acde8a485699, t3://10.178.139.99:7021]
[EL Finest]: 2008.12.11 13:05:30.375--ServerSession(5286698)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Received remote command org.eclipse.persistence.sessions.coordination.MergeChangeSetCommand from Service[TopLinkCommandChannel, 4be734db-b016-485d-80e0-acde8a485699, t3://10.178.139.99:7021]
[EL Finest]: 2008.12.11 13:05:30.375--ServerSession(5286698)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Executing command org.eclipse.persistence.sessions.coordination.MergeChangeSetCommand from Service[TopLinkCommandChannel, 4be734db-b016-485d-80e0-acde8a485699, t3://10.178.139.99:7021]
[EL Finer]: 2008.12.11 13:05:30.375--ServerSession(5286698)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Received updates from Remote Server
[EL Finest]: 2008.12.11 13:05:30.375--ServerSession(5286698)--Thread(Thread[[ACTIVE] ExecuteThread: '1' for queue: 'weblogic.kernel.Default (self-tuning)',5,Pooled Threads])--Merging com.talapala.library.objects.Book: [12] from remote server
I hope this post helps people who are stuck in making cache coordination work through RMI in EclipseLink. I would like to thank Prabaharan Vijayaratnam, who helped me figure this stuff out.
Regards,
Prashanth.