-
- All Superinterfaces:
java.lang.AutoCloseable,java.io.Closeable
- All Known Implementing Classes:
Snmp
public interface Session extends java.io.CloseableSessiondefines a common interface for all classes that implement SNMP protocol operations based on SNMP4J.- Version:
- 3.1.0
- Author:
- Frank Fock
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidcancel(PDU request, ResponseListener listener)Cancels an asynchronous request.voidclose()Closes the session and frees any allocated resources, i.e.byte[]getLocalEngineID()Gets the local engine ID if the MPv3 is available, otherwise a runtime exception is thrown.<A extends Address>
ResponseEvent<A>send(PDU pdu, Target<A> target)Sends aPDUto the given target and returns the received responsePDU.<A extends Address>
voidsend(PDU pdu, Target<A> target, java.lang.Object userHandle, ResponseListener listener)Asynchronously sends aPDUto the given target.<A extends Address>
ResponseEvent<A>send(PDU pdu, Target<A> target, TransportMapping<? super A> transport)Sends aPDUto the given target and returns the received responsePDUencapsulated in aResponseEventobject that also includes: the transport address of the response sending peer, theTargetinformation of the target, the requestPDU, the responsePDU(if any).<A extends Address>
voidsend(PDU pdu, Target<A> target, TransportMapping<? super A> transport, java.lang.Object userHandle, ResponseListener listener)Asynchronously sends aPDUto the given target.voidsetLocalEngine(byte[] engineID, int engineBoots, int engineTime)Sets the local engine ID for the SNMP entity represented by thisSnmpinstance.
-
-
-
Method Detail
-
close
void close() throws java.io.IOExceptionCloses the session and frees any allocated resources, i.e. sockets. After aSessionhas been closed it must be used.- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException- if the session could not free all resources.
-
send
<A extends Address> ResponseEvent<A> send(PDU pdu, Target<A> target) throws java.io.IOException
Sends aPDUto the given target and returns the received responsePDU.- Type Parameters:
A- theAddresstype of target and response (i.e., must be the same)- Parameters:
pdu- thePDUto send.target- theTargetinstance that specifies how and where to send the PDU.- Returns:
- the received response encapsulated in a
ResponseEventinstance. To obtain the received responsePDUcallResponseEvent.getResponse(). If the request timed out, that method will returnnull. If the sentpduis an unconfirmed PDU (notification, response, or report), thennullwill be returned. - Throws:
java.io.IOException- if the message could not be send.
-
send
<A extends Address> void send(PDU pdu, Target<A> target, java.lang.Object userHandle, ResponseListener listener) throws java.io.IOException
Asynchronously sends aPDUto the given target. The response is then returned by calling the suppliedResponseListenerinstance.- Type Parameters:
A- theAddresstype of target and response (i.e., must be the same)- Parameters:
pdu- the PDU instance to send.target- the Target instance representing the target SNMP engine where to send thepdu.userHandle- an user defined handle that is returned when the request is returned via thelistenerobject.listener- aResponseListenerinstance that is called whenpduis a confirmed PDU and the request is either answered or timed out.- Throws:
java.io.IOException- if the message could not be send.
-
send
<A extends Address> ResponseEvent<A> send(PDU pdu, Target<A> target, TransportMapping<? super A> transport) throws java.io.IOException
Sends aPDUto the given target and returns the received responsePDUencapsulated in aResponseEventobject that also includes:- the transport address of the response sending peer,
- the
Targetinformation of the target, - the request
PDU, - the response
PDU(if any).
- Type Parameters:
A- the targetAddresstype.- Parameters:
pdu- the PDU instance to send.target- the Target instance representing the target SNMP engine where to send thepdu.transport- specifies theTransportMappingto be used when sending the PDU. Iftransportisnull, the associated message dispatcher will try to determine the transport mapping by thetarget's address.- Returns:
- the received response encapsulated in a
ResponseEventinstance. To obtain the received responsePDUcallResponseEvent.getResponse(). If the request timed out, that method will returnnull. If the sentpduis an unconfirmed PDU (notification, response, or report), thennullwill be returned. - Throws:
java.io.IOException- if the message could not be send.
-
send
<A extends Address> void send(PDU pdu, Target<A> target, TransportMapping<? super A> transport, java.lang.Object userHandle, ResponseListener listener) throws java.io.IOException
Asynchronously sends aPDUto the given target. The response is then returned by calling the suppliedResponseListenerinstance.- Type Parameters:
A- the targetAddresstype.- Parameters:
pdu- the PDU instance to send.target- the Target instance representing the target SNMP engine where to send thepdu.transport- specifies theTransportMappingto be used when sending the PDU. Iftransportisnull, the associated message dispatcher will try to determine the transport mapping by thetarget's address.userHandle- an user defined handle that is returned when the request is returned via thelistenerobject.listener- aResponseListenerinstance that is called whenpduis a confirmed PDU and the request is either answered or timed out.- Throws:
java.io.IOException- if the message could not be send.
-
cancel
void cancel(PDU request, ResponseListener listener)
Cancels an asynchronous request. Any asynchronous request must be canceled when the supplied response listener is being called, even if theResponseEventindicates an error.- Parameters:
request- a request PDU as sent viasend(PDU pdu, Target target, Object userHandle, ResponseListener listener)or any .listener- a ResponseListener instance.
-
setLocalEngine
void setLocalEngine(byte[] engineID, int engineBoots, int engineTime)Sets the local engine ID for the SNMP entity represented by thisSnmpinstance. This is a convenience method that sets the local engine ID in the associatedMPv3andUSM.- Parameters:
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.- Since:
- 3.0
-
getLocalEngineID
byte[] getLocalEngineID()
Gets the local engine ID if the MPv3 is available, otherwise a runtime exception is thrown.- Returns:
- byte[] the local engine ID.
- Since:
- 3.0
-
-