EMS: Baguette Server, Control Service: Changed NRE.stateLastUpdate from Date to Instant. Changed TopicBeacon to configure gson serializing Instant type to ISO date/time strings

This commit is contained in:
ipatini 2023-10-07 15:19:54 +03:00
parent 79540e41cb
commit 92635a6c98
2 changed files with 24 additions and 5 deletions

View File

@ -15,6 +15,7 @@ import gr.iccs.imu.ems.util.StrUtil;
import lombok.*; import lombok.*;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import java.time.Instant;
import java.util.*; import java.util.*;
@Data @Data
@ -34,7 +35,7 @@ public class NodeRegistryEntry {
private final transient BaguetteServer baguetteServer; private final transient BaguetteServer baguetteServer;
@Getter private String hostname; @Getter private String hostname;
@Getter private STATE state = null; @Getter private STATE state = null;
@Getter private Date stateLastUpdate; @Getter private Instant stateLastUpdate;
@Getter private String reference = UUID.randomUUID().toString(); @Getter private String reference = UUID.randomUUID().toString();
@Getter private List<Object> errors = new LinkedList<>(); @Getter private List<Object> errors = new LinkedList<>();
@JsonIgnore @JsonIgnore
@ -71,7 +72,7 @@ public class NodeRegistryEntry {
private void setState(@NonNull STATE s) { private void setState(@NonNull STATE s) {
state = s; state = s;
stateLastUpdate = new Date(); stateLastUpdate = Instant.now();
} }
public void refreshReference() { reference = UUID.randomUUID().toString(); } public void refreshReference() { reference = UUID.randomUUID().toString(); }

View File

@ -9,8 +9,7 @@
package gr.iccs.imu.ems.control.util; package gr.iccs.imu.ems.control.util;
import com.google.gson.Gson; import com.google.gson.*;
import com.google.gson.GsonBuilder;
import gr.iccs.imu.ems.baguette.server.NodeRegistryEntry; import gr.iccs.imu.ems.baguette.server.NodeRegistryEntry;
import gr.iccs.imu.ems.brokercep.BrokerCepService; import gr.iccs.imu.ems.brokercep.BrokerCepService;
import gr.iccs.imu.ems.brokercep.event.EventMap; import gr.iccs.imu.ems.brokercep.event.EventMap;
@ -30,6 +29,7 @@ import org.springframework.stereotype.Service;
import javax.jms.JMSException; import javax.jms.JMSException;
import java.io.Serializable; import java.io.Serializable;
import java.time.Duration; import java.time.Duration;
import java.time.Instant;
import java.util.*; import java.util.*;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
@ -59,7 +59,25 @@ public class TopicBeacon implements InitializingBean {
} }
// initialize a Gson instance // initialize a Gson instance
gson = new GsonBuilder().disableHtmlEscaping().create(); gson = new GsonBuilder()
.disableHtmlEscaping()
.registerTypeAdapter(Instant.class,
(JsonSerializer<Instant>) (src, typeOfSrc, context) ->
(src==null) ? JsonNull.INSTANCE : new JsonPrimitive(src.toString()))
.registerTypeAdapter(Instant.class,
(JsonDeserializer<Instant>) (json, typeOfT, context) -> {
if (json.isJsonNull()) return null;
if (!json.isJsonPrimitive())
throw new IllegalArgumentException("");
JsonPrimitive primitive = json.getAsJsonPrimitive();
if (!primitive.isString())
throw new IllegalArgumentException("");
String s = primitive.getAsString();
if (StringUtils.isEmpty(s))
return null;
return Instant.parse(s);
})
.create();
// configure and start scheduler // configure and start scheduler
Date startTime = new Date(System.currentTimeMillis() + properties.getInitialDelay()); Date startTime = new Date(System.currentTimeMillis() + properties.getInitialDelay());