Question

Is there way to handle situation when message is not delivered to server? Dolphin log infors about situation clearly, but I'would like to catch it from code. I was looking for some method like: onError to override like onFinished:

clientDolphin.send(message, new OnFinishedHandlerAdapter() {
        @Override
        public void onFinished(List<ClientPresentationModel> presentationModels) {
            // Do something useful
            }
        }
    });

, but there is nothing like that. Also wrapping send call in try/catch does not work(not suprising since send is not blocking its caller code).

I thing there is definitely some easy way to get informed about undelivered message, but I cant see it. Thaks, in advace, for answers!

Was it helpful?

Solution

You can assign an onException handler to the ClientConnector - and you are actually supposed to do so. The exception handler will get the exception object passed in that happened in the asynchronous send action.

Below is the default handler that even tells you, what you should do ;-)

Closure onException = { Throwable up ->
    def out = new StringWriter()
    up.printStackTrace(new PrintWriter(out))
    log.severe("onException reached, rethrowing in UI Thread, consider setting ClientConnector.onException\n${out.buffer}")
    uiThreadHandler.executeInsideUiThread { throw up } // not sure whether this is a good default
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top