Open Kilda Java Documentation
BaseFlow.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.command.flow;
17 
18 import static org.openkilda.messaging.Utils.FLOW_ID;
20 
24 
25 import com.fasterxml.jackson.annotation.JsonCreator;
26 import com.fasterxml.jackson.annotation.JsonInclude;
27 import com.fasterxml.jackson.annotation.JsonProperty;
28 import com.fasterxml.jackson.annotation.JsonPropertyOrder;
29 
33 @JsonInclude(JsonInclude.Include.NON_NULL)
34 @JsonPropertyOrder({
35  TRANSACTION_ID,
36  FLOW_ID,
37  "cookie",
38  "switch_id"})
39 public class BaseFlow extends CommandData {
43  @JsonProperty(TRANSACTION_ID)
44  protected Long transactionId;
45 
49  @JsonProperty(FLOW_ID)
50  protected String id;
51 
55  @JsonProperty("cookie")
56  protected Long cookie;
57 
61  @JsonProperty("switch_id")
62  protected SwitchId switchId;
63 
73  @JsonCreator
74  public BaseFlow(@JsonProperty(TRANSACTION_ID) final Long transactionId,
75  @JsonProperty(FLOW_ID) final String id,
76  @JsonProperty("cookie") final Long cookie,
77  @JsonProperty("switch_id") final SwitchId switchId) {
78  setTransactionId(transactionId);
79  setId(id);
80  setCookie(cookie);
81  setSwitchId(switchId);
82  }
83 
89  public Long getTransactionId() {
90  return transactionId;
91  }
92 
98  public void setTransactionId(final Long transactionId) {
99  this.transactionId = transactionId;
100  }
101 
107  public String getId() {
108  return id;
109  }
110 
116  public void setId(final String id) {
117  if (id == null || id.isEmpty()) {
118  throw new IllegalArgumentException("flow id must be set");
119  }
120  this.id = id;
121  }
122 
128  public Long getCookie() {
129  return cookie;
130  }
131 
137  public void setCookie(final Long cookie) {
138  this.cookie = cookie;
139  }
140 
147  return switchId;
148  }
149 
155  public void setSwitchId(SwitchId switchId) {
156  if (switchId == null) {
157  throw new IllegalArgumentException("need to set a switch_id");
158  } else if (!Utils.validateSwitchId(switchId)) {
159  throw new IllegalArgumentException("need to set valid value for switch_id");
160  }
161  this.switchId = switchId;
162  }
163 }
static boolean validateSwitchId(SwitchId switchId)
Definition: Utils.java:144
id
Definition: nodes.py:55
void setTransactionId(final Long transactionId)
Definition: BaseFlow.java:98
static final String TRANSACTION_ID
Definition: Utils.java:39
static final String FLOW_ID
Definition: Utils.java:61