diff --git a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/RedisRegistrationStore.java b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/RedisRegistrationStore.java index 1cbd8d245d..f7c77cbd15 100644 --- a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/RedisRegistrationStore.java +++ b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/RedisRegistrationStore.java @@ -45,9 +45,11 @@ import org.eclipse.leshan.core.observation.ObservationIdentifier; import org.eclipse.leshan.core.observation.SingleObservation; import org.eclipse.leshan.core.peer.LwM2mIdentity; +import org.eclipse.leshan.core.peer.LwM2mPeer; import org.eclipse.leshan.core.util.NamedThreadFactory; import org.eclipse.leshan.core.util.Validate; import org.eclipse.leshan.server.redis.serialization.LwM2mIdentitySerDes; +import org.eclipse.leshan.server.redis.serialization.LwM2mPeerSerDes; import org.eclipse.leshan.server.redis.serialization.ObservationSerDes; import org.eclipse.leshan.server.redis.serialization.RegistrationSerDes; import org.eclipse.leshan.server.registration.Deregistration; @@ -98,7 +100,7 @@ public class RedisRegistrationStore implements RegistrationStore, Startable, Sto private final JedisLock lock; private final RegistrationSerDes registrationSerDes; private final ObservationSerDes observationSerDes; - private final LwM2mIdentitySerDes identitySerDes = new LwM2mIdentitySerDes(); // TODO add it to builder ? + private final LwM2mIdentitySerDes identitySerDes; public RedisRegistrationStore(Pool p) { this(new Builder(p).generateDefaultValue()); @@ -121,6 +123,7 @@ public RedisRegistrationStore(Builder builder) { this.lock = builder.lock; this.registrationSerDes = builder.registrationSerDes; this.observationSerDes = builder.observationSerDes; + this.identitySerDes = builder.identitySerDes; } /* *************** Redis Key utility function **************** */ @@ -766,6 +769,7 @@ public void setExpirationListener(ExpirationListener listener) { public static class Builder { private final Pool pool; + private String prefix; private String registrationByEndpointPrefix; private String endpointByRegistrationIdPrefix; @@ -786,6 +790,8 @@ public static class Builder { private JedisLock lock; private RegistrationSerDes registrationSerDes; private ObservationSerDes observationSerDes; + private LwM2mIdentitySerDes identitySerDes; + private LwM2mPeerSerDes peerSerDes; /** * Set the prefix for all keys and prefixes. @@ -942,6 +948,23 @@ public Builder setRegistrationSerDes(RegistrationSerDes registrationSerDes) { return this; } + /** + * Set {@link LwM2mIdentitySerDes} instance used to serialize/de-serialize {@link LwM2mIdentity} to/from this + * store. + */ + public Builder setIdentitySerDes(LwM2mIdentitySerDes identitySerDes) { + this.identitySerDes = identitySerDes; + return this; + } + + /** + * Set {@link LwM2mPeerSerDes} instance used to serialize/de-serialize {@link LwM2mPeer} to/from this store. + */ + public Builder setPeerSerDes(LwM2mPeerSerDes peerSerDes) { + this.peerSerDes = peerSerDes; + return this; + } + /** * Set {@link ObservationSerDes} instance used to serialize/de-serialize {@link Observation} to/from this store. */ @@ -977,7 +1000,14 @@ protected Builder generateDefaultValue() { } if (this.registrationSerDes == null) { - this.registrationSerDes = new RegistrationSerDes(); + if (peerSerDes == null) { + this.peerSerDes = new LwM2mPeerSerDes(); + } + this.registrationSerDes = new RegistrationSerDes(peerSerDes); + } + + if (this.identitySerDes == null) { + this.identitySerDes = new LwM2mIdentitySerDes(); } if (this.observationSerDes == null) { diff --git a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java index e57ca62897..9cef37dded 100644 --- a/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java +++ b/leshan-server-redis/src/main/java/org/eclipse/leshan/server/redis/serialization/RegistrationSerDes.java @@ -59,9 +59,9 @@ public class RegistrationSerDes { private final AttributeParser attributeParser; - private final LwM2mPeerSerDes peerSerDes = new LwM2mPeerSerDes(); + private final LwM2mPeerSerDes peerSerDes; - public RegistrationSerDes() { + public RegistrationSerDes(LwM2mPeerSerDes peerSerDes) { // Define all supported Attributes Collection> suppportedAttributes = new ArrayList>(); suppportedAttributes.addAll(Attributes.ALL); @@ -69,10 +69,17 @@ public RegistrationSerDes() { // Create default link Parser this.attributeParser = new DefaultAttributeParser(suppportedAttributes); + this.peerSerDes = peerSerDes; + } + + public RegistrationSerDes() { + this.attributeParser = new DefaultAttributeParser(); + this.peerSerDes = new LwM2mPeerSerDes(); } - public RegistrationSerDes(AttributeParser attributeParser) { + public RegistrationSerDes(AttributeParser attributeParser, LwM2mPeerSerDes peerSerDes) { this.attributeParser = attributeParser; + this.peerSerDes = peerSerDes; } public JsonNode jSerialize(Registration r) {