A
Alex M
Can someone post a complete example of how to utilize toplink
distributed cache synchronization with RMI? in Toplink 3.6?
Here's my current problem. I have two applications. One is a web
application, the other a regular java application that synchronously
performs batch operations on the database. The changes the standalone
application makes the the database need to be reflected in the web
application. Both use toplink to connect to the database. I would
like to use cache synchronization to synchronize the toplink cache's
between the two applications.
Going by the documentation given in the example, I end up with the
following. To make the toplink session available to others for
synchronization, I do the following:
private static void publishSession(Server serverSession, String
registryName, NotBoundException e) {
CacheSynchronizationManager syncMgr = new
CacheSynchronizationManager();
serverSession.setCacheSynchronizationManager(syncMgr);
try {
RMIRemoteSessionController controller = new
RMIRemoteSessionControllerDispatcher(serverSession);
syncMgr.setSessionRemoteController(controller);
Naming.rebind(registryName, controller);
} catch (RemoteException e1) {
logger.info("Problems synchronizing session (RMI registry not
available), synchronized caching disabled.");
logger.error(e1.getMessage(), e1);
} catch (MalformedURLException e1) {
logger.info("Problems synchronizing session (URL is malformed),
synchronized caching disabled.");
logger.error(e1.getMessage(), e1);
}
}
To connect to an existing session, I do the following:
private static void connectToExistingSession(Server serverSession,
String registryName) throws NotBoundException, MalformedURLException,
RemoteException {
RMIRemoteSessionController controller =
(RMIRemoteSessionController)Naming.lookup(registryName);
RemoteConnection connection = new RMIConnection(controller);
CacheSynchronizationManager syncMgr = new
CacheSynchronizationManager();
serverSession.setCacheSynchronizationManager(syncMgr);
serverSession.getCacheSynchronizationManager().addRemoteConnection(connection);
}
What I end up with is a ClassCastException generated by the call to
addRemoteConnection:
INTERNAL EXCEPTION: java.lang.ClassCastException
LOCAL EXCEPTION STACK:
EXCEPTION [TOPLINK-0] (3.6.2 JDK1.2):
TOPLink.Public.Remote.CommunicationException
EXCEPTION DESCRIPTION: Error Sending connection service to
INTERNAL EXCEPTION: java.lang.ClassCastException
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnectionForSynchronization(CacheSynchronizationManager.java:84)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnection(CacheSynchronizationManager.java:68)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.connectToExistingSession(SessionServer.java:245)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.synchronizeSession(SessionServer.java:214)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.createServerSession(SessionServer.java:200)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.getSession(SessionServer.java:168)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.acquireUnitOfWork(SessionServer.java:88)
at mojo.km.context.ClientResource.getUnitOfWork(ClientResource.java:70)
at mojo.km.context.ContextManager.getCurrentUnitOfWork(ContextManager.java:508)
at mojo.km.persistence.toplink.Home.findAll(Home.java:113)
at mojo.km.persistence.Home.findAll(Home.java:199)
at pd.oe.dataentry.command.DataEntryCompletionFactory.completeDataEntries(DataEntryCompletionFactory.java:50)
at pd.oe.dataentry.command.CompleteDataEntryCommand.execute(CompleteDataEntryCommand.java:39)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.executeTransaction(TransientEventBroadcaster.java:197)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.fireEvent(TransientEventBroadcaster.java:294)
at mojo.km.context.TopLinkTransactionalContext.TransactionalContextManager.postEvent(TransactionalContextManager.java:61)
at mojo.km.dispatch.CurrentContext.RequestStrategy.postEvent(RequestStrategy.java:27)
at pd.utility.service.AbstractEventDrivenService.postEvent(AbstractEventDrivenService.java:132)
at pd.utility.service.AbstractEventDrivenService.start(AbstractEventDrivenService.java:104)
at mojo.km.context.ContextManager$1.run(ContextManager.java:308)
INTERNAL EXCEPTION STACK:
java.lang.ClassCastException
at TOPLink.Public.Remote.RMI.RMIRemoteSessionControllerDispatcher.addRemoteConnectionForSynchronization(RMIRemoteSessionControllerDispatcher.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at TOPLink.Public.Remote.RMI.RMIRemoteSessionControllerDispatcher_Stub.addRemoteConnectionForSynchronization(RMIRemoteSessionControllerDispatcher_Stub.java:146)
at TOPLink.Public.Remote.RMI.RMIConnection.addRemoteConnectionForSynchronization(RMIConnection.java:46)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnectionForSynchronization(CacheSynchronizationManager.java:82)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnection(CacheSynchronizationManager.java:68)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.connectToExistingSession(SessionServer.java:245)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.synchronizeSession(SessionServer.java:214)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.createServerSession(SessionServer.java:200)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.getSession(SessionServer.java:168)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.acquireUnitOfWork(SessionServer.java:88)
at mojo.km.context.ClientResource.getUnitOfWork(ClientResource.java:70)
at mojo.km.context.ContextManager.getCurrentUnitOfWork(ContextManager.java:508)
at mojo.km.persistence.toplink.Home.findAll(Home.java:113)
at mojo.km.persistence.Home.findAll(Home.java:199)
at pd.oe.dataentry.command.DataEntryCompletionFactory.completeDataEntries(DataEntryCompletionFactory.java:50)
at pd.oe.dataentry.command.CompleteDataEntryCommand.execute(CompleteDataEntryCommand.java:39)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.executeTransaction(TransientEventBroadcaster.java:197)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.fireEvent(TransientEventBroadcaster.java:294)
at mojo.km.context.TopLinkTransactionalContext.TransactionalContextManager.postEvent(TransactionalContextManager.java:61)
at mojo.km.dispatch.CurrentContext.RequestStrategy.postEvent(RequestStrategy.java:27)
at pd.utility.service.AbstractEventDrivenService.postEvent(AbstractEventDrivenService.java:132)
at pd.utility.service.AbstractEventDrivenService.start(AbstractEventDrivenService.java:104)
at mojo.km.context.ContextManager$1.run(ContextManager.java:308)
23:11:56,485 ERROR mojo.km.context.TopLinkTransactionalContext.ExceptionHandler
- OEDataEntry - - Cannot acquire TOPLink unit of work.
EXCEPTION [TOPLINK-0] (3.6.2 JDK1.2):
TOPLink.Public.Remote.CommunicationException
EXCEPTION DESCRIPTION: Error Sending connection service to
INTERNAL EXCEPTION: java.lang.ClassCastException
distributed cache synchronization with RMI? in Toplink 3.6?
Here's my current problem. I have two applications. One is a web
application, the other a regular java application that synchronously
performs batch operations on the database. The changes the standalone
application makes the the database need to be reflected in the web
application. Both use toplink to connect to the database. I would
like to use cache synchronization to synchronize the toplink cache's
between the two applications.
Going by the documentation given in the example, I end up with the
following. To make the toplink session available to others for
synchronization, I do the following:
private static void publishSession(Server serverSession, String
registryName, NotBoundException e) {
CacheSynchronizationManager syncMgr = new
CacheSynchronizationManager();
serverSession.setCacheSynchronizationManager(syncMgr);
try {
RMIRemoteSessionController controller = new
RMIRemoteSessionControllerDispatcher(serverSession);
syncMgr.setSessionRemoteController(controller);
Naming.rebind(registryName, controller);
} catch (RemoteException e1) {
logger.info("Problems synchronizing session (RMI registry not
available), synchronized caching disabled.");
logger.error(e1.getMessage(), e1);
} catch (MalformedURLException e1) {
logger.info("Problems synchronizing session (URL is malformed),
synchronized caching disabled.");
logger.error(e1.getMessage(), e1);
}
}
To connect to an existing session, I do the following:
private static void connectToExistingSession(Server serverSession,
String registryName) throws NotBoundException, MalformedURLException,
RemoteException {
RMIRemoteSessionController controller =
(RMIRemoteSessionController)Naming.lookup(registryName);
RemoteConnection connection = new RMIConnection(controller);
CacheSynchronizationManager syncMgr = new
CacheSynchronizationManager();
serverSession.setCacheSynchronizationManager(syncMgr);
serverSession.getCacheSynchronizationManager().addRemoteConnection(connection);
}
What I end up with is a ClassCastException generated by the call to
addRemoteConnection:
INTERNAL EXCEPTION: java.lang.ClassCastException
LOCAL EXCEPTION STACK:
EXCEPTION [TOPLINK-0] (3.6.2 JDK1.2):
TOPLink.Public.Remote.CommunicationException
EXCEPTION DESCRIPTION: Error Sending connection service to
INTERNAL EXCEPTION: java.lang.ClassCastException
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnectionForSynchronization(CacheSynchronizationManager.java:84)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnection(CacheSynchronizationManager.java:68)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.connectToExistingSession(SessionServer.java:245)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.synchronizeSession(SessionServer.java:214)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.createServerSession(SessionServer.java:200)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.getSession(SessionServer.java:168)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.acquireUnitOfWork(SessionServer.java:88)
at mojo.km.context.ClientResource.getUnitOfWork(ClientResource.java:70)
at mojo.km.context.ContextManager.getCurrentUnitOfWork(ContextManager.java:508)
at mojo.km.persistence.toplink.Home.findAll(Home.java:113)
at mojo.km.persistence.Home.findAll(Home.java:199)
at pd.oe.dataentry.command.DataEntryCompletionFactory.completeDataEntries(DataEntryCompletionFactory.java:50)
at pd.oe.dataentry.command.CompleteDataEntryCommand.execute(CompleteDataEntryCommand.java:39)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.executeTransaction(TransientEventBroadcaster.java:197)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.fireEvent(TransientEventBroadcaster.java:294)
at mojo.km.context.TopLinkTransactionalContext.TransactionalContextManager.postEvent(TransactionalContextManager.java:61)
at mojo.km.dispatch.CurrentContext.RequestStrategy.postEvent(RequestStrategy.java:27)
at pd.utility.service.AbstractEventDrivenService.postEvent(AbstractEventDrivenService.java:132)
at pd.utility.service.AbstractEventDrivenService.start(AbstractEventDrivenService.java:104)
at mojo.km.context.ContextManager$1.run(ContextManager.java:308)
INTERNAL EXCEPTION STACK:
java.lang.ClassCastException
at TOPLink.Public.Remote.RMI.RMIRemoteSessionControllerDispatcher.addRemoteConnectionForSynchronization(RMIRemoteSessionControllerDispatcher.java:43)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:261)
at sun.rmi.transport.Transport$1.run(Transport.java:148)
at sun.rmi.transport.Transport.serviceCall(Transport.java:144)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:534)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:133)
at TOPLink.Public.Remote.RMI.RMIRemoteSessionControllerDispatcher_Stub.addRemoteConnectionForSynchronization(RMIRemoteSessionControllerDispatcher_Stub.java:146)
at TOPLink.Public.Remote.RMI.RMIConnection.addRemoteConnectionForSynchronization(RMIConnection.java:46)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnectionForSynchronization(CacheSynchronizationManager.java:82)
at TOPLink.Public.Remote.CacheSynchronizationManager.addRemoteConnection(CacheSynchronizationManager.java:68)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.connectToExistingSession(SessionServer.java:245)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.synchronizeSession(SessionServer.java:214)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.createServerSession(SessionServer.java:200)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.getSession(SessionServer.java:168)
at mojo.km.context.TopLinkTransactionalContext.SessionServer.acquireUnitOfWork(SessionServer.java:88)
at mojo.km.context.ClientResource.getUnitOfWork(ClientResource.java:70)
at mojo.km.context.ContextManager.getCurrentUnitOfWork(ContextManager.java:508)
at mojo.km.persistence.toplink.Home.findAll(Home.java:113)
at mojo.km.persistence.Home.findAll(Home.java:199)
at pd.oe.dataentry.command.DataEntryCompletionFactory.completeDataEntries(DataEntryCompletionFactory.java:50)
at pd.oe.dataentry.command.CompleteDataEntryCommand.execute(CompleteDataEntryCommand.java:39)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.executeTransaction(TransientEventBroadcaster.java:197)
at mojo.km.context.TopLinkTransactionalContext.TransientEventBroadcaster.fireEvent(TransientEventBroadcaster.java:294)
at mojo.km.context.TopLinkTransactionalContext.TransactionalContextManager.postEvent(TransactionalContextManager.java:61)
at mojo.km.dispatch.CurrentContext.RequestStrategy.postEvent(RequestStrategy.java:27)
at pd.utility.service.AbstractEventDrivenService.postEvent(AbstractEventDrivenService.java:132)
at pd.utility.service.AbstractEventDrivenService.start(AbstractEventDrivenService.java:104)
at mojo.km.context.ContextManager$1.run(ContextManager.java:308)
23:11:56,485 ERROR mojo.km.context.TopLinkTransactionalContext.ExceptionHandler
- OEDataEntry - - Cannot acquire TOPLink unit of work.
EXCEPTION [TOPLINK-0] (3.6.2 JDK1.2):
TOPLink.Public.Remote.CommunicationException
EXCEPTION DESCRIPTION: Error Sending connection service to
INTERNAL EXCEPTION: java.lang.ClassCastException