diff --git a/ems-core/baguette-server/src/main/java/gr/iccs/imu/ems/baguette/server/NodeRegistryEntry.java b/ems-core/baguette-server/src/main/java/gr/iccs/imu/ems/baguette/server/NodeRegistryEntry.java index b033514..6b42b90 100644 --- a/ems-core/baguette-server/src/main/java/gr/iccs/imu/ems/baguette/server/NodeRegistryEntry.java +++ b/ems-core/baguette-server/src/main/java/gr/iccs/imu/ems/baguette/server/NodeRegistryEntry.java @@ -15,6 +15,7 @@ import gr.iccs.imu.ems.util.StrUtil; import lombok.*; import org.apache.commons.lang3.StringUtils; +import java.time.Instant; import java.util.*; @Data @@ -34,7 +35,7 @@ public class NodeRegistryEntry { private final transient BaguetteServer baguetteServer; @Getter private String hostname; @Getter private STATE state = null; - @Getter private Date stateLastUpdate; + @Getter private Instant stateLastUpdate; @Getter private String reference = UUID.randomUUID().toString(); @Getter private List errors = new LinkedList<>(); @JsonIgnore @@ -71,7 +72,7 @@ public class NodeRegistryEntry { private void setState(@NonNull STATE s) { state = s; - stateLastUpdate = new Date(); + stateLastUpdate = Instant.now(); } public void refreshReference() { reference = UUID.randomUUID().toString(); } diff --git a/ems-core/control-service/src/main/java/gr/iccs/imu/ems/control/util/TopicBeacon.java b/ems-core/control-service/src/main/java/gr/iccs/imu/ems/control/util/TopicBeacon.java index 6caad3b..a4a4fe5 100644 --- a/ems-core/control-service/src/main/java/gr/iccs/imu/ems/control/util/TopicBeacon.java +++ b/ems-core/control-service/src/main/java/gr/iccs/imu/ems/control/util/TopicBeacon.java @@ -9,8 +9,7 @@ package gr.iccs.imu.ems.control.util; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; +import com.google.gson.*; import gr.iccs.imu.ems.baguette.server.NodeRegistryEntry; import gr.iccs.imu.ems.brokercep.BrokerCepService; import gr.iccs.imu.ems.brokercep.event.EventMap; @@ -30,6 +29,7 @@ import org.springframework.stereotype.Service; import javax.jms.JMSException; import java.io.Serializable; import java.time.Duration; +import java.time.Instant; import java.util.*; import java.util.concurrent.atomic.AtomicLong; @@ -59,7 +59,25 @@ public class TopicBeacon implements InitializingBean { } // initialize a Gson instance - gson = new GsonBuilder().disableHtmlEscaping().create(); + gson = new GsonBuilder() + .disableHtmlEscaping() + .registerTypeAdapter(Instant.class, + (JsonSerializer) (src, typeOfSrc, context) -> + (src==null) ? JsonNull.INSTANCE : new JsonPrimitive(src.toString())) + .registerTypeAdapter(Instant.class, + (JsonDeserializer) (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 Date startTime = new Date(System.currentTimeMillis() + properties.getInitialDelay());