Open Kilda Java Documentation
Message.java
Go to the documentation of this file.
1 /* Copyright 2017 Telstra Open Source
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 package org.openkilda.messaging;
17 
18 import static com.google.common.base.MoreObjects.toStringHelper;
21 import static org.openkilda.messaging.Utils.PAYLOAD;
22 import static org.openkilda.messaging.Utils.TIMESTAMP;
23 
24 import com.fasterxml.jackson.annotation.JsonCreator;
25 import com.fasterxml.jackson.annotation.JsonInclude;
26 import com.fasterxml.jackson.annotation.JsonProperty;
27 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
28 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
29 
30 import java.io.Serializable;
31 
35 @JsonSerialize
36 @JsonInclude(JsonInclude.Include.NON_NULL)
37 @JsonPropertyOrder({
38  DESTINATION,
39  PAYLOAD,
40  TIMESTAMP,
41  CORRELATION_ID})
42 public class Message extends BaseMessage {
46  private static final long serialVersionUID = 1L;
47 
52  @JsonProperty(CORRELATION_ID)
53  protected String correlationId;
54 
58  @JsonProperty(DESTINATION)
59  protected Destination destination;
60 
68  @JsonCreator
69  public Message(@JsonProperty(TIMESTAMP) final long timestamp,
70  @JsonProperty(CORRELATION_ID) final String correlationId,
71  @JsonProperty(DESTINATION) final Destination destination) {
72  super(timestamp);
73  this.correlationId = correlationId;
74  this.destination = destination;
75  }
76 
83  public Message(final long timestamp, final String correlationId) {
84  super(timestamp);
85  this.correlationId = correlationId;
86  }
87 
93  public String getCorrelationId() {
94  return correlationId;
95  }
96 
103  return destination;
104  }
105 
111  public void setDestination(final Destination destination) {
112  this.destination = destination;
113  }
114 
118  @Override
119  public String toString() {
120  return toStringHelper(this)
121  .add(TIMESTAMP, timestamp)
122  .add(CORRELATION_ID, correlationId)
123  .add(DESTINATION, destination)
124  .toString();
125  }
126 }
127 
static final String PAYLOAD
Definition: Utils.java:57
static final String DESTINATION
Definition: Utils.java:51
void setDestination(final Destination destination)
Definition: Message.java:111
static final String CORRELATION_ID
Definition: Utils.java:43
static final String TIMESTAMP
Definition: Utils.java:35
Message(final long timestamp, final String correlationId)
Definition: Message.java:83