HB1HeartbeatMessage.java

  1. package org.sim0mq.message.heartbeat;

  2. import org.sim0mq.Sim0MQException;
  3. import org.sim0mq.message.Sim0MQMessage;

  4. /**
  5.  * Heartbeat, HB.1. Request to test if other party is still alive. From FM to FS, LB and MC, or from FS to MC.
  6.  * <p>
  7.  * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
  8.  * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
  9.  * </p>
  10.  * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  11.  */
  12. public class HB1HeartbeatMessage extends Sim0MQMessage
  13. {
  14.     /** the unique message id. */
  15.     private static final String MESSAGETYPE = "HB.1";

  16.     /** */
  17.     private static final long serialVersionUID = 20190714L;

  18.     /**
  19.      * @param federationId the federation id can be coded using different types. Examples are two 64-bit longs indicating a
  20.      *            UUID, or a String with a UUID number, a String with meaningful identification, or a short or an int with a
  21.      *            simulation run number.
  22.      * @param senderId The sender id can be used to send back a message to the sender at some later time.
  23.      * @param receiverId The receiver id can be used to check whether the message is meant for us, or should be discarded (or an
  24.      *            error can be sent if we receive a message not meant for us).
  25.      * @param messageId The unique message number is meant to confirm with a callback that the message has been received
  26.      *            correctly. The number is unique for the sender, so not globally within the federation.
  27.      * @throws Sim0MQException on unknown data type
  28.      * @throws NullPointerException when one of the parameters is null
  29.      */
  30.     @SuppressWarnings("checkstyle:parameternumber")
  31.     public HB1HeartbeatMessage(final Object federationId, final Object senderId, final Object receiverId,
  32.             final Object messageId) throws Sim0MQException, NullPointerException
  33.     {
  34.         super(true, federationId, senderId, receiverId, MESSAGETYPE, messageId, null);
  35.     }

  36.     /**
  37.      * @param objectArray Object[]; Full message object array
  38.      * @throws Sim0MQException on unknown data type
  39.      * @throws NullPointerException when one of the parameters is null
  40.      */
  41.     public HB1HeartbeatMessage(final Object[] objectArray) throws Sim0MQException, NullPointerException
  42.     {
  43.         super(objectArray, 0, MESSAGETYPE);
  44.     }

  45.     /**
  46.      * Builder for the Heartbeat Message. Can string setters together, and call build() at the end to build the actual message.
  47.      * <p>
  48.      * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
  49.      * <br>
  50.      * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
  51.      * </p>
  52.      * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
  53.      */
  54.     public static class Builder extends Sim0MQMessage.Builder<HB1HeartbeatMessage.Builder>
  55.     {
  56.         /**
  57.          * Empty constructor.
  58.          */
  59.         public Builder()
  60.         {
  61.             // nothing to do.
  62.         }

  63.         @Override
  64.         public HB1HeartbeatMessage build() throws Sim0MQException, NullPointerException
  65.         {
  66.             return new HB1HeartbeatMessage(this.federationId, this.senderId, this.receiverId, this.messageId);
  67.         }

  68.     }
  69. }