blob: 4b7170e4dac0c39299febfceb1350a0a37615a1c [file] [log] [blame]
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -08001/*
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.drivers.p4runtime.mirror;
18
Carmelo Casconeb4863b32019-03-13 18:54:34 -070019import com.google.common.base.MoreObjects;
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080020import org.onosproject.net.pi.runtime.PiEntity;
21import org.onosproject.store.service.WallClockTimestamp;
22
Carmelo Casconeb4863b32019-03-13 18:54:34 -070023import java.util.Objects;
24
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080025public class TimedEntry<E extends PiEntity> {
26
27 private final long timestamp;
28 private final E entity;
29
30 TimedEntry(long timestamp, E entity) {
31 this.timestamp = timestamp;
32 this.entity = entity;
33 }
34
35 public long timestamp() {
36 return timestamp;
37 }
38
39 public E entry() {
40 return entity;
41 }
42
43 public long lifeSec() {
44 final long now = new WallClockTimestamp().unixTimestamp();
45 return (now - timestamp) / 1000;
46 }
Carmelo Casconeb4863b32019-03-13 18:54:34 -070047
48 @Override
49 public int hashCode() {
50 return Objects.hash(timestamp, entity);
51 }
52
53 @Override
54 public boolean equals(Object obj) {
55 if (this == obj) {
56 return true;
57 }
58 if (obj == null || getClass() != obj.getClass()) {
59 return false;
60 }
61 final TimedEntry other = (TimedEntry) obj;
62 return Objects.equals(this.timestamp, other.timestamp)
63 && Objects.equals(this.entity, other.entity);
64 }
65
66 @Override
67 public String toString() {
68 return MoreObjects.toStringHelper(this)
69 .add("timestamp", timestamp)
70 .add("entity", entity)
71 .toString();
72 }
Carmelo Cascone6a0b5a32017-11-20 23:08:32 -080073}