blob: 05a8f77d032011433751d41d839ee91efca5f712 [file] [log] [blame]
jobind19b7142019-05-17 09:46:52 -04001/*
2 * Copyright 2015-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.net.host.impl;
18
19import org.onosproject.net.HostLocation;
20
21import java.util.Objects;
22import java.util.Set;
23
24import static com.google.common.base.MoreObjects.toStringHelper;
25
26/**
27 * Used for tracking of the host move.
28 */
29public class HostMoveTracker {
30 private Integer counter;
31 private Long timeStamp;
32 private Set<HostLocation> locations;
33
34 /**
35 * Initialize the instance of HostMoveTracker.
36 *
37 * @param locations List of locations where host is present
38 */
39 public HostMoveTracker(Set<HostLocation> locations) {
40 counter = 1;
41 timeStamp = System.currentTimeMillis();
42 this.locations = locations;
43 }
44
45 /**
46 * Updates locations in HostMoveTracker.
47 *
48 * @param locations List of locations where host is present
49 */
50 public void updateHostMoveTracker(Set<HostLocation> locations) {
51 counter += 1;
52 timeStamp = System.currentTimeMillis();
53 this.locations = locations;
54 }
55
56 /**
57 * Reset hostmove count,timestamp and updated locations.
58 *
59 * @param locations List of locations where host is present
60 */
61 public void resetHostMoveTracker(Set<HostLocation> locations) {
62 counter = 0;
63 timeStamp = System.currentTimeMillis();
64 this.locations = locations;
65 }
66
67 /**
68 * Reset hostmove count and timestamp.
69 */
70 public void resetHostMoveTracker() {
71 counter = 0;
72 timeStamp = System.currentTimeMillis();
73 }
74
75 public Long getTimeStamp() {
76 return timeStamp;
77 }
78
79 public Integer getCounter() {
80 return counter;
81 }
82
83
84 public Set<HostLocation> getLocations() {
85 return locations;
86 }
87
88 @Override
89 public boolean equals(Object o) {
90 if (this == o) {
91 return true;
92 }
93 if (o == null || getClass() != o.getClass()) {
94 return false;
95 }
96 HostMoveTracker that = (HostMoveTracker) o;
97 return Objects.equals(locations, that.locations) &&
98 Objects.equals(counter, that.counter);
99 }
100
101 @Override
102 public int hashCode() {
103
104 return Objects.hash(locations, counter);
105 }
106
107 @Override
108 public String toString() {
109 return toStringHelper(this)
110 .add("counter", getCounter())
111 .add("timeStamp", getTimeStamp())
112 .add("locations", getLocations())
113 .toString();
114 }
115}