blob: 0abfd12de9b0c835cec828d260c6ec2ca05166d9 [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
18import com.google.common.collect.ImmutableList;
19import org.onosproject.store.Timestamp;
20
21import java.util.List;
22import java.util.Objects;
23
24/**
25 * A wrapper class that contains an intents, its state, and other metadata for
26 * internal use.
27 */
28public class IntentData { //FIXME need to make this "immutable"
29 // manager should be able to mutate a local copy while processing
30 private Intent intent;
31
32 private IntentState state;
33 private Timestamp version;
34
35 private List<Intent> installables;
36
37 public IntentData(Intent intent, IntentState state, Timestamp version) {
38 this.intent = intent;
39 this.state = state;
40 this.version = version;
41 }
42
43 // kryo constructor
44 protected IntentData() {
45 }
46
47 public Intent intent() {
48 return intent;
49 }
50
51 public IntentState state() {
52 return state;
53 }
54
Ray Milkey5b3717e2015-02-05 11:44:08 -080055 public Key key() {
Brian O'Connorcff03322015-02-03 15:28:59 -080056 return intent.key();
57 }
58
Brian O'Connor2ba63fd2015-02-09 22:48:11 -080059 public Timestamp version() {
60 return version;
61 }
62
Brian O'Connorcff03322015-02-03 15:28:59 -080063 public void setState(IntentState newState) {
64 this.state = newState;
65 }
66
Brian O'Connor2ba63fd2015-02-09 22:48:11 -080067 /**
68 * Sets the version for this intent data.
69 * <p>
70 * The store should call this method only once when the IntentData is
71 * first passed into the pending map. Ideally, an IntentData is timestamped
72 * on the same thread that the called used to submit the intents.
73 * </p>
74 *
75 * @param version the version/timestamp for this intent data
76 */
77 public void setVersion(Timestamp version) {
78 this.version = version;
79 }
80
Brian O'Connorcff03322015-02-03 15:28:59 -080081 public void setInstallables(List<Intent> installables) {
82 this.installables = ImmutableList.copyOf(installables);
83 }
84
85 public List<Intent> installables() {
86 return installables;
87 }
88
89 @Override
90 public int hashCode() {
91 return Objects.hash(intent, version);
92 }
93
94 @Override
95 public boolean equals(Object obj) {
96 if (this == obj) {
97 return true;
98 }
99 if (obj == null || getClass() != obj.getClass()) {
100 return false;
101 }
102 final IntentData other = (IntentData) obj;
103 return Objects.equals(this.intent, other.intent)
104 && Objects.equals(this.version, other.version);
105 }
106}