blob: ce64ecc09ee611c8b522eb2f643fd828b4f32555 [file] [log] [blame]
Brian O'Connorcff03322015-02-03 15:28:59 -08001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.net.intent;
17
Ray Milkey65cb59a2015-02-10 15:18:26 -080018import com.google.common.base.MoreObjects;
Brian O'Connorcff03322015-02-03 15:28:59 -080019import com.google.common.collect.ImmutableList;
20import org.onosproject.store.Timestamp;
21
22import java.util.List;
23import java.util.Objects;
24
25/**
26 * A wrapper class that contains an intents, its state, and other metadata for
27 * internal use.
28 */
29public class IntentData { //FIXME need to make this "immutable"
30 // manager should be able to mutate a local copy while processing
31 private Intent intent;
32
33 private IntentState state;
34 private Timestamp version;
35
36 private List<Intent> installables;
37
38 public IntentData(Intent intent, IntentState state, Timestamp version) {
39 this.intent = intent;
40 this.state = state;
41 this.version = version;
42 }
43
44 // kryo constructor
45 protected IntentData() {
46 }
47
48 public Intent intent() {
49 return intent;
50 }
51
52 public IntentState state() {
53 return state;
54 }
55
Ray Milkey5b3717e2015-02-05 11:44:08 -080056 public Key key() {
Brian O'Connorcff03322015-02-03 15:28:59 -080057 return intent.key();
58 }
59
Brian O'Connor2ba63fd2015-02-09 22:48:11 -080060 public Timestamp version() {
61 return version;
62 }
63
Brian O'Connorcff03322015-02-03 15:28:59 -080064 public void setState(IntentState newState) {
65 this.state = newState;
66 }
67
Brian O'Connor2ba63fd2015-02-09 22:48:11 -080068 /**
69 * Sets the version for this intent data.
70 * <p>
71 * The store should call this method only once when the IntentData is
72 * first passed into the pending map. Ideally, an IntentData is timestamped
73 * on the same thread that the called used to submit the intents.
74 * </p>
75 *
76 * @param version the version/timestamp for this intent data
77 */
78 public void setVersion(Timestamp version) {
79 this.version = version;
80 }
81
Brian O'Connorcff03322015-02-03 15:28:59 -080082 public void setInstallables(List<Intent> installables) {
83 this.installables = ImmutableList.copyOf(installables);
84 }
85
86 public List<Intent> installables() {
87 return installables;
88 }
89
90 @Override
91 public int hashCode() {
92 return Objects.hash(intent, version);
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (this == obj) {
98 return true;
99 }
100 if (obj == null || getClass() != obj.getClass()) {
101 return false;
102 }
103 final IntentData other = (IntentData) obj;
104 return Objects.equals(this.intent, other.intent)
105 && Objects.equals(this.version, other.version);
106 }
Ray Milkey65cb59a2015-02-10 15:18:26 -0800107
108 public String toString() {
109 return MoreObjects.toStringHelper(getClass())
110 .add("key", key())
111 .add("state", state())
112 .add("version", version())
113 .toString();
114 }
115
Brian O'Connorcff03322015-02-03 15:28:59 -0800116}