Class MOScalar<V extends org.snmp4j.smi.Variable>

java.lang.Object
org.snmp4j.agent.mo.MOScalar<V>
All Implemented Interfaces:
ManagedObject, ManagedObjectValueAccess, MOScope, RegisteredManagedObject, SerializableManagedObject
Direct Known Subclasses:
AgentppSimulationMib.AgentppSimDeleteRow, AgentppSimulationMib.AgentppSimDeleteTableContents, DateAndTimeScalar, DisplayStringScalar, EnumeratedScalar, NotificationLogMib.NlmConfigGlobalAgeOut, NotificationLogMib.NlmConfigGlobalEntryLimit, SnmpTsmMib.SnmpTsmConfigurationUsePrefix, SNMPv2MIB.SysUpTimeImpl, TestAndIncr, TimeStampScalar

public class MOScalar<V extends org.snmp4j.smi.Variable> extends Object implements ManagedObject, MOScope, SerializableManagedObject, ManagedObjectValueAccess
The MOScalar class represents scalar SNMP managed objects. Subclasses might support Java serialization for this class. SNMP4J serialization is provided in any case by the SerializableManagedObject interface.
Version:
2.4.1
Author:
Frank Fock
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected MOAccess
     
    protected org.snmp4j.smi.OID
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Construct a MOScalar for deserialization.
     
    MOScalar(org.snmp4j.smi.OID id, MOAccess access, V value)
    Creates a scalar MO instance with OID, maximum access level and initial value.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a MOChangeListener that needs to be informed about state changes of this scalar.
    void
    Adds a value validation listener to check new values.
    protected int
    changeValue(V value)
    Changes the value of this scalar on behalf of a commit or undo operation.
    protected boolean
    Checks whether the request is within the scope of this scalar or not.
    void
    Cleansup a (sub)request and frees all resources locked during the preparation phase.
    void
    commit(SubRequest request)
    Commits a previously prepared SET (sub)request.
    boolean
    covers(org.snmp4j.smi.OID oid)
    Checks if this scope covers the supplied OID.
    org.snmp4j.smi.OID
    find(MOScope range)
    Finds the first object ID (OID) in the specified search range.
    protected void
     
    protected void
     
    protected void
     
    protected void
     
    protected void
     
    void
    get(SubRequest request)
    Processes a GET request and return the result in the supplied sub-request.
    Gets the access object for this scalar.
    org.snmp4j.smi.OID
    Gets the unique object ID of the managed object.
    org.snmp4j.smi.OID
    Gets the lower bound OID of the scope.
    org.snmp4j.smi.OID
    Gets the instance OID of this scalar managed object.
    Returns the scope of OIDs that are covered by this scalar's object registration.
    Returns a scope that covers only the scalar instance itself without any possible OIDs down in the tree or at the same level.
    org.snmp4j.smi.OID
    Gets the upper bound OID of the scope.
    Returns the actual value of this scalar managed object.
    org.snmp4j.smi.Variable
    getValue(org.snmp4j.smi.OID instanceOID)
    Returns the variable (a copy thereof) with the specified instance OID managed by this ManagedObject.
    boolean
    Checks whether the supplied scope is covered by this scope.
    boolean
    Indicates whether the lower bound OID is included in the scope or not.
    boolean
    Checks whether the supplied scope overlap with this one, thus sharing at least one OID with the supplied one.
    boolean
    Indicates whether the upper bound OID is included in the scope or not.
    int
    Checks whether the new value contained in the supplied sub-request is a valid value for this object.
    boolean
    Tests if this instance of a SerializableManagedObject should be serialized or deserialized through persistent storage load or save operation.
    void
    load(MOInput input)
    Loads the content of the managed object from the specified input (stream).
    boolean
    next(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.
    void
    Prepares a SET (sub)request.
    void
    Removes a MOChangeListener.
    void
    Removes a value validation listener
    void
    save(MOOutput output)
    Saves the (non-volatile) content of this managed object to the specified output (stream).
    boolean
    setValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)
    Sets the value of a particular MIB object instance managed by this ManagedObject.
    int
    setValue(V value)
    Sets the value of this scalar managed object without checking it for the correct syntax.
    void
    setVolatile(boolean isVolatile)
    Sets the volatile flag for this instance.
     
    protected String
     
    void
    undo(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
  • Field Details

    • oid

      protected org.snmp4j.smi.OID oid
    • access

      protected MOAccess access
  • Constructor Details

    • MOScalar

      protected MOScalar()
      Construct a MOScalar for deserialization. If used by a subclass, make sure the oid and access members are set before the scalar is registered with a MOServer instance. The oid must 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 is null or a Counter syntax, the scalar is created as a volatile (non-persistent) instance by default.
  • Method Details

    • getScope

      public MOScope getScope()
      Returns the scope of OIDs that are covered by this scalar's object registration. This range is 1.3.6...n <= x < 1.3.6...n+1 where 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 by getSingleInstanceScope().
      Specified by:
      getScope in interface ManagedObject
      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: ManagedObject
      Finds the first object ID (OID) in the specified search range.
      Specified by:
      find in interface ManagedObject
      Parameters:
      range - the MOScope for the search.
      Returns:
      the OID that is included in the search range and null if no such instances could be found.
    • get

      public void get(SubRequest request)
      Description copied from interface: ManagedObject
      Processes a GET request and return the result in the supplied sub-request.
      Specified by:
      get in interface ManagedObject
      Parameters:
      request - the SubRequest to 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:
      true if the request is within scope and false otherwise. In the latter case, the variable of the request is set to Null.noSuchInstance and the request is marked completed.
    • next

      public boolean next(SubRequest request)
      Description copied from interface: ManagedObject
      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.
      Specified by:
      next in interface ManagedObject
      Parameters:
      request - the SubRequest to process.
      Returns:
      true if the search request found an appropriate instance, false otherwise.
    • 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 a MOValueValidationEvent the registered listeners.
      Parameters:
      request - the SubRequest with the new value.
      Returns:
      SnmpConstants.SNMP_ERROR_SUCCESS if the new value is OK, any other appropriate SNMPv2/v3 error status if not.
    • prepare

      public void prepare(SubRequest request)
      Description copied from interface: ManagedObject
      Prepares 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:
      prepare in interface ManagedObject
      Parameters:
      request - the SubRequest to process.
    • commit

      public void commit(SubRequest request)
      Description copied from interface: ManagedObject
      Commits 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:
      commit in interface ManagedObject
      Parameters:
      request - the SubRequest to 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 default setValue(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: ManagedObject
      Compensates (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:
      undo in interface ManagedObject
      Parameters:
      request - the SubRequest to process.
    • cleanup

      public void cleanup(SubRequest request)
      Description copied from interface: ManagedObject
      Cleansup a (sub)request and frees all resources locked during the preparation phase.
      Specified by:
      cleanup in interface ManagedObject
      Parameters:
      request - the SubRequest to 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: MOScope
      Gets the lower bound OID of the scope. Whether the lower bound is included or excluded from the scope's region is determined by MOScope.isLowerIncluded().
      Specified by:
      getLowerBound in interface MOScope
      Returns:
      an OID.
    • getUpperBound

      public org.snmp4j.smi.OID getUpperBound()
      Description copied from interface: MOScope
      Gets the upper bound OID of the scope. Whether the upper bound is included or excluded from the scope's region is determined by MOScope.isUpperIncluded().
      Specified by:
      getUpperBound in interface MOScope
      Returns:
      OID
    • isCovered

      public boolean isCovered(MOScope other)
      Description copied from interface: MOScope
      Checks whether the supplied scope is covered by this scope.
      Specified by:
      isCovered in interface MOScope
      Parameters:
      other - the MOScope to check
      Returns:
      true if the lower bound of other is greater or equal than the lower bound of this scope and if the upper bound of other is lower or equal than the upper bound of this scope.
    • isLowerIncluded

      public boolean isLowerIncluded()
      Description copied from interface: MOScope
      Indicates whether the lower bound OID is included in the scope or not.
      Specified by:
      isLowerIncluded in interface MOScope
      Returns:
      true if the lower bound is included.
    • isUpperIncluded

      public boolean isUpperIncluded()
      Description copied from interface: MOScope
      Indicates whether the upper bound OID is included in the scope or not.
      Specified by:
      isUpperIncluded in interface MOScope
      Returns:
      true if 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 internal value member and then call super.getValue() in the derived class.
      Returns:
      a non null Variable with the same syntax defined for this scalar object.
    • isVolatile

      public boolean isVolatile()
      Description copied from interface: SerializableManagedObject
      Tests if this instance of a SerializableManagedObject should be serialized or deserialized through persistent storage load or save operation.
      Specified by:
      isVolatile in interface SerializableManagedObject
      Returns:
      true if SerializableManagedObject.load(org.snmp4j.agent.io.MOInput) and SerializableManagedObject.save(org.snmp4j.agent.io.MOOutput) should not be called through a persistent storage operation and false if 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 - if true the 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: MOScope
      Checks whether the supplied scope overlap with this one, thus sharing at least one OID with the supplied one.
      Specified by:
      isOverlapping in interface MOScope
      Parameters:
      other - a MOScope.
      Returns:
      true if 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 - a MOValueValidationListener instance.
    • removeMOValueValidationListener

      public void removeMOValueValidationListener(MOValueValidationListener l)
      Removes a value validation listener
      Parameters:
      l - a MOValueValidationListener instance.
    • fireValidate

      protected void fireValidate(MOValueValidationEvent validationEvent)
    • getID

      public org.snmp4j.smi.OID getID()
      Description copied from interface: RegisteredManagedObject
      Gets the unique object ID of the managed object.
      Specified by:
      getID in interface RegisteredManagedObject
      Returns:
      an OID.
    • load

      public void load(MOInput input) throws IOException
      Description copied from interface: SerializableManagedObject
      Loads the content of the managed object from the specified input (stream).
      Specified by:
      load in interface SerializableManagedObject
      Parameters:
      input - a MOInput instance.
      Throws:
      IOException - if an MOInput operation fails.
    • save

      public void save(MOOutput output) throws IOException
      Description copied from interface: SerializableManagedObject
      Saves the (non-volatile) content of this managed object to the specified output (stream).
      Specified by:
      save in interface SerializableManagedObject
      Parameters:
      output - a MOOutput instance.
      Throws:
      IOException - if an MOOutput operation fails.
    • covers

      public boolean covers(org.snmp4j.smi.OID oid)
      Description copied from interface: MOScope
      Checks if this scope covers the supplied OID.
      Specified by:
      covers in interface MOScope
      Parameters:
      oid - an OID.
      Returns:
      true if oid is greater or equal the scope's lower bound and if it is less or equal its upper bound.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringDetails

      protected String toStringDetails()
    • addMOChangeListener

      public void addMOChangeListener(MOChangeListener l)
      Adds a MOChangeListener that needs to be informed about state changes of this scalar.
      Parameters:
      l - a MOChangeListener instance.
      Since:
      1.1
    • removeMOChangeListener

      public void removeMOChangeListener(MOChangeListener l)
      Removes a MOChangeListener.
      Parameters:
      l - a MOChangeListener instance.
      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: ManagedObjectValueAccess
      Returns the variable (a copy thereof) with the specified instance OID managed by this ManagedObject.
      Specified by:
      getValue in interface ManagedObjectValueAccess
      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 Variable or null if such a variable does not exist.
    • setValue

      public boolean setValue(org.snmp4j.smi.VariableBinding newValueAndInstancceOID)
      Description copied from interface: ManagedObjectValueAccess
      Sets the value of a particular MIB object instance managed by this ManagedObject. This is a low level operation, thus no change events will be fired.
      Specified by:
      setValue in interface ManagedObjectValueAccess
      Parameters:
      newValueAndInstancceOID - a VariableBinding identifying the object instance to modify by its OID and the new value by its variable part.
      Returns:
      true if the object instance exists and has been modified successfully, false otherwise.