View Javadoc
1   package org.sim0mq.message.federatestarter;
2   
3   import org.djutils.exceptions.Throw;
4   import org.sim0mq.Sim0MQException;
5   import org.sim0mq.message.Sim0MQMessage;
6   
7   /**
8    * FederatesKilled, FS.5. Message sent by the Federate Starter to the Federation Manager in response to message FM.9.
9    * <p>
10   * Copyright (c) 2016-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 FS5FederatesKilledMessage extends Sim0MQMessage
16  {
17      /** */
18      private static final long serialVersionUID = 20170422L;
19  
20      /** succeeded? */
21      private final boolean status;
22  
23      /** If there is an error, the error message is sent as well. Otherwise this field is an empty string. */
24      private final String error;
25  
26      /** the unique message id. */
27      private static final String MESSAGETYPE = "FS.5";
28  
29      /**
30       * @param federationId the federation id can be coded using different types. Examples are two 64-bit longs indicating a
31       *            UUID, or a String with a UUID number, a String with meaningful identification, or a short or an int with a
32       *            simulation run number.
33       * @param senderId The sender id can be used to send back a message to the sender at some later time.
34       * @param receiverId The receiver id can be used to check whether the message is meant for us, or should be discarded (or an
35       *            error can be sent if we receive a message not meant for us).
36       * @param messageId The unique message number is meant to confirm with a callback that the message has been received
37       *            correctly. The number is unique for the sender, so not globally within the federation.
38       * @param status boolean; success or failure of killing all models.
39       * @param error If there is an error, the error message is sent as well. Otherwise this field is an empty string.
40       * @throws Sim0MQException on unknown data type
41       * @throws NullPointerException when one of the parameters is null
42       */
43      @SuppressWarnings("checkstyle:parameternumber")
44      public FS5FederatesKilledMessage(final Object federationId, final Object senderId, final Object receiverId,
45              final Object messageId, final boolean status, final String error) throws Sim0MQException, NullPointerException
46      {
47          this(new Object[] {Sim0MQMessage.VERSION, true, federationId, senderId, receiverId, MESSAGETYPE, messageId, 2, status,
48                  error});
49      }
50  
51      /**
52       * @param objectArray Object[]; the fields that constitute the message
53       * @throws Sim0MQException on unknown data type
54       * @throws NullPointerException when one of the parameters is null
55       */
56      public FS5FederatesKilledMessage(final Object[] objectArray) throws Sim0MQException, NullPointerException
57      {
58          super(objectArray, 2, MESSAGETYPE);
59          Throw.when(!(objectArray[8] instanceof Boolean), Sim0MQException.class, "status (field 8) should be a Boolean");
60          this.status = ((Boolean) objectArray[8]).booleanValue();
61          Throw.when(!(objectArray[9] instanceof String), Sim0MQException.class, "error (field 9) should be a String");
62          this.error = objectArray[9].toString();
63      }
64  
65      /**
66       * @return status
67       */
68      public boolean isStatus()
69      {
70          return this.status;
71      }
72  
73      /**
74       * @return error
75       */
76      public String getError()
77      {
78          return this.error;
79      }
80  
81      /**
82       * Builder for the FederateStarted Message. Can string setters together, and call build() at the end to build the actual
83       * message.
84       * <p>
85       * Copyright (c) 2016-2024 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
86       * <br>
87       * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
88       * </p>
89       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
90       */
91      public static class Builder extends Sim0MQMessage.Builder<FS5FederatesKilledMessage.Builder>
92      {
93          /** did the kill operation succeed? */
94          private boolean status;
95  
96          /** If there is an error, the error message is sent as well. Otherwise this field is an empty string. */
97          private String error;
98  
99          /**
100          * Empty constructor.
101          */
102         public Builder()
103         {
104             // nothing to do.
105         }
106 
107         /**
108          * @param newStatus set status
109          * @return the original object for chaining
110          */
111         public final Builder setStatus(final boolean newStatus)
112         {
113             this.status = newStatus;
114             return this;
115         }
116 
117         /**
118          * @param newError set error
119          * @return the original object for chaining
120          */
121         public final Builder setError(final String newError)
122         {
123             this.error = newError;
124             return this;
125         }
126 
127         @Override
128         public FS5FederatesKilledMessage build() throws Sim0MQException, NullPointerException
129         {
130             return new FS5FederatesKilledMessage(this.federationId, this.senderId, this.receiverId, this.messageId, this.status,
131                     this.error);
132         }
133 
134     }
135 }