KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > event > ResponseEvent


1 /*_############################################################################
2   _##
3   _## SNMP4J - ResponseEvent.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.event;
22
23 import java.util.EventObject JavaDoc;
24
25 import org.snmp4j.PDU;
26 import org.snmp4j.smi.Address;
27 // Imports needed for JavaDoc
28
import org.snmp4j.Session;
29
30 /**
31  * <code>ResponseEvent</code> associates a request PDU with the corresponding
32  * response and an optional user object.
33  *
34  * @author Frank Fock
35  * @version 1.1
36  */

37 public class ResponseEvent extends EventObject JavaDoc {
38
39   private static final long serialVersionUID = 3966730838956160070L;
40
41   private Address peerAddress;
42   private PDU request;
43   private PDU response;
44   private Object JavaDoc userObject;
45   private Exception JavaDoc error;
46
47   /**
48    * Creates an <code>ResponseEvent</code> instance.
49    * @param source
50    * the event source.
51    * @param peerAddress
52    * the transport address of the entity that send the response.
53    * @param request
54    * the request PDU (must not be <code>null</code>).
55    * @param response
56    * the response PDU or <code>null</code> if the request timed out.
57    * @param userObject
58    * an optional user object.
59    */

60   public ResponseEvent(Object JavaDoc source, Address peerAddress,
61                        PDU request, PDU response, Object JavaDoc userObject) {
62     super(source);
63     setPeerAddress(peerAddress);
64     setRequest(request);
65     setResponse(response);
66     setUserObject(userObject);
67   }
68
69   /**
70    * Creates an <code>ResponseEvent</code> instance with an exception object
71    * indicating a message processing error.
72    * @param source
73    * the event source.
74    * @param peerAddress
75    * the transport address of the entity that send the response.
76    * @param request
77    * the request PDU (must not be <code>null</code>).
78    * @param response
79    * the response PDU or <code>null</code> if the request timed out.
80    * @param userObject
81    * an optional user object.
82    * @param error
83    * an <code>Exception</code>.
84    */

85   public ResponseEvent(Object JavaDoc source,
86                        Address peerAddress,
87                        PDU request, PDU response,
88                        Object JavaDoc userObject,
89                        Exception JavaDoc error) {
90     this(source, peerAddress, request, response, userObject);
91     this.error = error;
92   }
93
94   /**
95    * Gets the request PDU.
96    * @return
97    * a <code>PDU</code>.
98    */

99   public PDU getRequest() {
100     return request;
101   }
102
103   protected final void setPeerAddress(Address peerAddress) {
104     this.peerAddress = peerAddress;
105   }
106
107   protected final void setRequest(PDU request) {
108     this.request = request;
109   }
110
111   protected final void setResponse(PDU response) {
112     this.response = response;
113   }
114
115   /**
116    * Gets the response PDU.
117    * @return
118    * a PDU instance if a response has been received. If the request
119    * timed out then <code>null</code> will be returned.
120    */

121   public PDU getResponse() {
122     return response;
123   }
124
125   protected final void setUserObject(Object JavaDoc userObject) {
126     this.userObject = userObject;
127   }
128
129   /**
130    * Gets the user object that has been supplied to the asynchronous request
131    * {@link Session#send(PDU pdu, Target target, Object userHandle,
132    * ResponseListener listener)}.
133    * @return
134    * an Object.
135    */

136   public Object JavaDoc getUserObject() {
137     return userObject;
138   }
139
140   /**
141    * Gets the exception object from the exception that has been generated
142    * when the request processing has failed due to an error.
143    * @return
144    * an <code>Exception</code> instance.
145    */

146   public Exception JavaDoc getError() {
147     return error;
148   }
149
150   /**
151    * Gets the transport address of the response sender.
152    * @return
153    * the transport <code>Address</code> of the command responder that send
154    * this response, or <code>null</code> if no response has been received
155    * within the time-out interval or if an error occured (see
156    * {@link #getError()}).
157    */

158   public Address getPeerAddress() {
159     return peerAddress;
160   }
161
162 }
163
Popular Tags