View Javadoc

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.lisp.proto.rev151105.eid.container.Eid;
13  import org.opendaylight.yang.gen.v1.urn.opendaylight.lfm.lisp.proto.rev151105.rloc.container.Rloc;
14  
15  /**
16   * Request source RLOC in the mapping service with it's properties.
17   */
18  public class SubscriberRLOC {
19      private Rloc rloc;
20      private Eid eid;
21      private Date lastRequestDate;
22      private static final long SUBSCRIBER_TIMEOUT = 86400000L; /* 1 day (default Cisco IOS mapping TTL) */
23  
24      public SubscriberRLOC(Rloc srcRloc, Eid srcEid) {
25          this(srcRloc, srcEid, new Date(System.currentTimeMillis()));
26      }
27  
28      public SubscriberRLOC(Rloc srcRloc, Eid srcEid,
29              Date lastRequestDate) {
30          super();
31          this.rloc = srcRloc;
32          this.eid = srcEid;
33          this.lastRequestDate = lastRequestDate;
34      }
35  
36      public Rloc getSrcRloc() {
37          return rloc;
38      }
39  
40      public void setSrcRloc(Rloc srcRloc) {
41          this.rloc = srcRloc;
42      }
43  
44      public Eid getSrcEid() {
45          return eid;
46      }
47  
48      public void setSrcEid(Eid srcEid) {
49          this.eid = srcEid;
50      }
51  
52      public Date getLastRequestDate() {
53          return lastRequestDate;
54      }
55  
56      public void setLastRequestDate(Date lastRequestDate) {
57          this.lastRequestDate = lastRequestDate;
58      }
59  
60      public boolean timedOut() {
61          return System.currentTimeMillis() - lastRequestDate.getTime() > SUBSCRIBER_TIMEOUT;
62      }
63  
64      @Override
65      public int hashCode() {
66          final int prime = 31;
67          int result = 1;
68          result = prime * result + ((rloc == null) ? 0 : rloc.hashCode());
69          result = prime * result + ((eid == null) ? 0 : eid.hashCode());
70          return result;
71      }
72  
73      @Override
74      public boolean equals(Object obj) {
75          if (this == obj) {
76              return true;
77          }
78          if (obj == null) {
79              return false;
80          }
81          if (getClass() != obj.getClass()) {
82              return false;
83          }
84          SubscriberRLOC other = (SubscriberRLOC) obj;
85          if (!rloc.equals(other.rloc)) {
86              return false;
87          }
88          return true;
89      }
90  
91      @Override
92      public String toString() {
93          return "_rloc=" + rloc.toString() + ", _eid=" + eid.toString()
94                  + ", last request @ " + lastRequestDate.toString();
95      }
96  }