Commit 58e544c32e6f2274a3084a1ba1509a020fa2d59d

Authored by Andrii Shvaika
1 parent 3a7101a8

Make LwM2mValueConverterImpl singleton

@@ -91,7 +91,7 @@ public class LwM2MTransportRequest { @@ -91,7 +91,7 @@ public class LwM2MTransportRequest {
91 91
92 @PostConstruct 92 @PostConstruct
93 public void init() { 93 public void init() {
94 - this.converter = new LwM2mValueConverterImpl(); 94 + this.converter = LwM2mValueConverterImpl.getInstance();
95 executorResponse = Executors.newCachedThreadPool( 95 executorResponse = Executors.newCachedThreadPool(
96 new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL))); 96 new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL)));
97 executorResponseError = Executors.newCachedThreadPool( 97 executorResponseError = Executors.newCachedThreadPool(
@@ -73,7 +73,7 @@ public class LwM2MTransportServerConfiguration { @@ -73,7 +73,7 @@ public class LwM2MTransportServerConfiguration {
73 builder.setEncoder(new DefaultLwM2mNodeEncoder()); 73 builder.setEncoder(new DefaultLwM2mNodeEncoder());
74 LwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder(); 74 LwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder();
75 builder.setDecoder(decoder); 75 builder.setDecoder(decoder);
76 - builder.setEncoder(new DefaultLwM2mNodeEncoder(new LwM2mValueConverterImpl())); 76 + builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance()));
77 77
78 /** Create CoAP Config */ 78 /** Create CoAP Config */
79 builder.setCoapConfig(getCoapConfig()); 79 builder.setCoapConfig(getCoapConfig());
@@ -89,7 +89,7 @@ public class LwM2MTransportServerConfiguration { @@ -89,7 +89,7 @@ public class LwM2MTransportServerConfiguration {
89 builder.setDtlsConfig(dtlsConfig); 89 builder.setDtlsConfig(dtlsConfig);
90 90
91 /** Use a magic converter to support bad type send by the UI. */ 91 /** Use a magic converter to support bad type send by the UI. */
92 - builder.setEncoder(new DefaultLwM2mNodeEncoder(new LwM2mValueConverterImpl())); 92 + builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance()));
93 93
94 /** Create DTLS security mode 94 /** Create DTLS security mode
95 * There can be only one DTLS security mode 95 * There can be only one DTLS security mode
@@ -123,7 +123,7 @@ public class LwM2MTransportService { @@ -123,7 +123,7 @@ public class LwM2MTransportService {
123 new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL))); 123 new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL)));
124 this.executorUnRegistered = Executors.newCachedThreadPool( 124 this.executorUnRegistered = Executors.newCachedThreadPool(
125 new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL))); 125 new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL)));
126 - this.converter = new LwM2mValueConverterImpl(); 126 + this.converter = LwM2mValueConverterImpl.getInstance();
127 } 127 }
128 128
129 /** 129 /**
@@ -78,7 +78,7 @@ public class LwM2MClient implements Cloneable { @@ -78,7 +78,7 @@ public class LwM2MClient implements Cloneable {
78 * Key <objectId>, response<Value -> instance -> resources: value...> 78 * Key <objectId>, response<Value -> instance -> resources: value...>
79 */ 79 */
80 this.responses = new ConcurrentHashMap<>(); 80 this.responses = new ConcurrentHashMap<>();
81 - this.converter = new LwM2mValueConverterImpl(); 81 + this.converter = LwM2mValueConverterImpl.getInstance();
82 } 82 }
83 83
84 /** 84 /**
@@ -33,6 +33,12 @@ import java.util.Date; @@ -33,6 +33,12 @@ import java.util.Date;
33 @Slf4j 33 @Slf4j
34 public class LwM2mValueConverterImpl implements LwM2mValueConverter { 34 public class LwM2mValueConverterImpl implements LwM2mValueConverter {
35 35
  36 + private static final LwM2mValueConverterImpl INSTANCE = new LwM2mValueConverterImpl();
  37 +
  38 + public static LwM2mValueConverterImpl getInstance() {
  39 + return INSTANCE;
  40 + }
  41 +
36 @Override 42 @Override
37 public Object convertValue(Object value, Type currentType, Type expectedType, LwM2mPath resourcePath) 43 public Object convertValue(Object value, Type currentType, Type expectedType, LwM2mPath resourcePath)
38 throws CodecException { 44 throws CodecException {