KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > mp > PduHandle


1 /*_############################################################################
2   _##
3   _## SNMP4J - PduHandle.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21 package org.snmp4j.mp;
22
23 /**
24  * The <code>PduHandle</code> class represents an unique key for a SNMP PDU.
25  * It uses an unique transaction ID (request ID) to identify the PDUs.
26  *
27  * @author Frank Fock
28  * @version 1.0.3
29  * @since 1.0
30  */

31 public class PduHandle {
32
33   private static final long serialVersionUID = -6365764428974409942L;
34
35   public static final int NONE = Integer.MIN_VALUE;
36   private int transactionID = NONE;
37
38   /**
39    * Creates a <code>PduHandle</code> with a transaction ID set to {@link #NONE}.
40    */

41   public PduHandle() {
42   }
43
44   /**
45    * Creates a <code>PduHandle</code> for the supplied transaction ID.
46    * @param transactionID
47    * an unqiue transaction ID.
48    */

49   public PduHandle(int transactionID) {
50     setTransactionID(transactionID);
51   }
52
53   /**
54    * Gets the transaction ID of this handle.
55    * @return
56    * the transaction ID.
57    */

58   public int getTransactionID() {
59     return transactionID;
60   }
61
62   /**
63    * Sets the transaction ID which is typically the request ID of the PDU.
64    * @param transactionID
65    * an unqiue transaction ID.
66    */

67   public void setTransactionID(int transactionID) {
68     this.transactionID = transactionID;
69   }
70
71   /**
72    * Copy all members from the supplied <code>PduHandle</code>.
73    * @param other
74    * a PduHandle.
75    */

76   public void copyFrom(PduHandle other) {
77     setTransactionID(other.transactionID);
78   }
79
80   /**
81    * Indicates whether some other object is "equal to" this one.
82    *
83    * @param obj the reference object with which to compare.
84    * @return <code>true</code> if this object is the same as the obj argument;
85    * <code>false</code> otherwise.
86    */

87   public boolean equals(Object JavaDoc obj) {
88     if (obj instanceof PduHandle) {
89       return (transactionID == ((PduHandle)obj).transactionID);
90     }
91     return false;
92   }
93
94   /**
95    * Returns a hash code value for the object.
96    *
97    * @return a hash code value for this object.
98    */

99   public int hashCode() {
100     return transactionID;
101   }
102
103   public String JavaDoc toString() {
104     return "PduHandle["+transactionID+"]";
105   }
106
107 }
108
109
Popular Tags