Skip to content

Commit

Permalink
Limit Jedis resource consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Oct 3, 2017
1 parent c15336a commit 8cb071b
Showing 1 changed file with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,7 @@ public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
@Override
public Registration getRegistration(String registrationId) {
try (Jedis j = pool.getResource()) {
byte[] ep = j.get(toRegIdKey(registrationId));
if (ep == null) {
return null;
}
byte[] data = j.get(toEndpointKey(ep));
if (data == null) {
return null;
}

return deserializeReg(data);
return getRegistration(j, registrationId);
}
}

Expand Down Expand Up @@ -458,7 +449,7 @@ private Collection<Observation> getObservations(Jedis j, String registrationId)
public Collection<Observation> removeObservations(String registrationId) {
try (Jedis j = pool.getResource()) {
// check registration exists
Registration registration = getRegistration(registrationId);
Registration registration = getRegistration(j, registrationId);
if (registration == null)
return Collections.emptyList();

Expand Down Expand Up @@ -523,7 +514,7 @@ public void remove(byte[] token) {

org.eclipse.californium.core.observe.Observation obs = deserializeObs(serializedObs);
String registrationId = obs.getRequest().getUserContext().get(CoapRequestBuilder.CTX_REGID);
Registration registration = getRegistration(registrationId);
Registration registration = getRegistration(j, registrationId);
String endpoint = registration.getEndpoint();

byte[] lockValue = null;
Expand Down Expand Up @@ -553,6 +544,19 @@ public org.eclipse.californium.core.observe.Observation get(byte[] token) {

/* *************** Observation utility functions **************** */

private Registration getRegistration(Jedis j, String registrationId) {
byte[] ep = j.get(toRegIdKey(registrationId));
if (ep == null) {
return null;
}
byte[] data = j.get(toEndpointKey(ep));
if (data == null) {
return null;
}

return deserializeReg(data);
}

private void unsafeRemoveObservation(Jedis j, String registrationId, byte[] observationId) {
if (j.del(toKey(OBS_TKN, observationId)) > 0L) {
j.lrem(toKey(OBS_TKNS_REGID_IDX, registrationId), 0, observationId);
Expand Down

0 comments on commit 8cb071b

Please sign in to comment.