Package org.snmp4j.model.snmp.api
Class LocalSnmpService
java.lang.Object
org.snmp4j.model.snmp.api.LocalSnmpService
- All Implemented Interfaces:
SnmpService
,TransactionManager
The LocalSnmpService is the default
SnmpService
implementation that
sends directly (from the local device) SNMP request to the specified targets.- Version:
- 1.0
- Author:
- Frank Fock
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionCreates a localSnmpService
withUSM
andTSM
security models, theMPv3
message processing model, and theDefaultUdpTransportMapping
transport mapping.LocalSnmpService
(org.snmp4j.MessageDispatcher messageDispatcher, List<org.snmp4j.TransportMapping> transportMappings, List<org.snmp4j.mp.MessageProcessingModel> messageProcessingModels, org.snmp4j.security.SecurityModels securityModels, org.snmp4j.security.SecurityProtocols securityProtocols) Creates a localSnmpService
with the given message dispatcher, transport mappings, message processing and security models, and security protocols. -
Method Summary
Modifier and TypeMethodDescriptionList<? extends SnmpCommitResult>
commit
(SnmpTransaction transaction, SnmpCommitListener commitListener) Commits the transaction to the agent.List<? extends org.snmp4j.smi.VariableBinding>
Gets the SNMP values for the specified OIDs.List<? extends org.snmp4j.smi.VariableBinding>
Gets the next following SNMP values for the specified OIDs.org.snmp4j.util.PDUFactory
Gets thePDUFactory
of this SNMP service.org.snmp4j.Snmp
getSnmp()
Returns theSnmp
instance used by this localSnmpService
.getSnmpTransaction
(SnmpTransactionStrategy transactionStrategy) List<? extends org.snmp4j.smi.VariableBinding>
getSubTree
(org.snmp4j.Target target, org.snmp4j.smi.OID oid) Gets the SNMP values for the specified sub-tree root OID.getTable
(org.snmp4j.Target target, List<org.snmp4j.smi.OID> columnOIDs, org.snmp4j.smi.OID minIndexOID, org.snmp4j.smi.OID maxIndexOID) Gets the rows of a SNMP table synchronously.void
getTable
(org.snmp4j.Target target, List<org.snmp4j.smi.OID> columnOIDs, org.snmp4j.smi.OID minIndex, org.snmp4j.smi.OID maxIndex, SnmpRowListener callback, Object userObject) Gets the rows of a SNMP table asynchronously.void
Initializes the transports associated with this service.boolean
isAtomic
(SnmpTransaction transaction) Checks if this transaction can be committed with atomicity.void
rollback
(SnmpTransaction transaction) void
setPduFactory
(org.snmp4j.util.PDUFactory pduFactory) Sets thePDUFactory
of this SNMP service.void
update
(SnmpTransaction snmpTransaction, org.snmp4j.Target target, SnmpValuesChangeSet variableBindings, SnmpCommitListener commitListener) Updates (SETs) a set of changes with an atomic SET operation asynchronously.
-
Constructor Details
-
LocalSnmpService
public LocalSnmpService()Creates a localSnmpService
withUSM
andTSM
security models, theMPv3
message processing model, and theDefaultUdpTransportMapping
transport mapping. -
LocalSnmpService
public LocalSnmpService(org.snmp4j.MessageDispatcher messageDispatcher, List<org.snmp4j.TransportMapping> transportMappings, List<org.snmp4j.mp.MessageProcessingModel> messageProcessingModels, org.snmp4j.security.SecurityModels securityModels, org.snmp4j.security.SecurityProtocols securityProtocols) Creates a localSnmpService
with the given message dispatcher, transport mappings, message processing and security models, and security protocols.- Parameters:
messageDispatcher
- the message dispatcher to be used by this local SNMP service. Cannot benull
.transportMappings
- the transport mappings to be used. Ifnull
is given, a newDefaultUdpTransportMapping
will be created and used.messageProcessingModels
- the message processing models to be used by the service. Ifnull
is given, a newMPv3
is created and used (without any SNMPv1 or v2c models).securityModels
- the security models to be used with the provided message processing models. If there is no message processing model, that requires a security model (i.e.,MPv1
andMPv2c
only) then this value can benull
.securityProtocols
- the security protocols to be used with the provided message processing models. If there is no message processing model, that requires a security protocol (i.e.,MPv1
andMPv2c
only) then this value can benull
.
-
-
Method Details
-
getSnmp
public org.snmp4j.Snmp getSnmp()Returns theSnmp
instance used by this localSnmpService
.- Returns:
- a
Snmp
instance.
-
initTransports
Description copied from interface:SnmpService
Initializes the transports associated with this service. This will open the necessary network ports.- Specified by:
initTransports
in interfaceSnmpService
- Throws:
IOException
- if an IO error occurred during initialization.
-
getPduFactory
public org.snmp4j.util.PDUFactory getPduFactory()Gets thePDUFactory
of this SNMP service.- Returns:
- a
PDUFactory
instance.
-
setPduFactory
public void setPduFactory(org.snmp4j.util.PDUFactory pduFactory) Sets thePDUFactory
of this SNMP service. The factory is used to create any SNMPPDU
created on behalf of this service. By default, this is theDefaultPDUFactory
with the PDU typePDU.GET
.- Parameters:
pduFactory
- thePDUFactory
to be used by this local SNMP service.
-
get
public List<? extends org.snmp4j.smi.VariableBinding> get(org.snmp4j.Target target, List<org.snmp4j.smi.OID> oidList) throws SnmpException Description copied from interface:SnmpService
Gets the SNMP values for the specified OIDs.- Specified by:
get
in interfaceSnmpService
- Parameters:
target
- the SNMP target to send the SNMP PDUs to.oidList
- the instance object identifiers to GET values for.- Returns:
- a list of variable bindings.
- Throws:
SnmpException
- if an SNMP error or timeout occurred.
-
getNext
public List<? extends org.snmp4j.smi.VariableBinding> getNext(org.snmp4j.Target target, List<org.snmp4j.smi.OID> oidList) throws SnmpException Description copied from interface:SnmpService
Gets the next following SNMP values for the specified OIDs.- Specified by:
getNext
in interfaceSnmpService
- Parameters:
target
- the SNMP target to send the SNMP PDUs to.oidList
- the instance object identifiers to GET-NEXT values for.- Returns:
- a list of variable bindings.
- Throws:
SnmpException
- if an SNMP error or timeout occurred.
-
getSubTree
public List<? extends org.snmp4j.smi.VariableBinding> getSubTree(org.snmp4j.Target target, org.snmp4j.smi.OID oid) throws SnmpException Description copied from interface:SnmpService
Gets the SNMP values for the specified sub-tree root OID.- Specified by:
getSubTree
in interfaceSnmpService
- Parameters:
target
- the SNMP target to send the SNMP PDUs to.oid
- the root OID of the sub-tree to get values for (using GETBULK or GETNEXT).- Returns:
- a list of variable bindings.
- Throws:
SnmpException
- if an SNMP error or timeout occurred.
-
getTable
public List<? extends SnmpRow> getTable(org.snmp4j.Target target, List<org.snmp4j.smi.OID> columnOIDs, org.snmp4j.smi.OID minIndexOID, org.snmp4j.smi.OID maxIndexOID) throws SnmpException Description copied from interface:SnmpService
Gets the rows of a SNMP table synchronously.- Specified by:
getTable
in interfaceSnmpService
- Parameters:
target
- the SNMP target to send the SNMP PDUs to.columnOIDs
- the OIDs of the columns to retrieve (columns might be combined from several tables although the indexes of the included tables should then contain a common prefix).minIndexOID
- the minimum index to return (ornull
for no limit).maxIndexOID
- the maximum index to return (ornull
for no limit).- Returns:
- a list of
SnmpRow
instances. - Throws:
SnmpException
- if an SNMP error or timeout occurred.
-
getTable
public void getTable(org.snmp4j.Target target, List<org.snmp4j.smi.OID> columnOIDs, org.snmp4j.smi.OID minIndex, org.snmp4j.smi.OID maxIndex, SnmpRowListener callback, Object userObject) throws SnmpException Description copied from interface:SnmpService
Gets the rows of a SNMP table asynchronously.- Specified by:
getTable
in interfaceSnmpService
- Parameters:
target
- the SNMP target to send the SNMP PDUs to.columnOIDs
- the OIDs of the columns to retrieve (columns might be combined from several tables although the indexes of the included tables should then contain a common prefix).minIndex
- the minimum index to return (ornull
for no limit).maxIndex
- the maximum index to return (ornull
for no limit).callback
- the callback that receives the retrieved rows.userObject
- an optinal user object to be associated with this retrieval.- Throws:
SnmpException
- if an SNMP error or timeout occurred.
-
update
public void update(SnmpTransaction snmpTransaction, org.snmp4j.Target target, SnmpValuesChangeSet variableBindings, SnmpCommitListener commitListener) Description copied from interface:SnmpService
Updates (SETs) a set of changes with an atomic SET operation asynchronously.- Specified by:
update
in interfaceSnmpService
- Parameters:
snmpTransaction
- the transaction that controls this update.target
- the SNMP target.variableBindings
- the change set to commit to the agent identified bytarget
.commitListener
- a listener for commit events.
-
commit
public List<? extends SnmpCommitResult> commit(SnmpTransaction transaction, SnmpCommitListener commitListener) Description copied from interface:TransactionManager
Commits the transaction to the agent.- Specified by:
commit
in interfaceTransactionManager
- Parameters:
transaction
- the transaction to commit.commitListener
- the optional listener that is immediately informed during this commit call about failures and successful committed change sets.- Returns:
- the
SnmpErrorStatus
indicating success or failure reason of the transaction.
-
rollback
- Specified by:
rollback
in interfaceTransactionManager
-
isAtomic
Description copied from interface:TransactionManager
Checks if this transaction can be committed with atomicity. As SNMP guarantees atomicity only for a single SET PDU. That is, if a transaction cannot be completed with a single SET PDU (message), this method will returnfalse
.- Specified by:
isAtomic
in interfaceTransactionManager
- Parameters:
transaction
- the transaction to test.- Returns:
true
if this transaction can be committed by using a single SET PDU. Thus, the variables to set do not exceed the target's maximum size PDU length (including estimated SNMP message overhead).
-
getSnmpTransaction
- Specified by:
getSnmpTransaction
in interfaceTransactionManager
-