|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.snmp4j.Snmp
public class Snmp
The Snmp class is the core of SNMP4J. It provides functions to
send and receive SNMP PDUs. All SNMP PDU types can be send. Confirmed
PDUs can be sent synchronously and asynchronously.
The Snmp class is transport protocol independent. Support for
a specific TransportMapping instance is added by calling the
addTransportMapping(TransportMapping transportMapping) method or
creating a Snmp instance by using the non-default constructor
with the corresponding transport mapping. Transport mappings are used
for incoming and outgoing messages.
To setup a default SNMP session for UDP transport and with SNMPv3 support the following code snippet can be used:
Address targetAddress = GenericAddress.parse("udp:127.0.0.1/161");
TransportMapping transport = new DefaultUdpTransportMapping();
snmp = new Snmp(transport);
USM usm = new USM(SecurityProtocols.getInstance(),
new OctetString(MPv3.createLocalEngineID()), 0);
SecurityModels.getInstance().addSecurityModel(usm);
transport.listen();
How a synchronous SNMPv3 message with authentication and privacy is then sent illustrates the following code snippet:
// add user to the USM
snmp.getUSM().addUser(new OctetString("MD5DES"),
new UsmUser(new OctetString("MD5DES"),
AuthMD5.ID,
new OctetString("MD5DESUserAuthPassword"),
PrivDES.ID,
new OctetString("MD5DESUserPrivPassword")));
// create the target
UserTarget target = new UserTarget();
target.setAddress(targetAddress);
target.setRetries(1);
target.setTimeout(5000);
target.setVersion(SnmpConstants.version3);
target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
target.setSecurityName(new OctetString("MD5DES"));
// create the PDU
PDU pdu = new ScopedPDU();
pdu.add(new VariableBinding(new OID("1.3.6")));
pdu.setType(PDU.GETNEXT);
// send the PDU
ResponseEvent response = snmp.send(pdu, target);
// extract the response PDU (could be null if timed out)
PDU responsePDU = response.getResponse();
// extract the address used by the agent to send the response:
Address peerAddress = response.getPeerAddress();
An asynchronous SNMPv1 request is sent by the following code:
// setting up target
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString("public"));
target.setAddress(targetAddress);
target.setRetries(2);
target.setTimeout(1500);
target.setVersion(SnmpConstants.version1);
// creating PDU
PDU pdu = new PDU();
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,1})));
pdu.add(new VariableBinding(new OID(new int[] {1,3,6,1,2,1,1,2})));
pdu.setType(PDU.GETNEXT);
// sending request
ResponseListener listener = new ResponseListener() {
public void onResponse(ResponseEvent event) {
// Always cancel async request when response has been received
// otherwise a memory leak is created! Not canceling a request
// immediately can be useful when sending a request to a broadcast
// address.
((Snmp)event.getSource()).cancel(event.getRequest(), this);
System.out.println("Received response PDU is: "+event.getResponse());
}
};
snmp.sendPDU(pdu, target, null, listener);
Traps (notifications) and other SNMP PDUs can be received by adding the
folling code to the first code snippet above:
CommandResponder trapPrinter = new CommandResponder() {
public synchronized void processPdu(CommandResponderEvent e) {
PDU command = e.getPDU();
if (command != null) {
System.out.println(command.toString());
}
}
};
snmp.addCommandResponder(trapPrinter);
| Nested Class Summary | |
|---|---|
static interface |
Snmp.ReportHandler
Interface for handling reports. |
| Constructor Summary | |
|---|---|
Snmp()
Creates a Snmp instance that uses a
MessageDispatcherImpl with no message processing
models and no security protols (by default). |
|
Snmp(MessageDispatcher messageDispatcher)
Creates a Snmp instance by supplying a
MessageDispatcher. |
|
Snmp(MessageDispatcher messageDispatcher,
TransportMapping transportMapping)
Creates a Snmp instance by supplying a
MessageDispatcher and a TransportMapping. |
|
Snmp(TransportMapping transportMapping)
Creates a Snmp instance that uses a
MessageDispatcherImpl with all supported message processing
models and the default security protols for dispatching. |
|
| Method Summary | |
|---|---|
void |
addCommandResponder(CommandResponder listener)
Adds a CommandResponder to this SNMP session. |
boolean |
addNotificationListener(Address listenAddress,
CommandResponder listener)
Adds a notification listener to this Snmp instance. |
void |
addTransportMapping(TransportMapping transportMapping)
Adds a TransportMapping to this SNMP session. |
void |
cancel(PDU request,
ResponseListener listener)
Cancels an asynchronous request. |
void |
close()
Closes the session and frees any allocated resources, i.e. sockets and the internal thread for processing request timeouts. |
byte[] |
discoverAuthoritativeEngineID(Address address,
long timeout)
Discovers the engine ID of the SNMPv3 entity denoted by the supplied address. |
protected void |
fireProcessPdu(CommandResponderEvent event)
Fires a CommandResponderEvent event to inform listeners about
a received PDU. |
ResponseEvent |
get(PDU pdu,
Target target)
Sends a GET request to a target. |
void |
get(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a GET request PDU to the given target. |
ResponseEvent |
getBulk(PDU pdu,
Target target)
Sends a GETBULK request to a target. |
void |
getBulk(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a GETBULK request PDU to the given
target. |
byte[] |
getLocalEngineID()
Gets the local engine ID if the MPv3 is available, otherwise a runtime exception is thrown. |
MessageDispatcher |
getMessageDispatcher()
Returns the message dispatcher associated with this SNMP session. |
MessageProcessingModel |
getMessageProcessingModel(int messageProcessingModel)
Gets the message processing model for the supplied ID. |
ResponseEvent |
getNext(PDU pdu,
Target target)
Sends a GETNEXT request to a target. |
void |
getNext(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a GETNEXT request PDU to the given
target. |
int |
getNextRequestID()
Gets the next unique request ID. |
Snmp.ReportHandler |
getReportHandler()
Returns the report handler which is used internally to process reports received from command responders. |
TimeoutModel |
getTimeoutModel()
Gets the timeout model associated with this SNMP session. |
USM |
getUSM()
Gets the User Based Security Model (USM). |
ResponseEvent |
inform(PDU pdu,
Target target)
Sends an INFORM request to a target. |
void |
inform(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends an INFORM request PDU to the given
target. |
protected void |
initMessageDispatcher()
|
void |
listen()
Puts all associated transport mappings into listen mode. |
void |
notify(PDU pdu,
Target target)
Sends a SNMPv2c or SNMPv3 notification to a target. |
void |
processPdu(CommandResponderEvent event)
Process an incoming request or notification PDU. |
void |
removeCommandResponder(CommandResponder listener)
Removes a CommandResponder from this SNMP session. |
boolean |
removeNotificationListener(Address listenAddress)
Removes (deletes) the notification listener for the specified transport endpoint. |
void |
removeTransportMapping(TransportMapping transportMapping)
Removes the specified transport mapping from this SNMP session. |
ResponseEvent |
send(PDU pdu,
Target target)
Sends a PDU to the given target and returns the received
response PDU. |
void |
send(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a PDU to the given target. |
ResponseEvent |
send(PDU pdu,
Target target,
TransportMapping transport)
Sends a PDU to the given target and if the PDU
is a confirmed request, then the received response is returned
synchronously. |
void |
send(PDU pdu,
Target target,
TransportMapping transport,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a PDU to the given target. |
protected PduHandle |
sendMessage(PDU pdu,
Target target,
TransportMapping transport,
PduHandleCallback pduHandleCallback)
Actually sends a PDU to a target and returns a handle for the sent PDU. |
PDU |
sendPDU(PDU pdu,
Target target)
Deprecated. This method has been deprecated because it does not return the transport address of the entity (target) that sent the response. Please use send(PDU pdu, Target target) instead. It returns
a ResponseEvent object holding the response PDU and transport
address of a successfully received response. This method will be supported
until v2.0. |
void |
sendPDU(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Deprecated. Please use send(PDU pdu, Target target, Object
userHandle, ResponseListener listener) instead. It has exactly
the same function but follows the new naming scheme. This method
will be supported until v2.0. |
ResponseEvent |
set(PDU pdu,
Target target)
Sends a SET request to a target. |
void |
set(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
Asynchronously sends a SET request PDU to the given target. |
void |
setLocalEngine(byte[] engineID,
int engineBoots,
int engineTime)
Sets the local engine ID for the SNMP entity represented by this Snmp instance. |
void |
setReportHandler(Snmp.ReportHandler reportHandler)
Sets the report handler and overrides the default report handler. |
void |
setTimeoutModel(TimeoutModel timeoutModel)
Sets the timeout model for this SNMP session. |
void |
trap(PDUv1 pdu,
Target target)
Sends a SNMPv1 trap to a target. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Snmp()
Snmp instance that uses a
MessageDispatcherImpl with no message processing
models and no security protols (by default). You will have to add
those by calling the appropriate methods on
getMessageDispatcher().
At least one transport mapping has to be added before listen()
is called in order to be able to send and receive SNMP messages.
To initialize a Snmp instance created with this constructor
follow this sample code:
Transport transport = ...;
Snmp snmp = new Snmp();
SecurityProtocols.getInstance().addDefaultProtocols();
MessageDispatcher disp = snmp.getMessageDispatcher();
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
snmp.addTransportMapping(transport);
OctetString localEngineID = new OctetString(
MPv3.createLocalEngineID());
// For command generators, you may use the following code to avoid
// engine ID clashes:
// MPv3.createLocalEngineID(
// new OctetString("MyUniqueID"+System.currentTimeMillis())));
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
disp.addMessageProcessingModel(new MPv3(usm));
snmp.listen();
public Snmp(TransportMapping transportMapping)
Snmp instance that uses a
MessageDispatcherImpl with all supported message processing
models and the default security protols for dispatching.
To initialize a Snmp instance created with this constructor
follow this sample code:
Transport transport = ...; Snmp snmp = new Snmp(transport); OctetString localEngineID = new OctetString(snmp.getMPv3().getLocalEngineID()); USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0); SecurityModels.getInstance().addSecurityModel(usm); snmp.listen();
transportMapping - TransportMapping
the initial TransportMapping. You can add more or remove
the same later.
public Snmp(MessageDispatcher messageDispatcher,
TransportMapping transportMapping)
Snmp instance by supplying a
MessageDispatcher and a TransportMapping.
As of version 1.1, the supplied message dispatcher is not altered in terms of adding any message processing models to it. This has to be done now outside the Snmp class.
To initialize a Snmp instance created with this constructor
follow this sample code:
Transport transport = ...;
SecurityProtocols.getInstance().addDefaultProtocols();
MessageDispatcher disp = new MessageDispatcherImpl();
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
Snmp snmp = new Snmp(disp, transport);
OctetString localEngineID = new OctetString(
MPv3.createLocalEngineID());
// For command generators, you may use the following code to avoid
// engine ID clashes:
// MPv3.createLocalEngineID(
// new OctetString("MyUniqueID"+System.currentTimeMillis())));
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
disp.addMessageProcessingModel(new MPv3(usm));
snmp.listen();
messageDispatcher - a MessageDispatcher instance that will be used to
dispatch incoming and outgoing messages.transportMapping - the initial TransportMapping,
which may be null. You can add or remove transport
mappings later using addTransportMapping(org.snmp4j.TransportMapping) and
removeTransportMapping(org.snmp4j.TransportMapping) respectively.public Snmp(MessageDispatcher messageDispatcher)
Snmp instance by supplying a
MessageDispatcher.
The supplied message dispatcher is not altered in terms of adding any message processing models to it. This has to be done now outside the Snmp class.
Do not forget to add at least one transport mapping before calling the listen method!
To initialize a Snmp instance created with this constructor
follow this sample code:
Transport transport = ...;
SecurityProtocols.getInstance().addDefaultProtocols();
MessageDispatcher disp = new MessageDispatcherImpl();
disp.addMessageProcessingModel(new MPv1());
disp.addMessageProcessingModel(new MPv2c());
Snmp snmp = new Snmp(disp);
snmp.addTransportMapping(transport);
OctetString localEngineID = new OctetString(
MPv3.createLocalEngineID());
// For command generators, you may use the following code to avoid
// engine ID clashes:
// MPv3.createLocalEngineID(
// new OctetString("MyUniqueID"+System.currentTimeMillis())));
USM usm = new USM(SecurityProtocols.getInstance(), localEngineID, 0);
disp.addMessageProcessingModel(new MPv3(usm));
snmp.listen();
messageDispatcher - a MessageDispatcher instance that will be used to
dispatch incoming and outgoing messages.| Method Detail |
|---|
protected final void initMessageDispatcher()
public MessageDispatcher getMessageDispatcher()
MessageDispatcher instance.public void addTransportMapping(TransportMapping transportMapping)
TransportMapping to this SNMP session.
transportMapping - a TransportMapping instance.public void removeTransportMapping(TransportMapping transportMapping)
transportMapping - a previously added TransportMapping.
public boolean addNotificationListener(Address listenAddress,
CommandResponder listener)
CommandResponder with the internal
NotificationDispatcher.
listenAddress - the Address denoting the transport end-point
(interface and port) to listen for incoming notifications.listener - the CommandResponder instance that should handle
the received notifications.
true if registration was successful and false
if, for example, the transport mapping for the listen address could not
be created.public boolean removeNotificationListener(Address listenAddress)
listenAddress - the listen Address to be removed.
true if the notification listener has been removed
successfully.
public void listen()
throws java.io.IOException
java.io.IOException - if a transport mapping throws an IOException when its
TransportMapping.listen() method has been called.public int getNextRequestID()
MessageDispatcher.getNextRequestID()
public void close()
throws java.io.IOException
If there are any pending requests, the ResponseListener associated
with the pending requests, will be called with a null
response and a InterruptedException in the error member of the
ResponseEvent returned.
After a Session has been closed it must not be used anymore.
close in interface Sessionjava.io.IOException - if a transport mapping cannot be closed successfully.
public ResponseEvent get(PDU pdu,
Target target)
throws java.io.IOException
PDU.GET and then sends a synchronous request to the supplied
target.
pdu - a PDU instance. For SNMPv3 messages, the supplied PDU
instance has to be a ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null.
java.io.IOException - if the PDU cannot be sent to the target.
public void get(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
PDU to the given target.
The response is then returned by calling the supplied
ResponseListener instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU cannot be sent to the target.
public ResponseEvent getNext(PDU pdu,
Target target)
throws java.io.IOException
PDU.GETNEXT and then sends a synchronous request to the supplied
target. This method is a convenience wrapper for the
send(PDU pdu, Target target) method.
pdu - a PDU instance. For SNMPv3 messages, the supplied PDU
instance has to be a ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null.
java.io.IOException - if the PDU cannot be sent to the target.
public void getNext(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
PDU to the given
target. The response is then returned by calling the supplied
ResponseListener instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU cannot be sent to the target.
public ResponseEvent getBulk(PDU pdu,
Target target)
throws java.io.IOException
PDU.GETBULK and then sends a synchronous request to the supplied
target. This method is a convenience wrapper for the
send(PDU pdu, Target target) method.
pdu - a PDU instance. For SNMPv3 messages, the supplied PDU
instance has to be a ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null.
java.io.IOException - if the PDU cannot be sent to the target.
public void getBulk(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
PDU to the given
target. The response is then returned by calling the supplied
ResponseListener instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU cannot be sent to the target.
public ResponseEvent inform(PDU pdu,
Target target)
throws java.io.IOException
PDU.INFORM and then sends a synchronous request to the supplied
target. This method is a convenience wrapper for the
send(PDU pdu, Target target) method.
pdu - a PDU instance. For SNMPv3 messages, the supplied PDU
instance has to be a ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null.
java.io.IOException - if the inform request could not be send to the specified target.
public void inform(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
PDU to the given
target. The response is then returned by calling the supplied
ResponseListener instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU cannot be sent to the target.
public void trap(PDUv1 pdu,
Target target)
throws java.io.IOException
PDU.V1TRAP and then sends it to the supplied target. This method
is a convenience wrapper for the send(PDU pdu, Target target)
method.
pdu - a PDUv1 instance.target - the Target instance representing the target SNMP engine where to send
the pdu. The selected SNMP protocol version for the
target must be SnmpConstants.version1.
java.io.IOException - if the trap cannot be sent.
public void notify(PDU pdu,
Target target)
throws java.io.IOException
PDU.NOTIFICATION and then sends it to the supplied
target. This method is a convenience wrapper for the
send(PDU pdu, Target target) method.
pdu - a PDUv1 instance.target - the Target instance representing the target SNMP engine where to send
the pdu. The selected SNMP protocol version for the
target must be SnmpConstants.version2c or
SnmpConstants.version2c.
java.io.IOException - if the notification cannot be sent.
public ResponseEvent set(PDU pdu,
Target target)
throws java.io.IOException
PDU.SET and then sends a synchronous request to the supplied
target.
pdu - a PDU instance. For SNMPv3 messages, the supplied PDU
instance has to be a ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null.
java.io.IOException - if the PDU cannot be sent to the target.
public void set(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
PDU to the given target.
The response is then returned by calling the supplied
ResponseListener instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU cannot be sent to the target.
public ResponseEvent send(PDU pdu,
Target target)
throws java.io.IOException
SessionPDU to the given target and returns the received
response PDU.
send in interface Sessionpdu - the PDU to send.target - the Target instance that specifies how and where to send
the PDU.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null. If the sent pdu
is an unconfirmed PDU (notification, response, or report), then
null will be returned.
java.io.IOException - if the message could not be send.
public ResponseEvent send(PDU pdu,
Target target,
TransportMapping transport)
throws java.io.IOException
PDU to the given target and if the PDU
is a confirmed request, then the received response is returned
synchronously.
send in interface Sessionpdu - a PDU instance. When sending a SNMPv1 trap PDU, the
supplied PDU instance must be a PDUv1. For all types of
SNMPv3 messages, the supplied PDU instance has to be a
ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.transport - specifies the TransportMapping to be used when sending
the PDU. If transport is null, the associated
message dispatcher will try to determine the transport mapping by the
target's address.
ResponseEvent
instance. To obtain the received response PDU call
ResponseEvent.getResponse(). If the request timed out,
that method will return null. If the sent pdu
is an unconfirmed PDU (notification, response, or report), then
null will be returned.
java.io.IOException - if the message could not be sent.PDU,
ScopedPDU,
PDUv1
public void send(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
SessionPDU to the given target. The response
is then returned by calling the supplied ResponseListener
instance.
send in interface Sessionpdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the message could not be send.
public void send(PDU pdu,
Target target,
TransportMapping transport,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
SessionPDU to the given target. The response
is then returned by calling the supplied ResponseListener
instance.
send in interface Sessionpdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.transport - specifies the TransportMapping to be used when sending
the PDU. If transport is null, the associated
message dispatcher will try to determine the transport mapping by the
target's address.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the message could not be send.
public PDU sendPDU(PDU pdu,
Target target)
throws java.io.IOException
send(PDU pdu, Target target) instead. It returns
a ResponseEvent object holding the response PDU and transport
address of a successfully received response. This method will be supported
until v2.0.
PDU to the given target and returns the received
response PDU.
pdu - a PDU instance. When sending a SNMPv1 trap PDU, the
supplied PDU instance must be a PDUv1. For all types of
SNMPv3 messages, the supplied PDU instance has to be a
ScopedPDU instance.target - the Target instance representing the target SNMP engine where to send
the pdu.
PDU or null
if the request timed out and if the PDU type of pdu
is an unconfirmed PDU (i.e., trap or notification).
java.io.IOException - if the message could not be sent.PDU,
ScopedPDU,
PDUv1
public void sendPDU(PDU pdu,
Target target,
java.lang.Object userHandle,
ResponseListener listener)
throws java.io.IOException
send(PDU pdu, Target target, Object
userHandle, ResponseListener listener) instead. It has exactly
the same function but follows the new naming scheme. This method
will be supported until v2.0.
PDU to the given target. The response
is then returned by calling the supplied ResponseListener
instance.
pdu - the PDU instance to send.target - the Target instance representing the target SNMP engine where to send
the pdu.userHandle - an user defined handle that is returned when the request is returned
via the listener object.listener - a ResponseListener instance that is called when
pdu is a confirmed PDU and the request is either answered
or timed out.
java.io.IOException - if the PDU could not be sent to the specified target.
protected PduHandle sendMessage(PDU pdu,
Target target,
TransportMapping transport,
PduHandleCallback pduHandleCallback)
throws java.io.IOException
pdu - the PDU instance to be sent.target - a Target instance denoting the target SNMP entity.transport - the (optional) transport mapping to be used to send the request.
If transport is null a suitable transport
mapping is determined from the target address.pduHandleCallback - callback for newly created PDU handles before the request is sent out.
java.io.IOException - if the transport fails to send the PDU or the if the message cannot
be BER encoded.
public void cancel(PDU request,
ResponseListener listener)
SessionResponseEvent indicates an error.
cancel in interface Sessionrequest - a request PDU as sent via Session.send(PDU pdu, Target target,
Object userHandle, ResponseListener listener) or any .listener - a ResponseListener instance.
public void setLocalEngine(byte[] engineID,
int engineBoots,
int engineTime)
Snmp instance. This is a convenience method that sets
the local engine ID in the associated MPv3 and
USM.
engineID - a byte array containing the local engine ID. The length and content
has to comply with the constraints defined in the SNMP-FRAMEWORK-MIB.engineBoots - the number of boots of this SNMP engine (zero based).engineTime - the number of seconds since the value of engineBoots last changed.MPv3,
USMpublic byte[] getLocalEngineID()
public byte[] discoverAuthoritativeEngineID(Address address,
long timeout)
For this method to operate succesfully, the discover engine IDs
flag in USM must be true (which is the default).
address - an Address instance representing the transport address of the SNMPv3
entity for which its authoritative engine ID should be discovered.timeout - the maximum time in milliseconds to wait for a response.
null
if it could not be discovered.USM.setEngineDiscoveryEnabled(boolean enableEngineDiscovery)public USM getUSM()
MPv3.getSecurityModel(int) method of the associated MPv3
instance to get the USM.
USM instance associated with the MPv3 bound to this
Snmp instance, or null otherwise.public MessageProcessingModel getMessageProcessingModel(int messageProcessingModel)
messageProcessingModel - a mesage processing model ID as defined in MessageProcessingModel.
MessageProcessingModel if
messageProcessingModel has been registered with the
message dispatcher associated with this SNMP session.public void processPdu(CommandResponderEvent event)
processPdu in interface CommandResponderevent - a CommandResponderEvent with the decoded incoming PDU as
dispatched to this method call by the associated message dispatcher.public void removeCommandResponder(CommandResponder listener)
CommandResponder from this SNMP session.
listener - a previously added CommandResponder instance.public void addCommandResponder(CommandResponder listener)
CommandResponder to this SNMP session.
The command responder will then be informed about incoming SNMP PDUs of
any kind that are not related to any outstanding requests of this SNMP
session.
listener - the CommandResponder instance to be added.protected void fireProcessPdu(CommandResponderEvent event)
CommandResponderEvent event to inform listeners about
a received PDU. If a listener has marked the event as processed further
listeners will not be informed about the event.
event - a CommandResponderEvent.public TimeoutModel getTimeoutModel()
null).setTimeoutModel(TimeoutModel timeoutModel)public Snmp.ReportHandler getReportHandler()
ReportHandler instance.public void setTimeoutModel(TimeoutModel timeoutModel)
timeout
parameter of the target has elapsed without a response beeing received for
the request. By specifying a different timeout model this behaviour can
be changed.
timeoutModel - a TimeoutModel instance (must not be null).public void setReportHandler(Snmp.ReportHandler reportHandler)
reportHandler - a ReportHandler instance which must not be
null.
|
Copyright 2003-2009 Frank Fock and Jochen Katz (SNMP4J.org) | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||