public class SnmpSession extends Object
The SnmpSession is the main connection between the SNMP manager and the SNMP Agent. All the request flow through this class. To use the SnmpSession class a SnmpHandler class must be defined to process any errors or responses through the library.
Once the session is created the creator must call close() to ensure an orderly release of threads and resources.
SnmpHandler
,
SnmpPacketHandler
,
SnmpPortal
Modifier and Type | Field and Description |
---|---|
static int |
ERROR_ENCODING
This is the command passed to the SnmpHandler if an encoding exception is
generated when attempting to send an SnmpPduRequest message
|
static int |
ERROR_IOEXCEPTION
This is the command passed to the SnmpHandler if an IOException occurs
while attempting to transmit the request
|
static int |
ERROR_TIMEOUT
This is the command passed to the SnmpHandler if a timeout occurs.
|
Constructor and Description |
---|
SnmpSession(InetAddress peer)
The default SnmpSession constructor.
|
SnmpSession(InetAddress peer,
SnmpParameters params)
Constructs the SnmpSession with the specific parameters.
|
SnmpSession(SnmpPeer peer)
Constructs the SnmpSession with the specific SnmpPeer.
|
Modifier and Type | Method and Description |
---|---|
void |
cancel(int requestId)
Cancels the current outstanding reqeust as defined by the SnmpPduPacket's
requestId method.
|
void |
close()
Used to close the session.
|
SnmpSyntax |
get(SnmpObjectId oid) |
SnmpSyntax[] |
get(SnmpObjectId[] oids) |
AsnEncoder |
getAsnEncoder()
Gets the AsnEncoder for the session.
|
SnmpSyntax[] |
getBulk(int nonRepeaters,
int maxReptitions,
SnmpObjectId id) |
SnmpSyntax[] |
getBulk(int nonRepeaters,
int maxRepititions,
SnmpObjectId[] oids) |
SnmpHandler |
getDefaultHandler()
Gets the default SnmpHandler for the session.
|
SnmpSyntax |
getNext(SnmpObjectId oid) |
SnmpSyntax[] |
getNext(SnmpObjectId[] oids) |
int |
getOutstandingCount()
Returns the number of outstanding request for the agent.
|
SnmpPeer |
getPeer()
Gets the current peer object.
|
SnmpPduPacket |
getResponse(SnmpPduPacket request) |
boolean |
isClosed()
Returns true if the
close method has been called. |
static void |
registerSyntaxObject(SnmpSyntax object)
Allows library users to register new ASN.1 types with the SNMP library.
|
int |
send(SnmpPduPacket pdu)
Sends the SNMP PDU to the remote agent and uses the default SnmpHandler
to process the request.
|
int |
send(SnmpPduPacket pdu,
SnmpHandler handler)
Send the SNMP PDU to the remote agent and invokes the specified handler
when the packet is recieve.
|
int |
send(SnmpPduTrap pdu)
Sends the SNMP PDU Trap to the remote agent.
|
int |
send(SnmpPduTrap pdu,
SnmpHandler handler)
Send the SNMP PDU Trap to the remote agent.
|
SnmpSyntax[] |
set(SnmpObjectId[] oids,
SnmpSyntax[] values) |
SnmpSyntax |
set(SnmpObjectId oid,
SnmpSyntax value) |
void |
setAsnEncoder(AsnEncoder encoder)
Sets the default encoder.
|
void |
setDefaultHandler(SnmpHandler hdl)
Sets the default SnmpHandler.
|
void |
setPeer(SnmpPeer peer)
Sets the passed SnmpPeer object to the one used for all new SNMP
communications.
|
public static final int ERROR_TIMEOUT
SnmpHandler
,
Constant Field Valuespublic static final int ERROR_IOEXCEPTION
SnmpHandler
,
Constant Field Valuespublic static final int ERROR_ENCODING
SnmpHandler
,
Constant Field Valuespublic SnmpSession(InetAddress peer) throws SocketException
peer
- The peer agentSocketException
- If thrown it is from the creation of a DatagramSocket.SnmpPeer
public SnmpSession(SnmpPeer peer) throws SocketException
peer
- The SnmpPeer used to configure this sessionSocketException
- If thrown it is from the creation of a DatagramSocket.SnmpPeer
public SnmpSession(InetAddress peer, SnmpParameters params) throws SocketException
peer
- The peer address for agentparams
- The SnmpParameters to configure with this sessionSocketException
- If thrown it is from the creation of a DatagramSocket.SnmpPeer
,
SnmpParameters
public SnmpHandler getDefaultHandler()
public void setDefaultHandler(SnmpHandler hdl)
hdl
- The new default handlerpublic SnmpPeer getPeer()
public void setPeer(SnmpPeer peer)
peer
- The SnmpPeer object for the sesisonpublic int getOutstandingCount()
IllegalStateException
- Throw if the session has been closed.public void cancel(int requestId)
requestId
- The request to cancelIllegalStateException
- Throw if the session has been closed.SnmpPduPacket
public int send(SnmpPduPacket pdu, SnmpHandler handler)
pdu
- The pdu to encode and sendhandler
- The handler object for this requestSnmpHandlerNotDefinedException
- Thrown if the handler is nullIllegalStateException
- Thrown if the session has been closed.public int send(SnmpPduPacket pdu)
pdu
- The pdu to encode and sendSnmpHandlerNotDefinedException
- Thrown if the handler is nullIllegalStateException
- Thrown if the session has been closed.public int send(SnmpPduTrap pdu, SnmpHandler handler)
pdu
- The pdu to encode and sendhandler
- The handler object for this requestSnmpHandlerNotDefinedException
- Thrown if the handler is nullIllegalStateException
- Thrown if the session has been closed.public int send(SnmpPduTrap pdu)
pdu
- The pdu to encode and sendSnmpHandlerNotDefinedException
- Thrown if the handler is nullIllegalStateException
- Thrown if the session has been closed.public boolean isClosed()
close
method has been called. The
session cannot be used to send request after close
has
been executed.public void close()
IllegalStateException
- Thrown if the session has already been closed by another
thread.public void setAsnEncoder(AsnEncoder encoder)
encoder
- The new encoderpublic AsnEncoder getAsnEncoder()
public static void registerSyntaxObject(SnmpSyntax object)
object
- The new SnmpSyntax object to registerpublic SnmpSyntax getNext(SnmpObjectId oid)
public SnmpSyntax[] getNext(SnmpObjectId[] oids)
public SnmpSyntax get(SnmpObjectId oid)
public SnmpSyntax set(SnmpObjectId oid, SnmpSyntax value)
public SnmpSyntax[] set(SnmpObjectId[] oids, SnmpSyntax[] values)
public SnmpSyntax[] get(SnmpObjectId[] oids)
public SnmpSyntax[] getBulk(int nonRepeaters, int maxReptitions, SnmpObjectId id)
public SnmpSyntax[] getBulk(int nonRepeaters, int maxRepititions, SnmpObjectId[] oids)
public SnmpPduPacket getResponse(SnmpPduPacket request)
Copyright © 2021. All rights reserved.