3923a99ef07690c32bd0daea943a6772f28d7211
[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.urn.opendaylight.lfm.control.plane.rev150314.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 LispAddressContainer eid;
20     private Date lastRequestDate;
21     private static final long SUBSCRIBER_TIMEOUT = 600000;    /* milliseconds */
22
23     public MappingServiceSubscriberRLOC(LispAddressContainer srcRloc, LispAddressContainer srcEid) {
24         this(srcRloc, srcEid, new Date(System.currentTimeMillis()));
25     }
26
27     public MappingServiceSubscriberRLOC(LispAddressContainer srcRloc, LispAddressContainer srcEid,
28             Date lastRequestDate) {
29         super();
30         this.rloc = srcRloc;
31         this.eid = srcEid;
32         this.lastRequestDate = lastRequestDate;
33     }
34
35     public LispAddressContainer getSrcRloc() {
36         return rloc;
37     }
38
39     public void setSrcRloc(LispAddressContainer srcRloc) {
40         this.rloc = srcRloc;
41     }
42
43     public LispAddressContainer getSrcEid() {
44         return eid;
45     }
46
47     public void setSrcEid(LispAddressContainer srcEid) {
48         this.eid = srcEid;
49     }
50
51     public Date getLastRequestDate() {
52         return lastRequestDate;
53     }
54
55     public void setLastRequestDate(Date lastRequestDate) {
56         this.lastRequestDate = lastRequestDate;
57     }
58
59     public boolean timedOut() {
60         return System.currentTimeMillis() - lastRequestDate.getTime() > SUBSCRIBER_TIMEOUT;
61     }
62
63     @Override
64     public int hashCode() {
65         final int prime = 31;
66         int result = 1;
67         result = prime * result + ((rloc == null) ? 0 : rloc.hashCode());
68         result = prime * result + ((eid == null) ? 0 : eid.hashCode());
69         return result;
70     }
71
72     @Override
73     public boolean equals(Object obj) {
74         if (this == obj)
75             return true;
76         if (obj == null)
77             return false;
78         if (getClass() != obj.getClass())
79             return false;
80         MappingServiceSubscriberRLOC other = (MappingServiceSubscriberRLOC) obj;
81         if (!rloc.equals(other.rloc))
82             return false;
83         return true;
84     }
85
86     @Override
87     public String toString() {
88         return "_rloc=" + rloc.toString() + ", _eid=" + eid.toString()
89                 + ", last request @ " + lastRequestDate.toString();
90     }
91 }