-
Notifications
You must be signed in to change notification settings - Fork 408
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callback mechanism into LwM2mClientObserver for when the unexpected error occurred #941
Add callback mechanism into LwM2mClientObserver for when the unexpected error occurred #941
Conversation
…2mClientObserver Add an interface method `void onUnexpectedErrorOccurred(Throwable unexpectedError)` into LwM2mClientObserver. This aims to hook a procedure when an unexpected error has been occurred. Signed-off-by: moznion <[email protected]>
…ngine` Call `LwM2mClientObserver#onUnexpectedErrorOccurred()` on `DefaultRegistrationEngine` when it raises `RuntimeException` at task loop. Signed-off-by: moznion <[email protected]>
…r has occurred Signed-off-by: moznion <[email protected]>
@@ -745,6 +748,9 @@ public void handshakeFailed(Handshaker handshaker, Throwable error) { | |||
builder.setBootstrapAdditionalAttributes(bsAdditionalAttributes); | |||
final LeshanClient client = builder.build(); | |||
|
|||
client.addObserver( | |||
new ClientShutdownOnUnexpectedErrorObserver(client, myDevice, randomTemperatureSensor)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done on LeshanClient
not LeshanClientDemo
or I missed something ?
(#933 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's a point. I think it would be better to implement this shutdown observer mechanism on LeshanClient
, but it breaks the backward compatibility of the client, so I delegated this behavior to the client of the client.
What do you think about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For master
, we don't care about backward compatibility question and should just focus on what could be the better behavior. (of course this doesn't mean we can break everything without any reason 😅 )
For 1.x
, we should try to not break the API and behavior but here we could almost consider this as a bug ... so changing this behavior doesn't disturb me.
WDYT ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I'm on the same page.
I also think it would be better to implement this on the LeshanClient.
I was scared to break the backward compatibility way too much, but it seems no problem. I'll do this.
One more thing. Would it useful to support a method to prevent shutting down even if an unexpected error has occurred on the LeshanClient? For example LeshanClient#doNotDestroyOnUnexpectedError()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not add it for now. Let's see if someone need it later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't see what could be the use case. As tasks in DefaultRegistrationEngine
are stopped. 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, my suggestion was for just in case. It looks there is no reason to support that. Thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at 7e6d029
myDevice.destroy(); | ||
randomTemperatureSensor.destroy(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to do the same Lwm2mInstanceEnabler
should also implement (startable, stopable, destroyable)
And Object enabler should do pretty much the same as "LwM2mObjectTree" by interating over instance. (see #933 (comment))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good. I'll do this 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at 3f73020
|
||
// ============== Unexpected Error Handling ================= | ||
|
||
void onUnexpectedErrorOccurred(Throwable unexpectedError); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe onUnexpectedError
is enough ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the advice, I've not had confidence in this honestly :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed at 16c6cb7
…rror/g Signed-off-by: moznion <[email protected]>
… ObjectEnabler To call `LwM2mInstanceEnabler#stop()`, `LwM2mInstanceEnabler#start()` and `LwM2mInstanceEnabler#destroy()` on the associated method, for each enabler if implemented the interface. Signed-off-by: moznion <[email protected]>
…shanClient Instead of on `LeshanClientDemo` Signed-off-by: moznion <[email protected]>
Signed-off-by: moznion <[email protected]>
I integrated this in master (commits d0f2705, a1bacb5, 1da2600, 7a013f0) I rewrite history to get more consistent commits. Thx @moznion for this new contribution 🙏 ! |
Many thanks for your support, @sbernard31 ! |
Ref #933
Done
onUnexpectedErrorOccurred()
method toLwM2mClientObserver
interfaceLwM2mClientObserver#onUnexpectedErrorOccurred()
onDefaultRegistrationEngine
when it raisesRuntimeException
at task loop.