In our current project, we have some cases where the client is started too early from another process. We would like: to detect this situation and to react (maybe close the client exe).
1/ Detecting that the server is not available:
Like every project, we have code looking like that in ClientSession#execLoadSession:
@Override
public void execLoadSession() throws ProcessingException {
setServiceTunnel(new ClientHttpServiceTunnel(this, UriUtility.toUrl(getBundle().getBundleContext().getProperty("server.url"))));
//pre-load all known code types
CODES.getAllCodeTypes(m4test.shared.core.Activator.PLUGIN_ID);
setDesktop(new Desktop());
// turn client notification polling on
// getServiceTunnel().setClientNotificationPollInterval(2000L);
}
This produces a stack trace like that:
java.lang.reflect.UndeclaredThrowableException
at com.sun.proxy.$Proxy7.getAllCodeTypeClasses(Unknown Source)
at org.eclipse.scout.rt.client.services.common.code.CodeServiceClientProxy.getAllCodeTypeClasses(CodeServiceClientProxy.java:351)
at org.eclipse.scout.rt.client.services.common.code.CodeServiceClientProxy.getAllCodeTypes(CodeServiceClientProxy.java:372)
at org.eclipse.scout.rt.shared.services.common.code.CODES.getAllCodeTypes(CODES.java:97)
at m4test.client.core.ClientSession.execLoadSession(ClientSession.java:30)
at ...
at org.eclipse.equinox.launcher.Main.main(Main.java:1438)
Caused by: ProcessingException[ProcessingStatus[ERROR code=0 Calling ICodeService.getAllCodeTypeClasses() java.net.ConnectException: Connection refused: connect]]
at org.eclipse.scout.rt.servicetunnel.AbstractServiceTunnel.invokeService(AbstractServiceTunnel.java:115)
at org.eclipse.scout.rt.servicetunnel.http.internal.AbstractInternalHttpServiceTunnel.invokeService(AbstractInternalHttpServiceTunnel.java:130)
at ...
at org.eclipse.scout.rt.servicetunnel.ServiceTunnelInvocationHandler.invoke(ServiceTunnelInvocationHandler.java:48)
... 42 more
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at ...
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Should I catch the UndeclaredThrowableException? I do not think that this is a good practice.
2/ closing the client exe programmatically
When I look at the Exit Menu, it calls:
ClientSyncJob.getCurrentSession(ClientSession.class).stopSession();
But it does'nt seems possible to call stopSession() from the execLoadSession(). It produces a NullPointerException because m_desktop is null:
java.lang.NullPointerException
at org.eclipse.scout.rt.client.AbstractClientSession.stopSession(AbstractClientSession.java:391)
at org.eclipse.scout.rt.client.AbstractClientSession.stopSession(AbstractClientSession.java:379)
at m4test.client.core.ClientSession.execLoadSession(ClientSession.java:22)
at org.eclipse.scout.rt.client.AbstractClientSession$LocalClientSessionExtension.execLoadSession(AbstractClientSession.java:671)
What do you think on these two topics?
Thank you in advance for your help.