Skip to content

Commit

Permalink
#387: add readlock on InMemoryRegistrationStore.getRegistrationByAdress
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Sep 25, 2017
1 parent 1616615 commit 00433fc
Showing 1 changed file with 14 additions and 8 deletions.
Expand Up @@ -128,7 +128,7 @@ public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
public Registration getRegistration(String registrationId) {
try {
lock.readLock().lock();

// TODO we should create an index instead of iterate all over the collection
if (registrationId != null) {
for (Registration registration : regsByEp.values()) {
if (registrationId.equals(registration.getId())) {
Expand All @@ -154,13 +154,20 @@ public Registration getRegistrationByEndpoint(String endpoint) {

@Override
public Registration getRegistrationByAdress(InetSocketAddress address) {
// TODO we should create an index instead of iterate all over the collection
for (Registration r : regsByEp.values()) {
if (address.getPort() == r.getPort() && address.getAddress().equals(r.getAddress())) {
return r;
try {
lock.readLock().lock();
// TODO we should create an index instead of iterate all over the collection
if (address != null) {
for (Registration r : regsByEp.values()) {
if (address.getPort() == r.getPort() && address.getAddress().equals(r.getAddress())) {
return r;
}
}
}
return null;
} finally {
lock.readLock().unlock();
}
return null;
}

@Override
Expand Down Expand Up @@ -314,8 +321,7 @@ public void setContext(byte[] token, CorrelationContext ctx) {
Key key = new Key(token);
org.eclipse.californium.core.observe.Observation obs = obsByToken.get(key);
if (obs != null) {
obsByToken.put(key,
new org.eclipse.californium.core.observe.Observation(obs.getRequest(), ctx));
obsByToken.put(key, new org.eclipse.californium.core.observe.Observation(obs.getRequest(), ctx));
}
} finally {
lock.writeLock().unlock();
Expand Down

0 comments on commit 00433fc

Please sign in to comment.