Skip to content

Commit

Permalink
#933: Add an interface LwM2mClientObserver2 to handle unexpected error
Browse files Browse the repository at this point in the history
This interface extends `LwM2mClientObserver` interface.
And make `LwM2mClientObserverAdapter` and
`LwM2mClientObserverDispatcher`
implement that new interface.
This doesn't break the backward compatibility because
`LwM2mClientObserver2` is compatible with `LwM2mClientObserver` and each
implementing class conceals the difference between `LwM2mClientObserver`
and `LwM2mClientObserver2`.

Signed-off-by: moznion <[email protected]>
  • Loading branch information
moznion authored and sbernard31 committed Dec 10, 2020
1 parent aad536f commit 9d5b405
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.eclipse.leshan.client.observer;

/**
* An extended interface of {@link LwM2mClientObserver} with handler for unexpected error.
* <p>
* Future plan: Since version 2.0, this interface is going to merge into {@link LwM2mClientObserver}.
*
* @since 1.3
*/
public interface LwM2mClientObserver2 extends LwM2mClientObserver {
// ============== Unexpected Error Handling =================

void onUnexpectedError(Throwable unexpectedError);
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* An abstract adapter class for observing registration life cycle. The methods in this class are empty. This class
* exists as convenience for creating client observer objects.
*/
public class LwM2mClientObserverAdapter implements LwM2mClientObserver {
public class LwM2mClientObserverAdapter implements LwM2mClientObserver2 {

@Override
public void onBootstrapStarted(ServerIdentity bsserver, BootstrapRequest request) {
Expand Down Expand Up @@ -95,4 +95,8 @@ public void onDeregistrationFailure(ServerIdentity server, DeregisterRequest req
@Override
public void onDeregistrationTimeout(ServerIdentity server, DeregisterRequest request) {
}

@Override
public void onUnexpectedError(Throwable unexpectedError) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* A dispatcher for LwM2mClientObserver. It allow several observers on a LwM2mClient.
*
*/
public class LwM2mClientObserverDispatcher implements LwM2mClientObserver {
public class LwM2mClientObserverDispatcher implements LwM2mClientObserver2 {
private CopyOnWriteArrayList<LwM2mClientObserver> observers = new CopyOnWriteArrayList<>();

public void addObserver(LwM2mClientObserver observer) {
Expand Down Expand Up @@ -151,4 +151,12 @@ public void onDeregistrationTimeout(ServerIdentity server, DeregisterRequest req
}
}

@Override
public void onUnexpectedError(Throwable unexpectedError) {
for (LwM2mClientObserver observer : observers) {
if (observer instanceof LwM2mClientObserver2) {
((LwM2mClientObserver2) observer).onUnexpectedError(unexpectedError);
}
}
}
}

0 comments on commit 9d5b405

Please sign in to comment.