1

有没有办法处理消息未传递到服务器的情况?海豚日志清楚地了解情况,但我想从代码中捕捉到它。我正在寻找一些方法,例如:onError以覆盖onFinished

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

,但没有这样的。在 try/catch 中包装send调用也不起作用(这并不奇怪,因为 send 没有阻塞它的调用者代码)。

我认为肯定有一些简单的方法可以了解未传递的消息,但我看不到它。谢谢,提前,寻求答案!

4

1 回答 1

1

您可以将 onException 处理程序分配给 ClientConnector - 实际上您应该这样做。异常处理程序将获取异步发送操作中发生的异常对象。

下面是默认的处理程序,它甚至会告诉您应该做什么;-)

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
}
于 2013-10-12T03:37:48.660 回答