KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > CommandResponderEvent


1 /*_############################################################################
2   _##
3   _## SNMP4J - CommandResponderEvent.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;
22
23 import java.util.EventObject JavaDoc;
24 import org.snmp4j.mp.StateReference;
25 import org.snmp4j.smi.Address;
26 import org.snmp4j.mp.PduHandle;
27 import org.snmp4j.smi.OctetString;
28
29 /**
30  * The <code>CommandResponderEvent</code> is fired by the
31  * <code>MessageDispatcher</code> to listeners that potentially can process
32  * the included request, report, or trap/notification.
33  *
34  * @author Jochen Katz & Frank Fock
35  * @version 1.1
36  */

37 public class CommandResponderEvent extends EventObject JavaDoc {
38
39   private static final long serialVersionUID = 1969372060103366769L;
40
41   private int securityModel;
42   private int securityLevel;
43   private int maxSizeResponsePDU;
44   private PduHandle pduHandle;
45   private StateReference stateReference;
46   private PDU pdu;
47   private int messageProcessingModel;
48   private byte[] securityName;
49   private boolean processed;
50   private Address peerAddress;
51   private transient TransportMapping transportMapping;
52
53   /**
54    * Constructs an event for processing an incoming request or notification PDU.
55    * @param messageDispatcher
56    * the source of the event. May be used to send response PDUs.
57    * @param transportMapping
58    * the <code>TransportMapping</code> which received the PDU.
59    * @param sourceAddress
60    * the source transport address of the SNMP message.
61    * @param messageProcessingModel
62    * the message processing model ID.
63    * @param securityModel
64    * the security model ID.
65    * @param securityName
66    * the principal.
67    * @param securityLevel
68    * the requested security level.
69    * @param pduHandle
70    * the PDU handle that uniquely identifies the <code>pdu</code>.
71    * @param pdu
72    * the SNMP request PDU to process.
73    * @param maxSizeResponseScopedPDU
74    * the maximum size of a possible response PDU.
75    * @param stateReference
76    * needed for responding a request, will be <code>null</code> for
77    * notifications.
78    */

79   public CommandResponderEvent(MessageDispatcher messageDispatcher,
80                                TransportMapping transportMapping,
81                                Address sourceAddress,
82                                int messageProcessingModel,
83                                int securityModel,
84                                byte[] securityName,
85                                int securityLevel,
86                                PduHandle pduHandle,
87                                PDU pdu,
88                                int maxSizeResponseScopedPDU,
89                                StateReference stateReference) {
90     super(messageDispatcher);
91     setTransportMapping(transportMapping);
92     setMessageProcessingModel(messageProcessingModel);
93     setSecurityModel(securityModel);
94     setSecurityName(securityName);
95     setSecurityLevel(securityLevel);
96     setPduHandle(pduHandle);
97     setPDU(pdu);
98     setMaxSizeResponsePDU(maxSizeResponseScopedPDU);
99     setStateReference(stateReference);
100     setPeerAddress(sourceAddress);
101   }
102
103   /**
104    * Creates shallow copy of the supplied <code>CommandResponderEvent</code>
105    * but the source of the event is set to the supplied source.
106    *
107    * @param source
108    * the (new) source of event copy to create.
109    * @param other
110    * the <code>CommandResponderEvent</code> to copy.
111    * @since 1.1
112    */

113   public CommandResponderEvent(Object JavaDoc source, CommandResponderEvent other) {
114     super(source);
115     setTransportMapping(other.transportMapping);
116     setMessageProcessingModel(other.messageProcessingModel);
117     setSecurityModel(other.securityModel);
118     setSecurityName(other.securityName);
119     setSecurityLevel(other.securityLevel);
120     setPduHandle(other.pduHandle);
121     setPDU(other.pdu);
122     setMaxSizeResponsePDU(other.maxSizeResponsePDU);
123     setStateReference(other.stateReference);
124     setPeerAddress(other.getPeerAddress());
125   }
126
127   /**
128    * Gets the message dispatcher instance that received the command
129    * (request PDU) or unconfirmed PDU like a report, trap, or notification..
130    * @return
131    * the <code>MessageDispatcher</code> instance that received the command.
132    */

133   public MessageDispatcher getMessageDispatcher() {
134     return (MessageDispatcher)super.getSource();
135   }
136
137   /**
138    * Gets the security model used by the command.
139    * @return int
140    */

141   public int getSecurityModel() {
142     return securityModel;
143   }
144   public void setSecurityModel(int securityModel) {
145     this.securityModel = securityModel;
146   }
147   public void setSecurityLevel(int securityLevel) {
148     this.securityLevel = securityLevel;
149   }
150   public int getSecurityLevel() {
151     return securityLevel;
152   }
153   public void setMaxSizeResponsePDU(int maxSizeResponsePDU) {
154     this.maxSizeResponsePDU = maxSizeResponsePDU;
155   }
156   public int getMaxSizeResponsePDU() {
157     return maxSizeResponsePDU;
158   }
159   public void setPduHandle(org.snmp4j.mp.PduHandle pduHandle) {
160     this.pduHandle = pduHandle;
161   }
162   public PduHandle getPduHandle() {
163     return pduHandle;
164   }
165   public void setStateReference(org.snmp4j.mp.StateReference stateReference) {
166     this.stateReference = stateReference;
167   }
168   public org.snmp4j.mp.StateReference getStateReference() {
169     return stateReference;
170   }
171   public void setPDU(PDU pdu) {
172     this.pdu = pdu;
173   }
174   public PDU getPDU() {
175     return pdu;
176   }
177   public void setMessageProcessingModel(int messageProcessingModel) {
178     this.messageProcessingModel = messageProcessingModel;
179   }
180   public int getMessageProcessingModel() {
181     return messageProcessingModel;
182   }
183   public void setSecurityName(byte[] securityName) {
184     this.securityName = securityName;
185   }
186   public byte[] getSecurityName() {
187     return securityName;
188   }
189
190   /**
191    * Sets the status of this PDU.
192    * @param processed
193    * If set to <code>true</code>, the dispatcher stops dispatching this
194    * event to other event listeners, because it has been successfully
195    * processed.
196    */

197   public void setProcessed(boolean processed) {
198     this.processed = processed;
199   }
200
201   /**
202    * Checks whether this event is already processed or not.
203    * @return
204    * <code>true</code> if this event has been processed, <code>false</code>
205    * otherwise.
206    */

207   public boolean isProcessed() {
208     return processed;
209   }
210
211   /**
212    * Gets the transport address of the sending entity.
213    * @return
214    * the <code>Address</code> of the PDU sender.
215    */

216   public Address getPeerAddress() {
217     return peerAddress;
218   }
219
220   /**
221    * Returns the transport mapping that received the PDU that triggered this
222    * event.
223    * @return
224    * a <code>TransportMapping</code> instance.
225    */

226   public TransportMapping getTransportMapping() {
227     return transportMapping;
228   }
229
230   /**
231    * Sets the transport address of the sending entity.
232    * @param peerAddress
233    * the <code>Address</code> of the PDU sender.
234    */

235   public void setPeerAddress(Address peerAddress) {
236     this.peerAddress = peerAddress;
237   }
238
239   protected void setTransportMapping(TransportMapping transportMapping) {
240     this.transportMapping = transportMapping;
241   }
242
243   public String JavaDoc toString() {
244     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
245     buf.append("CommandResponderEvent[");
246     buf.append("transportMapping=");
247     buf.append(transportMapping);
248     buf.append("peerAddress=");
249     buf.append(peerAddress);
250     buf.append(", processed=");
251     buf.append(processed);
252     buf.append(", pdu=[");
253     buf.append(pdu);
254     buf.append("], securityName=");
255     buf.append(new OctetString(securityName));
256     buf.append(", securityModel=");
257     buf.append(securityModel);
258     buf.append(", securityLevel=");
259     buf.append(securityLevel);
260     buf.append("]");
261     return buf.toString();
262   }
263 }
264
265
Popular Tags