001: /*_############################################################################
002: _##
003: _## SNMP4J-AgentX - AgentXRegEntry.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## This program is free software; you can redistribute it and/or modify
008: _## it under the terms of the GNU General Public License version 2 as
009: _## published by the Free Software Foundation.
010: _##
011: _## This program is distributed in the hope that it will be useful,
012: _## but WITHOUT ANY WARRANTY; without even the implied warranty of
013: _## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: _## GNU General Public License for more details.
015: _##
016: _## You should have received a copy of the GNU General Public License
017: _## along with this program; if not, write to the Free Software
018: _## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
019: _## MA 02110-1301 USA
020: _##
021: _##########################################################################*/
022:
023: package org.snmp4j.agent.agentx.master;
024:
025: import org.snmp4j.agent.agentx.AgentXRegion;
026: import org.snmp4j.smi.OctetString;
027: import org.snmp4j.smi.OID;
028:
029: public class AgentXRegEntry implements Comparable {
030:
031: private AgentXMasterSession session;
032: private AgentXRegion region;
033: private int priority;
034: private OctetString context;
035: private int timeout;
036: private OID id;
037:
038: public AgentXRegEntry(AgentXMasterSession session,
039: AgentXRegion region, int priority, OctetString context,
040: int timeout) {
041: this .session = session;
042: this .region = region;
043: this .priority = priority;
044: this .context = context;
045: if (this .context == null) {
046: this .context = new OctetString();
047: }
048: this .timeout = timeout;
049: }
050:
051: public OctetString getContext() {
052: return context;
053: }
054:
055: public int getPriority() {
056: return priority;
057: }
058:
059: public AgentXRegion getRegion() {
060: return region;
061: }
062:
063: public AgentXMasterSession getSession() {
064: return session;
065: }
066:
067: public int getSpecific() {
068: return region.getLowerBound().size();
069: }
070:
071: public int getTimeout() {
072: return timeout;
073: }
074:
075: public OID getId() {
076: return id;
077: }
078:
079: /**
080: * Compares this object with the specified object for order.
081: *
082: * @param o the Object to be compared.
083: * @return a negative integer, zero, or a positive integer as this object is
084: * less than, equal to, or greater than the specified object.
085: */
086: public int compareTo(Object o) {
087: AgentXRegEntry other = (AgentXRegEntry) o;
088: int diff = other.getSpecific() - getSpecific();
089: if (diff == 0) {
090: diff = getPriority() - other.getPriority();
091: }
092: /* The below is NOT correct since two registrations with the same specific
093: subtree and priority must be deemed equal.
094: if (diff == 0) {
095: diff = getRegion().compareTo(other.getRegion());
096: }
097: */
098: return diff;
099: }
100:
101: public boolean equals(Object obj) {
102: if (obj instanceof AgentXRegEntry) {
103: AgentXRegEntry other = (AgentXRegEntry) obj;
104: return session.equals(other.session)
105: && region.equals(other.region)
106: && (compareTo(other) == 0);
107: }
108: return false;
109: }
110:
111: public int hashCode() {
112: return session.getSessionID()
113: + region.getLowerBound().hashCode();
114: }
115:
116: public void setId(OID id) {
117: this .id = id;
118: }
119:
120: public String toString() {
121: return getClass().getName() + "[region=" + region
122: + ",priority=" + priority + ",context=" + context
123: + ",timeout=" + timeout + ",id=" + id + ",session="
124: + session + "]";
125: }
126:
127: }
|