Module org.snmp4j.agent
Package org.snmp4j.agent.mo
Class MOScalar<V extends org.snmp4j.smi.Variable>
- java.lang.Object
-
- org.snmp4j.agent.mo.MOScalar<V>
-
- All Implemented Interfaces:
ManagedObject<SubRequest<?>>,ManagedObjectValueAccess<SubRequest<?>>,ChangeableManagedObject<SubRequest<?>>,GenericManagedObject,MOScope,RandomAccessManagedObject<SubRequest<?>>,RegisteredManagedObject<SubRequest<?>>,SerializableManagedObject<SubRequest<?>>
- Direct Known Subclasses:
AgentppSimulationMib.AgentppSimDeleteRow,AgentppSimulationMib.AgentppSimDeleteTableContents,DateAndTimeScalar,DisplayStringScalar,EnumeratedScalar,NotificationLogMib.NlmConfigGlobalAgeOut,NotificationLogMib.NlmConfigGlobalEntryLimit,SnmpTsmMib.SnmpTsmConfigurationUsePrefix,SNMPv2MIB.SysUpTimeImpl,TestAndIncr,TimeStampScalar,UsmDHParametersImpl
public class MOScalar<V extends org.snmp4j.smi.Variable> extends Object implements GenericManagedObject, MOScope, SerializableManagedObject<SubRequest<?>>, ManagedObjectValueAccess<SubRequest<?>>, ChangeableManagedObject<SubRequest<?>>, RandomAccessManagedObject<SubRequest<?>>
TheMOScalarclass represents scalar SNMP managed objects. Subclasses might support Java serialization for this class. SNMP4J serialization is provided in any case by theSerializableManagedObjectinterface.- Version:
- 3.1.0
- Author:
- Frank Fock
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddMOChangeListener(MOChangeListener l)Adds aMOChangeListenerthat needs to be informed about state changes of this scalar.voidaddMOValueValidationListener(MOValueValidationListener l)Adds a value validation listener to check new values.protected intchangeValue(V value)Changes the value of this scalar on behalf of a commit or undo operation.protected booleancheckRequestScope(SubRequest<?> request)Checks whether the request is within the scope of this scalar or not.voidcleanup(SubRequest<?> request)Cleansup a (sub)request and frees all resources locked during the preparation phase.voidcommit(SubRequest<?> request)Commits a previously prepared SET (sub)request.booleancovers(org.snmp4j.smi.OID oid)Checks if this scope covers the supplied OID.List<org.snmp4j.smi.VariableBinding>exportInstance(org.snmp4j.smi.OID instanceID)Exports the byte representation of an instance of theManagedObject.org.snmp4j.smi.OIDfind(MOScope range)Finds the first object ID (OID) in the specified search range.protected voidfireAfterMOChange(MOChangeEvent changeEvent)protected voidfireAfterPrepareMOChange(MOChangeEvent changeEvent)protected voidfireBeforeMOChange(MOChangeEvent changeEvent)protected voidfireBeforePrepareMOChange(MOChangeEvent changeEvent)protected voidfireValidate(MOValueValidationEvent validationEvent)voidget(SubRequest<?> request)Processes a GET request and return the result in the supplied sub-request.MOAccessgetAccess()Gets the access object for this scalar.org.snmp4j.smi.OIDgetID()Gets the unique object ID of the managed object.org.snmp4j.smi.OIDgetLowerBound()Gets the lower bound OID of the scope.org.snmp4j.smi.OIDgetOid()Gets the instance OID of this scalar managed object.MOScopegetScope()Returns the scope of OIDs that are covered by this scalar's object registration.MOScopegetSingleInstanceScope()Returns a scope that covers only the scalar instance itself without any possible OIDs down in the tree or at the same level.protected intgetSyntax()Get the syntax of the scalars value by evaluating the internal cached value first.org.snmp4j.smi.OIDgetUpperBound()Gets the upper bound OID of the scope.VgetValue()Returns the actual value of this scalar managed object.org.snmp4j.smi.VariablegetValue(org.snmp4j.smi.OID instanceOID)Returns the variable (a copy thereof) with the specified instance OID managed by thisManagedObject.booleanimportInstance(org.snmp4j.smi.OID instanceID, List<org.snmp4j.smi.VariableBinding> data, ImportMode importMode)Imports the data that internally represents the instance specified by the OID suffixinstanceIDfrom the byte data provided which can be encoded in any representation theManagedObjectis able to understand.intinstanceCount()Returns the number of instances managed by thisManagedObject.Iterator<org.snmp4j.smi.OID>instanceIterator()booleanisCovered(MOScope other)Checks whether the supplied scope is covered by this scope.booleanisLowerIncluded()Indicates whether the lower bound OID is included in the scope or not.booleanisOverlapping(MOScope other)Checks whether the supplied scope overlap with this one, thus sharing at least one OID with the supplied one.booleanisUpperIncluded()Indicates whether the upper bound OID is included in the scope or not.intisValueOK(SubRequest<?> request)Checks whether the new value contained in the supplied sub-request is a valid value for this object.booleanisVolatile()Tests if this instance of a SerializableManagedObject should be serialized or deserialized through persistent storage load or save operation.voidload(MOInput input)Loads the content of the managed object from the specified input (stream).booleannext(SubRequest<?> request)Finds the successor instance for the object instance ID (OID) given by the supplied sub-request and returns it within the supplied sub-request object.voidprepare(SubRequest<?> request)Prepares a SET (sub)request.voidremoveMOChangeListener(MOChangeListener l)Removes aMOChangeListener.voidremoveMOValueValidationListener(MOValueValidationListener l)Removes a value validation listenervoidsave(MOOutput output)Saves the (non-volatile) content of this managed object to the specified output (stream).booleansetValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)Sets the value of a particular MIB object instance managed by thisManagedObject.intsetValue(V value)Sets the value of this scalar managed object without checking it for the correct syntax.voidsetVolatile(boolean isVolatile)Sets the volatile flag for this instance.StringtoString()protected StringtoStringDetails()voidundo(SubRequest<?> request)Compensates (undo) a (sub)request when a commit of another subrequest failed with an error.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.snmp4j.agent.RandomAccessManagedObject
getInstanceSubID, isVolatile
-
-
-
-
Field Detail
-
oid
protected org.snmp4j.smi.OID oid
-
access
protected MOAccess access
-
-
Constructor Detail
-
MOScalar
protected MOScalar()
Construct a MOScalar for deserialization. If used by a subclass, make sure theoidandaccessmembers are set before the scalar is registered with aMOServerinstance. Theoidmust not be changed or modified afterwards!- Since:
- 2.4.1
-
MOScalar
public MOScalar(org.snmp4j.smi.OID id, MOAccess access, V value)Creates a scalar MO instance with OID, maximum access level and initial value.- Parameters:
id- the instance OID of the scalar instance (last sub-identifier should be zero).access- the maximum access level supported by this instance.value- the initial value of the scalar instance. If the initial value isnullor a Counter syntax, the scalar is created as a volatile (non-persistent) instance by default.
-
-
Method Detail
-
getScope
public MOScope getScope()
Returns the scope of OIDs that are covered by this scalar's object registration. This range is1.3.6...n<= x <1.3.6...n+1where n is the last subidentifier of the OID registered by the corresponding OBJECT-TYPE definition. Prior to version 1.1.2, this method returned a scope equal to the scope now returned bygetSingleInstanceScope().- Specified by:
getScopein interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Returns:
- a MOScope that covers the OIDs by this scalar object registration.
-
getSingleInstanceScope
public MOScope getSingleInstanceScope()
Returns a scope that covers only the scalar instance itself without any possible OIDs down in the tree or at the same level.- Returns:
- a scope that covers exactly the OID of this scalar.
- Since:
- 1.1.2
-
find
public org.snmp4j.smi.OID find(MOScope range)
Description copied from interface:ManagedObjectFinds the first object ID (OID) in the specified search range.- Specified by:
findin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
range- theMOScopefor the search.- Returns:
- the
OIDthat is included in the searchrangeandnullif no such instances could be found.
-
get
public void get(SubRequest<?> request)
Description copied from interface:ManagedObjectProcesses a GET request and return the result in the supplied sub-request.- Specified by:
getin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.
-
getAccess
public MOAccess getAccess()
Gets the access object for this scalar.- Returns:
- the access instance associated with this scalar.
- Since:
- 1.2
-
checkRequestScope
protected boolean checkRequestScope(SubRequest<?> request)
Checks whether the request is within the scope of this scalar or not.- Parameters:
request- a SubRequest.- Returns:
trueif the request is within scope andfalseotherwise. In the latter case, the variable of the request is set toNull.noSuchInstanceand the request is marked completed.
-
next
public boolean next(SubRequest<?> request)
Description copied from interface:ManagedObjectFinds the successor instance for the object instance ID (OID) given by the supplied sub-request and returns it within the supplied sub-request object.- Specified by:
nextin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.- Returns:
trueif the search request found an appropriate instance,falseotherwise.
-
isValueOK
public int isValueOK(SubRequest<?> request)
Checks whether the new value contained in the supplied sub-request is a valid value for this object. The checks are performed by firing aMOValueValidationEventthe registered listeners.- Parameters:
request- theSubRequestwith the new value.- Returns:
SnmpConstants.SNMP_ERROR_SUCCESSif the new value is OK, any other appropriate SNMPv2/v3 error status if not.
-
getSyntax
protected int getSyntax()
Get the syntax of the scalars value by evaluating the internal cached value first. If that isnull, thegetValue()method is called instead to allow subclasses to return an updated value.- Returns:
value.getSyntax()if value is not null andgetValue().,getSyntax()if value is null.
-
prepare
public void prepare(SubRequest<?> request)
Description copied from interface:ManagedObjectPrepares a SET (sub)request. This method represents the first phase of a two phase commit. During preparation all necessary resources should be locked in order to be able to execute the commit without claiming additional resources.- Specified by:
preparein interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.
-
commit
public void commit(SubRequest<?> request)
Description copied from interface:ManagedObjectCommits a previously prepared SET (sub)request. This is the second phase of a two phase commit. The change is committed but the resources locked during prepare not freed yet.- Specified by:
commitin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.
-
changeValue
protected int changeValue(V value)
Changes the value of this scalar on behalf of a commit or undo operation. Overwrite this method for easy and simple instrumentation. By defaultsetValue(Variable value)is called.- Parameters:
value- the new value.- Returns:
- a SNMP error status if the operation failed (should be avoided).
- Since:
- 1.2
-
undo
public void undo(SubRequest<?> request)
Description copied from interface:ManagedObjectCompensates (undo) a (sub)request when a commit of another subrequest failed with an error. This also frees any resources locked during the preparation phase.- Specified by:
undoin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.
-
cleanup
public void cleanup(SubRequest<?> request)
Description copied from interface:ManagedObjectCleansup a (sub)request and frees all resources locked during the preparation phase.- Specified by:
cleanupin interfaceManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
request- theSubRequestto process.
-
getOid
public org.snmp4j.smi.OID getOid()
Gets the instance OID of this scalar managed object.- Returns:
- the instance OID (by reference).
-
getLowerBound
public org.snmp4j.smi.OID getLowerBound()
Description copied from interface:MOScopeGets the lower bound OID of the scope. Whether the lower bound is included or excluded from the scope's region is determined byMOScope.isLowerIncluded().- Specified by:
getLowerBoundin interfaceMOScope- Returns:
- an OID.
-
getUpperBound
public org.snmp4j.smi.OID getUpperBound()
Description copied from interface:MOScopeGets the upper bound OID of the scope. Whether the upper bound is included or excluded from the scope's region is determined byMOScope.isUpperIncluded().- Specified by:
getUpperBoundin interfaceMOScope- Returns:
- OID
-
isCovered
public boolean isCovered(MOScope other)
Description copied from interface:MOScopeChecks whether the supplied scope is covered by this scope.
-
isLowerIncluded
public boolean isLowerIncluded()
Description copied from interface:MOScopeIndicates whether the lower bound OID is included in the scope or not.- Specified by:
isLowerIncludedin interfaceMOScope- Returns:
trueif the lower bound is included.
-
isUpperIncluded
public boolean isUpperIncluded()
Description copied from interface:MOScopeIndicates whether the upper bound OID is included in the scope or not.- Specified by:
isUpperIncludedin interfaceMOScope- Returns:
trueif the upper bound is included.
-
getValue
public V getValue()
Returns the actual value of this scalar managed object. For a basic instrumentation, overwrite this method to provide always the actual value and/or to update the internalvaluemember and then callsuper.getValue()in the derived class.- Returns:
- a non
nullVariable with the same syntax defined for this scalar object.
-
isVolatile
public boolean isVolatile()
Description copied from interface:SerializableManagedObjectTests if this instance of a SerializableManagedObject should be serialized or deserialized through persistent storage load or save operation.- Specified by:
isVolatilein interfaceRandomAccessManagedObject<V extends org.snmp4j.smi.Variable>- Specified by:
isVolatilein interfaceSerializableManagedObject<V extends org.snmp4j.smi.Variable>- Returns:
trueifSerializableManagedObject.load(org.snmp4j.agent.io.MOInput)andSerializableManagedObject.save(org.snmp4j.agent.io.MOOutput)should not be called through a persistent storage operation andfalseif these method should be called.
-
setValue
public int setValue(V value)
Sets the value of this scalar managed object without checking it for the correct syntax.- Parameters:
value- a Variable with the with the same syntax defined for this scalar object (not checked).- Returns:
- a SNMP error code (zero indicating success by default).
-
setVolatile
public void setVolatile(boolean isVolatile)
Sets the volatile flag for this instance.- Parameters:
isVolatile- iftruethe state of this object will not be persistently stored, otherwise the agent may save the state of this object persistently.
-
isOverlapping
public boolean isOverlapping(MOScope other)
Description copied from interface:MOScopeChecks whether the supplied scope overlap with this one, thus sharing at least one OID with the supplied one.- Specified by:
isOverlappingin interfaceMOScope- Parameters:
other- aMOScope.- Returns:
trueif there exists at least one OID that is included in both scopes.
-
addMOValueValidationListener
public void addMOValueValidationListener(MOValueValidationListener l)
Adds a value validation listener to check new values.- Parameters:
l- aMOValueValidationListenerinstance.
-
removeMOValueValidationListener
public void removeMOValueValidationListener(MOValueValidationListener l)
Removes a value validation listener- Parameters:
l- aMOValueValidationListenerinstance.
-
fireValidate
protected void fireValidate(MOValueValidationEvent validationEvent)
-
getID
public org.snmp4j.smi.OID getID()
Description copied from interface:RegisteredManagedObjectGets the unique object ID of the managed object.- Specified by:
getIDin interfaceRegisteredManagedObject<V extends org.snmp4j.smi.Variable>- Returns:
- an OID.
-
load
public void load(MOInput input) throws IOException
Description copied from interface:SerializableManagedObjectLoads the content of the managed object from the specified input (stream).- Specified by:
loadin interfaceSerializableManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
input- aMOInputinstance.- Throws:
IOException- if an MOInput operation fails.
-
save
public void save(MOOutput output) throws IOException
Description copied from interface:SerializableManagedObjectSaves the (non-volatile) content of this managed object to the specified output (stream).- Specified by:
savein interfaceSerializableManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
output- aMOOutputinstance.- Throws:
IOException- if an MOOutput operation fails.
-
covers
public boolean covers(org.snmp4j.smi.OID oid)
Description copied from interface:MOScopeChecks if this scope covers the supplied OID.
-
toStringDetails
protected String toStringDetails()
-
addMOChangeListener
public void addMOChangeListener(MOChangeListener l)
Adds aMOChangeListenerthat needs to be informed about state changes of this scalar.- Specified by:
addMOChangeListenerin interfaceChangeableManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
l- aMOChangeListenerinstance.- Since:
- 1.1
-
removeMOChangeListener
public void removeMOChangeListener(MOChangeListener l)
Removes aMOChangeListener.- Specified by:
removeMOChangeListenerin interfaceChangeableManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
l- aMOChangeListenerinstance.- Since:
- 1.1
-
fireBeforePrepareMOChange
protected void fireBeforePrepareMOChange(MOChangeEvent changeEvent)
-
fireAfterPrepareMOChange
protected void fireAfterPrepareMOChange(MOChangeEvent changeEvent)
-
fireBeforeMOChange
protected void fireBeforeMOChange(MOChangeEvent changeEvent)
-
fireAfterMOChange
protected void fireAfterMOChange(MOChangeEvent changeEvent)
-
getValue
public org.snmp4j.smi.Variable getValue(org.snmp4j.smi.OID instanceOID)
Description copied from interface:ManagedObjectValueAccessReturns the variable (a copy thereof) with the specified instance OID managed by thisManagedObject.- Specified by:
getValuein interfaceManagedObjectValueAccess<V extends org.snmp4j.smi.Variable>- Parameters:
instanceOID- the instance OID of the value. Thus, for scalar values with .0 suffix and for tabular objects with table index suffix.- Returns:
- a copy of the requested
Variableornullif such a variable does not exist.
-
setValue
public boolean setValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)
Description copied from interface:ManagedObjectValueAccessSets the value of a particular MIB object instance managed by thisManagedObject. This is a low level operation, thus no change events will be fired.- Specified by:
setValuein interfaceManagedObjectValueAccess<V extends org.snmp4j.smi.Variable>- Parameters:
newValueAndInstancceOID- aVariableBindingidentifying the object instance to modify by its OID and the new value by its variable part.- Returns:
trueif the object instance exists and has been modified successfully,falseotherwise.
-
importInstance
public boolean importInstance(org.snmp4j.smi.OID instanceID, List<org.snmp4j.smi.VariableBinding> data, ImportMode importMode)Description copied from interface:RandomAccessManagedObjectImports the data that internally represents the instance specified by the OID suffixinstanceIDfrom the byte data provided which can be encoded in any representation theManagedObjectis able to understand.- Specified by:
importInstancein interfaceRandomAccessManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
instanceID- the OID suffix identifying the instance to export, for scalars this is "0" and for tabular objects this is the row index.data- the SNMP data of the instance where the OID identifies the sub-instance (i.e. the column sub-ID for row instances and "0" for scalar objects).importMode- defines the import strategy - must not benull!- Returns:
trueif the import was successful,falseotherwise.
-
exportInstance
public List<org.snmp4j.smi.VariableBinding> exportInstance(org.snmp4j.smi.OID instanceID)
Description copied from interface:RandomAccessManagedObjectExports the byte representation of an instance of theManagedObject.- Specified by:
exportInstancein interfaceRandomAccessManagedObject<V extends org.snmp4j.smi.Variable>- Parameters:
instanceID- the OID suffix identifying the instance to export, for scalars this is "0" and for tabular objects this is the row index.- Returns:
- the SNMP data of the instance where the OID identifies the sub-instance (i.e. the column sub-ID for row instances and "0" for scalar objects).
-
instanceIterator
public Iterator<org.snmp4j.smi.OID> instanceIterator()
- Specified by:
instanceIteratorin interfaceRandomAccessManagedObject<V extends org.snmp4j.smi.Variable>
-
instanceCount
public int instanceCount()
Returns the number of instances managed by thisManagedObject.- Specified by:
instanceCountin interfaceRandomAccessManagedObject<V extends org.snmp4j.smi.Variable>- Returns:
- the number of instances managed by this object.
-
-