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