89a6ed1bacca28f683ee88d809c0779c7dafd0c5
[lispflowmapping.git] / mappingservice / api / src / main / java / org / opendaylight / lispflowmapping / interfaces / dao / MappingServiceSubscriberRLOC.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.lispflowmapping.interfaces.dao;
9
10 import java.util.Date;
11
12 import org.opendaylight.yang.gen.v1.lispflowmapping.rev131031.lispaddress.LispAddressContainer;
13
14 /**
15  * Request source RLOC in the mapping service with it's properties.
16  */
17 public class MappingServiceSubscriberRLOC {
18     private LispAddressContainer rloc;
19     private Date lastRequestDate;
20     private static final long SUBSCRIBER_TIMEOUT = 600000;    /* milliseconds */
21
22     public MappingServiceSubscriberRLOC(LispAddressContainer srcRloc) {
23         this(srcRloc, new Date(System.currentTimeMillis()));
24     }
25
26     public MappingServiceSubscriberRLOC(LispAddressContainer srcRloc, Date lastRequestDate) {
27         super();
28         this.rloc = srcRloc;
29         this.lastRequestDate = lastRequestDate;
30     }
31
32     public LispAddressContainer getSrcRloc() {
33         return rloc;
34     }
35
36     public void setSrcRloc(LispAddressContainer srcRloc) {
37         this.rloc = srcRloc;
38     }
39
40     public Date getLastRequestDate() {
41         return lastRequestDate;
42     }
43
44     public void setLastRequestDate(Date lastRequestDate) {
45         this.lastRequestDate = lastRequestDate;
46     }
47
48     public boolean timedOut() {
49         return System.currentTimeMillis() - lastRequestDate.getTime() > SUBSCRIBER_TIMEOUT;
50     }
51
52     @Override
53     public int hashCode() {
54         return rloc.hashCode();
55     }
56
57     @Override
58     public boolean equals(Object obj) {
59         if (this == obj)
60             return true;
61         if (obj == null)
62             return false;
63         if (getClass() != obj.getClass())
64             return false;
65         MappingServiceSubscriberRLOC other = (MappingServiceSubscriberRLOC) obj;
66         if (!rloc.equals(other.rloc))
67             return false;
68         return true;
69     }
70
71     @Override
72     public String toString() {
73         return rloc.toString() + ", last request @ " + lastRequestDate.toString();
74     }
75 }