/** * Provide an instance of {@link TimeUntilDisconnectNotification} if a message indicates that the device sending it * is currently connected to a protocol adapter. * <p> * If this is not the case, the returned {@link Optional} will be empty. * * @param msg Message that is evaluated. * @return Optional containing an instance of the class {@link TimeUntilDisconnectNotification} if the device is considered * being ready to receive an upstream message or is empty otherwise. * @throws NullPointerException If msg is {@code null}. */ public static Optional<TimeUntilDisconnectNotification> fromMessage(final Message msg) { final Integer ttd = MessageHelper.getTimeUntilDisconnect(msg); if (ttd == null) { return Optional.empty(); } else if (ttd == 0 || MessageHelper.isDeviceCurrentlyConnected(msg)) { final String tenantId = MessageHelper.getTenantIdAnnotation(msg); final String deviceId = MessageHelper.getDeviceId(msg); if (tenantId != null && deviceId != null) { final Instant creationTime = Instant.ofEpochMilli(msg.getCreationTime()); final TimeUntilDisconnectNotification notification = new TimeUntilDisconnectNotification(tenantId, deviceId, ttd, getReadyUntilInstantFromTtd(ttd, creationTime), creationTime); return Optional.of(notification); } } return Optional.empty(); }
/** * Provide an instance of {@link TimeUntilDisconnectNotification} if a message indicates that the device sending it * is currently connected to a protocol adapter. * <p> * If this is not the case, the returned {@link Optional} will be empty. * * @param msg Message that is evaluated. * @return Optional containing an instance of the class {@link TimeUntilDisconnectNotification} if the device is considered * being ready to receive an upstream message or is empty otherwise. * @throws NullPointerException If msg is {@code null}. */ public static Optional<TimeUntilDisconnectNotification> fromMessage(final Message msg) { final Integer ttd = MessageHelper.getTimeUntilDisconnect(msg); if (ttd == null) { return Optional.empty(); } else if (ttd == 0 || MessageHelper.isDeviceCurrentlyConnected(msg)) { final String tenantId = MessageHelper.getTenantIdAnnotation(msg); final String deviceId = MessageHelper.getDeviceId(msg); if (tenantId != null && deviceId != null) { final Instant creationTime = Instant.ofEpochMilli(msg.getCreationTime()); final TimeUntilDisconnectNotification notification = new TimeUntilDisconnectNotification(tenantId, deviceId, ttd, getReadyUntilInstantFromTtd(ttd, creationTime), creationTime); return Optional.of(notification); } } return Optional.empty(); }