KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > agent > agentx > master > AgentXRegEntry


1 /*_############################################################################
2   _##
3   _## SNMP4J-AgentX - AgentXRegEntry.java
4   _##
5   _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
6   _##
7   _## This program is free software; you can redistribute it and/or modify
8   _## it under the terms of the GNU General Public License version 2 as
9   _## published by the Free Software Foundation.
10   _##
11   _## This program is distributed in the hope that it will be useful,
12   _## but WITHOUT ANY WARRANTY; without even the implied warranty of
13   _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   _## GNU General Public License for more details.
15   _##
16   _## You should have received a copy of the GNU General Public License
17   _## along with this program; if not, write to the Free Software
18   _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19   _## MA 02110-1301 USA
20   _##
21   _##########################################################################*/

22
23 package org.snmp4j.agent.agentx.master;
24
25 import org.snmp4j.agent.agentx.AgentXRegion;
26 import org.snmp4j.smi.OctetString;
27 import org.snmp4j.smi.OID;
28
29 public class AgentXRegEntry implements Comparable JavaDoc {
30
31   private AgentXMasterSession session;
32   private AgentXRegion region;
33   private int priority;
34   private OctetString context;
35   private int timeout;
36   private OID id;
37
38   public AgentXRegEntry(AgentXMasterSession session,
39                         AgentXRegion region,
40                         int priority,
41                         OctetString context,
42                         int timeout) {
43     this.session = session;
44     this.region = region;
45     this.priority = priority;
46     this.context = context;
47     if (this.context == null) {
48       this.context = new OctetString();
49     }
50     this.timeout = timeout;
51   }
52
53   public OctetString getContext() {
54     return context;
55   }
56
57   public int getPriority() {
58     return priority;
59   }
60
61   public AgentXRegion getRegion() {
62     return region;
63   }
64
65   public AgentXMasterSession getSession() {
66     return session;
67   }
68
69   public int getSpecific() {
70     return region.getLowerBound().size();
71   }
72
73   public int getTimeout() {
74     return timeout;
75   }
76
77   public OID getId() {
78     return id;
79   }
80
81   /**
82    * Compares this object with the specified object for order.
83    *
84    * @param o the Object to be compared.
85    * @return a negative integer, zero, or a positive integer as this object is
86    * less than, equal to, or greater than the specified object.
87    */

88   public int compareTo(Object JavaDoc o) {
89     AgentXRegEntry other = (AgentXRegEntry)o;
90     int diff = other.getSpecific() - getSpecific();
91     if (diff == 0) {
92       diff = getPriority() - other.getPriority();
93     }
94 /* The below is NOT correct since two registrations with the same specific
95    subtree and priority must be deemed equal.
96     if (diff == 0) {
97       diff = getRegion().compareTo(other.getRegion());
98     }
99 */

100     return diff;
101   }
102
103   public boolean equals(Object JavaDoc obj) {
104     if (obj instanceof AgentXRegEntry) {
105       AgentXRegEntry other = (AgentXRegEntry)obj;
106       return session.equals(other.session) &&
107           region.equals(other.region) &&
108           (compareTo(other) == 0);
109     }
110     return false;
111   }
112
113   public int hashCode() {
114     return session.getSessionID() + region.getLowerBound().hashCode();
115   }
116
117   public void setId(OID id) {
118     this.id = id;
119   }
120
121   public String JavaDoc toString() {
122     return getClass().getName()+"[region="+region+
123         ",priority="+priority+
124         ",context="+context+
125         ",timeout="+timeout+
126         ",id="+id+
127         ",session="+session+"]";
128   }
129
130 }
131
Popular Tags