blob: de538f599742d19093936b1c9933a82b3928e131 [file] [log] [blame]
Charles Chan35a32322017-08-14 11:42:11 -07001/*
2 * Copyright 2017-present Open Networking Foundation
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 */
16
17package org.onosproject.store.host.impl;
18
19import org.onosproject.net.HostId;
20import org.onosproject.net.HostLocation;
21
22import java.util.Objects;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Internal data structure to record the info of a host with location that is under verification.
28 */
29class PendingHostLocation {
30 private HostId hostId;
31 private HostLocation location;
32 private boolean expired;
33
34 /**
35 * Constructs PendingHostLocation.
36 *
37 * @param hostId Host ID
38 * @param location location to be verified
39 */
40 PendingHostLocation(HostId hostId, HostLocation location) {
41 this.hostId = hostId;
42 this.location = location;
43 this.expired = false;
44 }
45
46 /**
47 * Gets HostId of this entry.
48 *
49 * @return host id
50 */
51 HostId hostId() {
52 return hostId;
53 }
54
55 /**
56 * Gets HostLocation of this entry.
57 *
58 * @return host location
59 */
60 HostLocation location() {
61 return location;
62 }
63
64 /**
65 * Determine whether this probe is expired or not.
66 *
67 * @return true if this entry is expired and waiting to be removed from the cache
68 */
69 boolean expired() {
70 return expired;
71 }
72
73 /**
74 * Sets whether this probe is expired or not.
75 *
76 * @param expired true if this entry is expired and waiting to be removed from the cache
77 */
78 void setExpired(boolean expired) {
79 this.expired = expired;
80 }
81
82 @Override
83 public boolean equals(Object o) {
84 if (this == o) {
85 return true;
86 }
87 if (!(o instanceof PendingHostLocation)) {
88 return false;
89 }
90 PendingHostLocation that = (PendingHostLocation) o;
91 return (Objects.equals(this.hostId, that.hostId) &&
92 Objects.equals(this.location, that.location) &&
93 Objects.equals(this.expired, that.expired));
94 }
95 @Override
96 public int hashCode() {
97 return Objects.hash(hostId, location, expired);
98 }
99
100 @Override
101 public String toString() {
102 return toStringHelper(getClass())
103 .add("hostId", hostId)
104 .add("location", location)
105 .add("expired", expired)
106 .toString();
107 }
108}