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