use of org.eclipse.leshan.server.registration.UpdatedRegistration in project leshan by eclipse.
the class InMemoryRegistrationStore method updateRegistration.
@Override
public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
try {
lock.writeLock().lock();
Registration registration = getRegistration(update.getRegistrationId());
if (registration == null) {
return null;
} else {
Registration updatedRegistration = update.update(registration);
regsByEp.put(updatedRegistration.getEndpoint(), updatedRegistration);
return new UpdatedRegistration(registration, updatedRegistration);
}
} finally {
lock.writeLock().unlock();
}
}
use of org.eclipse.leshan.server.registration.UpdatedRegistration in project leshan by eclipse.
the class RedisRegistrationStore method updateRegistration.
@Override
public UpdatedRegistration updateRegistration(RegistrationUpdate update) {
try (Jedis j = pool.getResource()) {
// fetch the client ep by registration ID index
byte[] ep = j.get(toRegIdKey(update.getRegistrationId()));
if (ep == null) {
return null;
}
byte[] lockValue = null;
byte[] lockKey = toLockKey(ep);
try {
lockValue = RedisLock.acquire(j, lockKey);
// fetch the client
byte[] data = j.get(toEndpointKey(ep));
if (data == null) {
return null;
}
Registration r = deserializeReg(data);
Registration updatedRegistration = update.update(r);
// store the new client
j.set(toEndpointKey(updatedRegistration.getEndpoint()), serializeReg(updatedRegistration));
return new UpdatedRegistration(r, updatedRegistration);
} finally {
RedisLock.release(j, lockKey, lockValue);
}
}
}
use of org.eclipse.leshan.server.registration.UpdatedRegistration in project leshan by eclipse.
the class InMemoryRegistrationStoreTest method update_registration_keeps_properties_unchanged.
@Test
public void update_registration_keeps_properties_unchanged() {
givenASimpleRegistration(lifetime);
store.addRegistration(registration);
RegistrationUpdate update = new RegistrationUpdate(registrationId, Identity.unsecure(address, port), null, null, null, null, null);
UpdatedRegistration updatedRegistration = store.updateRegistration(update);
Assert.assertEquals(lifetime, updatedRegistration.getUpdatedRegistration().getLifeTimeInSec());
Assert.assertSame(binding, updatedRegistration.getUpdatedRegistration().getBindingMode());
Assert.assertEquals(sms, updatedRegistration.getUpdatedRegistration().getSmsNumber());
Assert.assertEquals(registration, updatedRegistration.getPreviousRegistration());
Registration reg = store.getRegistrationByEndpoint(ep);
Assert.assertEquals(lifetime, reg.getLifeTimeInSec());
Assert.assertSame(binding, reg.getBindingMode());
Assert.assertEquals(sms, reg.getSmsNumber());
}
use of org.eclipse.leshan.server.registration.UpdatedRegistration in project leshan by eclipse.
the class InMemoryRegistrationStoreTest method update_registration_to_extend_time_to_live.
@Test
public void update_registration_to_extend_time_to_live() {
givenASimpleRegistration(0L);
store.addRegistration(registration);
Assert.assertFalse(registration.isAlive());
RegistrationUpdate update = new RegistrationUpdate(registrationId, Identity.unsecure(address, port), lifetime, null, null, null, null);
UpdatedRegistration updatedRegistration = store.updateRegistration(update);
Assert.assertTrue(updatedRegistration.getUpdatedRegistration().isAlive());
Registration reg = store.getRegistrationByEndpoint(ep);
Assert.assertTrue(reg.isAlive());
}
Aggregations