1 package org.sim0mq.message.heartbeat;
2
3 import org.sim0mq.Sim0MQException;
4 import org.sim0mq.message.Sim0MQMessage;
5 import org.sim0mq.message.Sim0MQReply;
6
7 /**
8 * Alive Message, HB.2. A federate sends this message as a response to Heartbeat messages sent by the Federate Starter or the
9 * Federation Manager.
10 * <p>
11 * Copyright (c) 2019-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
12 * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
13 * </p>
14 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15 */
16 public class HB2AliveMessage extends Sim0MQReply
17 {
18 /** the unique message id. */
19 private static final String MESSAGETYPE = "HB.2";
20
21 /** */
22 private static final long serialVersionUID = 20190713L;
23
24 /**
25 * @param federationId the federation id can be coded using different types. Examples are two 64-bit longs indicating a
26 * UUID, or a String with a UUID number, a String with meaningful identification, or a short or an int with a
27 * simulation run number.
28 * @param senderId The sender id can be used to send back a message to the sender at some later time.
29 * @param receiverId The receiver id can be used to check whether the message is meant for us, or should be discarded (or an
30 * error can be sent if we receive a message not meant for us).
31 * @param messageId The unique message number is meant to confirm with a callback that the message has been received
32 * correctly. The number is unique for the sender, so not globally within the federation.
33 * @param uniqueId Id to identify the callback to the message.
34 * @throws Sim0MQException on unknown data type
35 * @throws NullPointerException when one of the parameters is null
36 */
37 public HB2AliveMessage(final Object federationId, final Object senderId, final Object receiverId, final Object messageId,
38 final Object uniqueId) throws Sim0MQException, NullPointerException
39 {
40 this(new Object[] {Sim0MQMessage.VERSION, true, federationId, senderId, receiverId, MESSAGETYPE, messageId, 1,
41 uniqueId});
42 }
43
44 /**
45 * @param objectArray Object[]; Full message object array
46 * @throws Sim0MQException on unknown data type
47 * @throws NullPointerException when one of the parameters is null
48 */
49 public HB2AliveMessage(final Object[] objectArray) throws Sim0MQException, NullPointerException
50 {
51 super(objectArray, 1, MESSAGETYPE);
52 }
53
54 /**
55 * @return messagetype
56 */
57 public static final String getMessageType()
58 {
59 return MESSAGETYPE;
60 }
61
62 /**
63 * Builder for the Alive Message. Can string setters together, and call build() at the end to build the actual message.
64 * <p>
65 * Copyright (c) 2016-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
66 * <br>
67 * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
68 * </p>
69 * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
70 */
71 public static class Builder extends Sim0MQReply.Builder<HB2AliveMessage.Builder>
72 {
73 /**
74 * Empty constructor.
75 */
76 public Builder()
77 {
78 // nothing to do.
79 }
80
81 @Override
82 public HB2AliveMessage build() throws Sim0MQException, NullPointerException
83 {
84 return new HB2AliveMessage(this.federationId, this.senderId, this.receiverId, this.messageId, this.replyToId);
85 }
86
87 }
88 }