Make LwM2mValueConverterImpl singleton

This commit is contained in:
Andrii Shvaika 2021-01-05 10:50:17 +02:00
parent 3a7101a8a3
commit 58e544c32e
5 changed files with 11 additions and 5 deletions

View File

@ -91,7 +91,7 @@ public class LwM2MTransportRequest {
@PostConstruct
public void init() {
this.converter = new LwM2mValueConverterImpl();
this.converter = LwM2mValueConverterImpl.getInstance();
executorResponse = Executors.newCachedThreadPool(
new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL)));
executorResponseError = Executors.newCachedThreadPool(

View File

@ -73,7 +73,7 @@ public class LwM2MTransportServerConfiguration {
builder.setEncoder(new DefaultLwM2mNodeEncoder());
LwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
builder.setDecoder(decoder);
builder.setEncoder(new DefaultLwM2mNodeEncoder(new LwM2mValueConverterImpl()));
builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance()));
/** Create CoAP Config */
builder.setCoapConfig(getCoapConfig());
@ -89,7 +89,7 @@ public class LwM2MTransportServerConfiguration {
builder.setDtlsConfig(dtlsConfig);
/** Use a magic converter to support bad type send by the UI. */
builder.setEncoder(new DefaultLwM2mNodeEncoder(new LwM2mValueConverterImpl()));
builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance()));
/** Create DTLS security mode
* There can be only one DTLS security mode

View File

@ -123,7 +123,7 @@ public class LwM2MTransportService {
new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL)));
this.executorUnRegistered = Executors.newCachedThreadPool(
new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL)));
this.converter = new LwM2mValueConverterImpl();
this.converter = LwM2mValueConverterImpl.getInstance();
}
/**

View File

@ -78,7 +78,7 @@ public class LwM2MClient implements Cloneable {
* Key <objectId>, response<Value -> instance -> resources: value...>
*/
this.responses = new ConcurrentHashMap<>();
this.converter = new LwM2mValueConverterImpl();
this.converter = LwM2mValueConverterImpl.getInstance();
}
/**

View File

@ -33,6 +33,12 @@ import java.util.Date;
@Slf4j
public class LwM2mValueConverterImpl implements LwM2mValueConverter {
private static final LwM2mValueConverterImpl INSTANCE = new LwM2mValueConverterImpl();
public static LwM2mValueConverterImpl getInstance() {
return INSTANCE;
}
@Override
public Object convertValue(Object value, Type currentType, Type expectedType, LwM2mPath resourcePath)
throws CodecException {