1 package org.sim0mq.message.modelcontroller;
2
3 import org.djutils.exceptions.Throw;
4 import org.djutils.serialization.SerializationException;
5 import org.sim0mq.Sim0MQException;
6 import org.sim0mq.message.MessageStatus;
7 import org.sim0mq.message.Sim0MQReply;
8 import org.sim0mq.message.SimulationMessage;
9
10
11
12
13
14
15
16
17
18
19 public class MC2AckNakMessage extends Sim0MQReply
20 {
21
22 private final boolean status;
23
24
25 private final String error;
26
27
28 private static final String MESSAGETYPE = "MC.2";
29
30
31 private static final long serialVersionUID = 20190712;
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49 public MC2AckNakMessage(final Object simulationRunId, final Object senderId, final Object receiverId, final long messageId,
50 final long uniqueId, final boolean status, final String error) throws Sim0MQException, NullPointerException
51 {
52 super(simulationRunId, senderId, receiverId, MESSAGETYPE, messageId, MessageStatus.NEW, uniqueId);
53 Throw.whenNull(error, "error cannot be null");
54 this.status = status;
55 this.error = error;
56 }
57
58
59
60
61 public final boolean getStatus()
62 {
63 return this.status;
64 }
65
66
67
68
69 public final String getError()
70 {
71 return this.error;
72 }
73
74
75
76
77 public static final String getMessageType()
78 {
79 return MESSAGETYPE;
80 }
81
82
83 @Override
84 public short getNumberOfPayloadFields()
85 {
86 return 3;
87 }
88
89
90 @Override
91 public Object[] createObjectArray()
92 {
93 return new Object[] {getMagicNumber(), getSimulationRunId(), getSenderId(), getReceiverId(), getMessageTypeId(),
94 getMessageId(), getMessageStatus(), getNumberOfPayloadFields(), getReplyToId(), this.status, this.error};
95 }
96
97
98 @Override
99 public byte[] createByteArray() throws Sim0MQException, SerializationException
100 {
101 return SimulationMessage.encodeUTF8(getSimulationRunId(), getSenderId(), getReceiverId(), getMessageTypeId(),
102 getMessageId(), getMessageStatus(), getReplyToId(), this.status, this.error);
103 }
104
105
106
107
108
109
110
111
112 public static MC2AckNakMessage createMessage(final Object[] fields, final Object intendedReceiverId) throws Sim0MQException
113 {
114 check(fields, 3, MESSAGETYPE, intendedReceiverId);
115 return new MC2AckNakMessage(fields[1], fields[2], fields[3], ((Long) fields[5]).longValue(),
116 ((Long) fields[8]).longValue(), (boolean) fields[9], fields[10].toString());
117 }
118
119
120
121
122
123
124
125
126
127
128
129 public static class Builder extends Sim0MQReply.Builder<MC2AckNakMessage.Builder>
130 {
131
132 private boolean status;
133
134
135 private String error;
136
137
138
139
140 public Builder()
141 {
142
143 }
144
145
146
147
148
149 public final Builder setStatus(final boolean newStatus)
150 {
151 this.status = newStatus;
152 return this;
153 }
154
155
156
157
158
159 public final Builder setError(final String newError)
160 {
161 this.error = newError;
162 return this;
163 }
164
165
166 @Override
167 public MC2AckNakMessage build() throws Sim0MQException, NullPointerException
168 {
169 return new MC2AckNakMessage(this.simulationRunId, this.senderId, this.receiverId, this.messageId, this.replyToId,
170 this.status, this.error);
171 }
172
173 }
174 }