View Javadoc
1   package org.sim0mq.message.federationmanager;
2   
3   import org.djutils.serialization.SerializationException;
4   import org.sim0mq.Sim0MQException;
5   import org.sim0mq.message.MessageStatus;
6   import org.sim0mq.message.Sim0MQMessage;
7   import org.sim0mq.message.SimulationMessage;
8   
9   /**
10   * RequestStatus, FM.5. Message sent by the Federation Manager to enquire the status of the simulation. The answer to this
11   * message is MC.1 "Status". Since the message type id clarifies the function of this message and no information exchange is
12   * necessary, the payload field can be empty.
13   * <p>
14   * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
15   * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
16   * </p>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class FM5RequestStatus extends Sim0MQMessage
20  {
21      /** the unique message id. */
22      private static final String MESSAGETYPE = "FM.5";
23  
24      /** */
25      private static final long serialVersionUID = 20190712L;
26  
27      /**
28       * @param simulationRunId the Simulation run ids can be provided in different types. Examples are two 64-bit longs
29       *            indicating a UUID, or a String with a UUID number, a String with meaningful identification, or a short or an
30       *            int with a simulation run number.
31       * @param senderId The sender id can be used to send back a message to the sender at some later time.
32       * @param receiverId The receiver id can be used to check whether the message is meant for us, or should be discarded (or an
33       *            error can be sent if we receive a message not meant for us).
34       * @param messageId The unique message number is meant to confirm with a callback that the message has been received
35       *            correctly. The number is unique for the sender, so not globally within the federation.
36       * @throws Sim0MQException on unknown data type
37       * @throws NullPointerException when one of the parameters is null
38       */
39      @SuppressWarnings("checkstyle:parameternumber")
40      public FM5RequestStatus(final Object simulationRunId, final Object senderId, final Object receiverId, final long messageId)
41              throws Sim0MQException, NullPointerException
42      {
43          super(simulationRunId, senderId, receiverId, MESSAGETYPE, messageId, MessageStatus.NEW);
44      }
45  
46      /**
47       * @return messagetype
48       */
49      public static final String getMessageType()
50      {
51          return MESSAGETYPE;
52      }
53  
54      /** {@inheritDoc} */
55      @Override
56      public short getNumberOfPayloadFields()
57      {
58          return 0;
59      }
60  
61      /** {@inheritDoc} */
62      @Override
63      public Object[] createObjectArray()
64      {
65          return new Object[] {getMagicNumber(), getSimulationRunId(), getSenderId(), getReceiverId(), getMessageTypeId(),
66                  getMessageId(), getMessageStatus(), getNumberOfPayloadFields()};
67      }
68  
69      /** {@inheritDoc} */
70      @Override
71      public byte[] createByteArray() throws Sim0MQException, SerializationException
72      {
73          return SimulationMessage.encodeUTF8(getSimulationRunId(), getSenderId(), getReceiverId(), getMessageTypeId(),
74                  getMessageId(), getMessageStatus());
75      }
76  
77      /**
78       * Build a message from an Object[] that was received.
79       * @param fields Object[]; the fields in the message
80       * @param intendedReceiverId id of the intended receiver
81       * @return a Sim0MQ message
82       * @throws Sim0MQException when number of fields is not correct
83       */
84      public static FM5RequestStatus createMessage(final Object[] fields, final Object intendedReceiverId) throws Sim0MQException
85      {
86          check(fields, 0, MESSAGETYPE, intendedReceiverId);
87          return new FM5RequestStatus(fields[1], fields[2], fields[3], ((Long) fields[5]).longValue());
88      }
89  
90      /**
91       * Builder for the RequestStatus Message. Can string setters together, and call build() at the end to build the actual
92       * message.
93       * <p>
94       * Copyright (c) 2019-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved.
95       * <br>
96       * BSD-style license. See <a href="http://sim0mq.org/docs/current/license.html">Sim0MQ License</a>.
97       * </p>
98       * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
99       */
100     public static class Builder extends Sim0MQMessage.Builder<FM5RequestStatus.Builder>
101     {
102         /**
103          * Empty constructor.
104          */
105         public Builder()
106         {
107             // nothing to do.
108         }
109 
110         /** {@inheritDoc} */
111         @Override
112         public FM5RequestStatus build() throws Sim0MQException, NullPointerException
113         {
114             return new FM5RequestStatus(this.simulationRunId, this.senderId, this.receiverId, this.messageId);
115         }
116 
117     }
118 }