From 1a8fecbe85f66d2995ee9a06c9c20ab5841b11b6 Mon Sep 17 00:00:00 2001 From: moznion Date: Wed, 9 Dec 2020 02:42:18 +0900 Subject: [PATCH] #933: Call `onUnexpectedError()` when unexpected error occurred If a task that are belong to `DefaultRegistrationEngine` raises unexpected `RuntimeException` and the `observer` member variable implements `LwM2mClientObserver2` (instead of `LwM2mClientObserver`), it calls `LwM2mClientObserver2#onUnexpectedError()` hook. The purpose of this hook gimmick is to shutdown the client application mainly. Signed-off-by: moznion --- .../client/engine/DefaultRegistrationEngine.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/leshan-client-core/src/main/java/org/eclipse/leshan/client/engine/DefaultRegistrationEngine.java b/leshan-client-core/src/main/java/org/eclipse/leshan/client/engine/DefaultRegistrationEngine.java index e26b70a964..5e0efa56b7 100644 --- a/leshan-client-core/src/main/java/org/eclipse/leshan/client/engine/DefaultRegistrationEngine.java +++ b/leshan-client-core/src/main/java/org/eclipse/leshan/client/engine/DefaultRegistrationEngine.java @@ -32,6 +32,7 @@ import org.eclipse.leshan.client.RegistrationUpdate; import org.eclipse.leshan.client.bootstrap.BootstrapHandler; import org.eclipse.leshan.client.observer.LwM2mClientObserver; +import org.eclipse.leshan.client.observer.LwM2mClientObserver2; import org.eclipse.leshan.client.request.LwM2mRequestSender; import org.eclipse.leshan.client.resource.LwM2mObjectEnabler; import org.eclipse.leshan.client.resource.LwM2mObjectTree; @@ -517,6 +518,9 @@ public void run() { LOG.info("Bootstrap task interrupted. "); } catch (RuntimeException e) { LOG.error("Unexpected exception during bootstrap task", e); + if (observer instanceof LwM2mClientObserver2) { + ((LwM2mClientObserver2) observer).onUnexpectedError(e); + } } } } @@ -555,6 +559,9 @@ public void run() { LOG.info("Registration task interrupted. "); } catch (RuntimeException e) { LOG.error("Unexpected exception during registration task", e); + if (observer instanceof LwM2mClientObserver2) { + ((LwM2mClientObserver2) observer).onUnexpectedError(e); + } } } } @@ -603,6 +610,9 @@ public void run() { LOG.info("Registration update task interrupted."); } catch (RuntimeException e) { LOG.error("Unexpected exception during update registration task", e); + if (observer instanceof LwM2mClientObserver2) { + ((LwM2mClientObserver2) observer).onUnexpectedError(e); + } } } }