Skip to content
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

Closed

Conversation

moznion
Copy link
Contributor

@moznion moznion commented Nov 30, 2020

Ref #933

Done

  • Add onUnexpectedErrorOccurred() method to LwM2mClientObserver interface
  • Call LwM2mClientObserver#onUnexpectedErrorOccurred() on DefaultRegistrationEngine when it raises RuntimeException at task loop.
  • Support this error handling system on the client demo project

…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]>
@@ -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));
Copy link
Contributor

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))

Copy link
Contributor Author

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?

Copy link
Contributor

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 ?

Copy link
Contributor Author

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().

Copy link
Contributor

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.

Copy link
Contributor

@sbernard31 sbernard31 Dec 2, 2020

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. 🤔

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at 7e6d029

Comment on lines 901 to 902
myDevice.destroy();
randomTemperatureSensor.destroy();
Copy link
Contributor

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))

Copy link
Contributor Author

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 👍

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe onUnexpectedError is enough ?

Copy link
Contributor Author

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 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed at 16c6cb7

… 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]>
@sbernard31
Copy link
Contributor

sbernard31 commented Dec 7, 2020

I integrated this in master (commits d0f2705, a1bacb5, 1da2600, 7a013f0)

I rewrite history to get more consistent commits.
I fixed a javadoc formatting issue in LwM2mInstanceEnabler.
I change a little bit the last commit by using anonymous class (see 7a013f0), in this commit I also changes LeshanClient.this.destroy(true); to LeshanClient.this.destroy(false); (because I was afraid in some condition that we could face a kind of infinite loop)

Thx @moznion for this new contribution 🙏 !

@sbernard31 sbernard31 closed this Dec 7, 2020
@moznion moznion deleted the 933_unexpected_error_callback branch December 8, 2020 02:09
@moznion
Copy link
Contributor Author

moznion commented Dec 8, 2020

Many thanks for your support, @sbernard31 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants