Skip to content

Commit

Permalink
added feature to control the type of observe reregister and cancel
Browse files Browse the repository at this point in the history
requests.

Signed-off-by: Rogier Cobben <[email protected]>
  • Loading branch information
rogierc authored and boaks committed Jan 27, 2023
1 parent 12b2f04 commit 70908f7
Show file tree
Hide file tree
Showing 2 changed files with 388 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* Contributors:
* Bosch IO.GmbH - initial implementation,
* mainly copied from CoapObserveRelation
* Rogier Cobben - added confirmable flag and methods to control
* the type of reregister and cancel requests.
******************************************************************************/
package org.eclipse.californium.core.coap;

Expand Down Expand Up @@ -72,6 +74,13 @@ public class ClientObserveRelation {
/** Indicates whether a proactive cancel request is pending. */
private volatile boolean proactiveCancel = false;

/**
* Indicates whether reregister and cancel requests are sent confirmable.
*
* @since 3.8
*/
private volatile boolean confirmable;

/** The current notification. */
private volatile Response current = null;

Expand Down Expand Up @@ -127,6 +136,7 @@ private void next() {
*/
public ClientObserveRelation(Request request, Endpoint endpoint, ScheduledThreadPoolExecutor executor) {
this.request = request;
this.confirmable = request.isConfirmable();
this.endpoint = endpoint;
this.orderer = new ObserveNotificationOrderer();
this.reregistrationBackoffMillis = endpoint.getConfig().get(CoapConfig.NOTIFICATION_REREGISTRATION_BACKOFF,
Expand All @@ -136,6 +146,29 @@ public ClientObserveRelation(Request request, Endpoint endpoint, ScheduledThread
this.request.setProtectFromOffload();
}

/**
* Checks if the relation is reregistered and cancelled confirmable or
* non-confirmable.
*
* @return {@code true}, if the relation is reregistered and cancelled
* confirmable.
* @since 3.8
*/
public boolean isConfirmable() {
return confirmable;
}

/**
* Set the relation reregister and cancel message type.
*
* @param confirmable when {@code true} reregister and cancel requests are
* sent confirmable, non-confirmable otherwise.
* @since 3.8
*/
public void setConfirmable(boolean confirmable) {
this.confirmable = confirmable;
}

/**
* Refreshes the Observe relationship with a new GET request with same token
* and options. The method also resets the notification orderer, since the
Expand All @@ -161,6 +194,7 @@ public boolean reregister() {
}
if (requestPending.compareAndSet(false, true)) {
Request refresh = Request.newGet();
refresh.setConfirmable(confirmable);
EndpointContext destinationContext = response != null ? response.getSourceContext()
: request.getDestinationContext();
refresh.setDestinationContext(destinationContext);
Expand Down Expand Up @@ -209,6 +243,7 @@ private void sendCancelObserve() {
: request.getDestinationContext();

Request cancel = Request.newGet();
cancel.setConfirmable(confirmable);
cancel.setDestinationContext(destinationContext);
// use same Token
cancel.setToken(request.getToken());
Expand Down Expand Up @@ -250,7 +285,7 @@ private void cancel() {
/**
* Marks this relation as canceled.
*
* @param canceled true if this relation has been canceled
* @param canceled {@code true} if this relation has been canceled
*/
protected void setCanceled(boolean canceled) {
this.canceled.set(canceled);
Expand Down Expand Up @@ -295,7 +330,7 @@ public void reactiveCancel() {
/**
* Checks if the relation has been canceled.
*
* @return true, if the relation has been canceled
* @return {@code true}, if the relation has been canceled
*/
public boolean isCanceled() {
return canceled.get();
Expand Down
Loading

0 comments on commit 70908f7

Please sign in to comment.