Skip to content

Commit

Permalink
GH-1384: Fix issue in LwM2mObservationStore.remove(Token)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 26, 2023
1 parent 346223b commit 233c209
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,24 @@ public Observation put(Token token, Observation obs) {

@Override
public void remove(Token token) {
org.eclipse.leshan.core.observation.Observation removedObservation = registrationStore.removeObservation(null,
new ObservationIdentifier(token.getBytes()));
notificationListener.cancelled(removedObservation);
// try to find observation for given token
org.eclipse.leshan.core.observation.Observation observation = registrationStore
.getObservation(new ObservationIdentifier(token.getBytes()));

if (observation != null) {
// try to remove observation
org.eclipse.leshan.core.observation.Observation removedObservation = registrationStore
.removeObservation(observation.getRegistrationId(), new ObservationIdentifier(token.getBytes()));
if (removedObservation != null) {
notificationListener.cancelled(removedObservation);
}
}
}

@Override
public Observation get(Token token) {
org.eclipse.leshan.core.observation.Observation observation = registrationStore.getObservation(null,
new ObservationIdentifier(token.getBytes()));
org.eclipse.leshan.core.observation.Observation observation = registrationStore
.getObservation(new ObservationIdentifier(token.getBytes()));
if (observation == null) {
return null;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ public Observation removeObservation(String registrationId, ObservationIdentifie
try {
lock.writeLock().lock();
Observation observation = unsafeGetObservation(observationId);
if (observation != null
&& (registrationId == null || registrationId.equals(observation.getRegistrationId()))) {
if (observation != null && registrationId.equals(observation.getRegistrationId())) {
unsafeRemoveObservation(observationId);
return observation;
}
Expand Down

0 comments on commit 233c209

Please sign in to comment.