|
Re: [CDO] recover from lost connection [message #660489 is a reply to message #660464] |
Fri, 18 March 2011 15:46 |
Victor Roldan Betancort Messages: 524 Registered: July 2009 |
Senior Member |
|
|
Sebastian,
please take a look at ReconnectingCDOSessionConfiguration.
org.eclipse.emf.cdo.net4j.ReconnectingCDOSessionConfiguratio n
org.eclipse.emf.cdo.net4j.CDONet4jUtil.createReconnectingSes sionConfiguration(String,
String, IManagedContainer)
Haven't tried it, but seems what your looking for ;)
Cheers,
Víctor.
Sebastian Paul escribió:
> Hi,
> I am investigating how CDO can handle instable connections. For this, I
> wrote a small test which starts a TCP proxy. The CDO connection is
> routed through this proxy. Stopping the proxy simulates a lost connection.
>
> LOGGER.debug("starting proxy");
> startProxy();
>
> LOGGER.debug("creating session");
> final CDOSession session = createSession(TCP_PROXY_URI);
> try {
> LOGGER.debug("stopping proxy (simulate disconnect)");
> stopProxy();
> Thread.sleep(1000);
> LOGGER.debug("restarting proxy (simulate reconnect)");
> startProxy();
> LOGGER.debug("reactivate session (recover from lost connection)");
> LifecycleUtil.activate(session);
> LOGGER.debug("refreshing object caches");
> session.refresh();
> }
> finally {
> session.close();
> stopProxy();
> }
>
>
> However, trying to reactivate the sessin fails with
> org.eclipse.net4j.channel.ChannelException: java.lang.NullPointerException
> at
> org.eclipse.spi.net4j.ChannelMultiplexer.openChannel(Channel Multiplexer.java:171)
>
> at
> org.eclipse.spi.net4j.ChannelMultiplexer.openChannel(Channel Multiplexer.java:1)
>
> at
> org.eclipse.net4j.signal.failover.NOOPFailOverStrategy.handl eOpen(NOOPFailOverStrategy.java:53)
>
> at org.eclipse.net4j.signal.SignalProtocol.open(SignalProtocol. java:169)
> at
> org.eclipse.emf.cdo.internal.net4j.protocol.CDOClientProtoco l.openSession(CDOClientProtocol.java:91)
>
> at
> org.eclipse.emf.cdo.internal.net4j.CDONet4jSessionConfigurat ionImpl.activateSession(CDONet4jSessionConfigurationImpl.jav a:216)
>
> at
> org.eclipse.emf.internal.cdo.session.CDOSessionImpl.doActiva te(CDOSessionImpl.java:999)
>
> at org.eclipse.net4j.util.lifecycle.Lifecycle.activate(Lifecycl e.java:72)
> at
> org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(Life cycleUtil.java:98)
>
> at
> org.eclipse.net4j.util.lifecycle.LifecycleUtil.activate(Life cycleUtil.java:88)
>
> ...
>
> When skipping the reactivation, any operation on the session quits with
> the error
> java.lang.IllegalStateException: Not active: CDOSession[cmtmem, 77]
> at
> org.eclipse.net4j.util.lifecycle.LifecycleUtil.checkActive(L ifecycleUtil.java:71)
>
> at
> org.eclipse.net4j.util.lifecycle.Lifecycle.checkActive(Lifec ycle.java:190)
> at
> org.eclipse.emf.internal.cdo.session.CDOSessionImpl.refresh( CDOSessionImpl.java:505)
>
> ...
>
>
> So what is the correct way to handle this? Is it possible to have this
> done automagically?
>
|
|
|
|
|
Re: [CDO] recover from lost connection [message #662100 is a reply to message #660535] |
Tue, 29 March 2011 09:55 |
Sebastian Paul Messages: 106 Registered: July 2009 |
Senior Member |
|
|
Hi,
now I have got the time for testing this with CDO 4.0, with partial success:
public void testConnectionLostWithRecovery() throws Exception {
LOGGER.debug("creating session");
final CDOSession session = createReconnectingSession();
try {
LOGGER.debug("stopping proxy (simulate disconnect)");
tcpProxy.stop();
LOGGER.debug("restarting proxy (simulate reconnect)");
tcpProxy.start();
LOGGER.debug("refreshing object caches");
session.refresh();
}
finally {
session.close();
}
}
public void testTransactionWithLostConnectionAndRecovery() throws
Exception {
LOGGER.debug("creating session");
final CDOSession session = createReconnectingSession();
try {
LOGGER.debug("opening transaction");
final CDOTransaction transaction = session.openTransaction();
LOGGER.debug("modifying resource");
final CDOResource resource =
transaction.getOrCreateResource(CDO_RESOURCE_PATH);
resource.getContents().add(createContent());
LOGGER.debug("stopping proxy (simulate disconnect)");
tcpProxy.stop();
LOGGER.debug("restarting proxy (simulate reconnect)");
tcpProxy.start();
LOGGER.debug("committing transaction");
transaction.commit();
}
finally {
session.close();
}
}
private CDOSession createReconnectingSession() {
final String hostAndPort = TCP_PROXY_URI.getHost() + ':' +
TCP_PROXY_URI.getPort();
final Path path = new Path(TCP_PROXY_URI.getPath());
final String repoName = path.segment(0);
final IManagedContainer container =
org.eclipse.net4j.internal.util.container.PluginContainer.ge tInstance();
final CDOSessionConfiguration sessionConfiguration =
CDONet4jUtil.createReconnectingSessionConfiguration(hostAndP ort,
repoName, container);
final CDOSession session = sessionConfiguration.openSession();
return session;
}
The test "testConnectionLostWithRecovery" succeeds.
But the test "testTransactionWithLostConnectionAndRecovery" fails:
org.eclipse.emf.cdo.util.CommitException: java.lang.NullPointerException
at
org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl. commit(CDOTransactionImpl.java:1067)
at
org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl. commit(CDOTransactionImpl.java:1073)
at ITCdoConnection.testTransactionWithLostConnectionAndRecovery
....
Maybe my session configuration is wrong?
I am wondering about the IManagedContainer which I have to provide to
CDONet4jUtil#createReconnectingSessionConfiguration. Currently I am
accessing internal API. What is the correct way to get an instance?
Am 2011-03-18 23:52, schrieb Eike Stepper:
> Hi Sebastian,
>
> I recall someone else has tried to backport our respective code from
> 4.0. And failed :P
>
> It's not a trivial undertaking and I think you'd be better served with
> CDO 4.0.
>
> Cheers
> /Eike
>
> ----
> http://www.esc-net.de
> http://thegordian.blogspot.com
> http://twitter.com/eikestepper
>
>
> Am 18.03.2011 17:22, schrieb Sebastian Paul:
>> Am 2011-03-18 16:46, schrieb Víctor Roldán Betancort:
>>> please take a look at ReconnectingCDOSessionConfiguration.
>>
>> Hi, thanks for the hint. I forgot to mention that I am using the
>> latest stable release of CDO, which is 3.0.1. As I cannot find the
>> type in my workspace, I guess it will be introduced in CDO 4.0.
>>
>> So I have to change my question and ask "How can I recover from a lost
>> connection in CDO 3.x" ;)
>>
>> Kind regards, Sebastian
--
Best regards,
Sebastian Paul
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04022 seconds