Package org.snmp4j.agent
Class DefaultMOServer
java.lang.Object
org.snmp4j.agent.DefaultMOServer
- All Implemented Interfaces:
MOServer
The default MO server implementation uses a sorted map for the managed object
registry.
- Version:
- 2.4.0
- Author:
- Frank Fock
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addContext
(org.snmp4j.smi.OctetString context) Adds the supplied context to the server.void
Adds a context listener to the server.void
addLookupListener
(MOServerLookupListener listener, ManagedObject mo) Adds a managed object lookup listener for the supplied managed object to this managed object server.protected void
checkForUpdate
(UpdatableManagedObject mo, MOQuery query) ChecksupdateStrategy
whether the queried managed object needs to be updated.protected void
fireContextChanged
(ContextEvent event) protected void
fireLookupEvent
(ManagedObject mo, MOQuery query) protected void
fireQueryEvent
(ManagedObject mo, MOQuery query) org.snmp4j.smi.OctetString[]
Returns the contexts known by the server.Return the locking strategy for this server.getManagedObject
(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context) Returns theManagedObject
with the specifiedOID
as ID returned byRegisteredManagedObject.getID()
or the lower bound (regardless whether the ManagedObject's scope includes it or not) when registered in the supplied context.getManagedObject
(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context, boolean fireLookupEvents) Returns theManagedObject
with the specifiedOID
as ID returned byRegisteredManagedObject.getID()
or the lower bound (regardless whether the ManagedObject's scope includes it or not) when registered in the supplied context.org.snmp4j.smi.OctetString[]
getRegisteredContexts
(ManagedObject managedObject) Returns the contexts for which the suppliedManagedObject
has been registered.Gets the update strategy forUpdatableManagedObject
s.static org.snmp4j.smi.Variable
Returns the value of a particular MIB object instance using theManagedObjectValueAccess
interface.boolean
isContextSupported
(org.snmp4j.smi.OctetString context) Checks whether the supplied context is supported (registered) by this server.iterator()
Return a read-onlyIterator
over the content of this server.boolean
lock
(Object owner, ManagedObject managedObject) Locks a ManagedObject by the supplied owner.boolean
lock
(Object owner, ManagedObject managedObject, long timeoutMillis) Locks a ManagedObject by the supplied owner.Lookup the first (lexicographically ordered) managed object that matches the supplied query.lookup
(MOQuery query, LockRequest lockRequest) Lookup the first (lexicographically ordered) managed object that matches the supplied query.void
register
(ManagedObject mo, org.snmp4j.smi.OctetString context) Registers a managed object for the specified context.static <R extends MOTableRow,
T extends MOTable<R, ? extends MOColumn, ? extends MOTableModel<R>>>
voidregisterTableRowListener
(MOServer server, MOTableRowListener<R> listener) Register a singleMOTableRowListener
with all tables in the specifiedMOServer
.void
removeContext
(org.snmp4j.smi.OctetString context) Removes a context from the server.void
Removes a previously added context listener.boolean
removeLookupListener
(MOServerLookupListener listener, ManagedObject mo) Removes a managed object lookup listener for the specified managed object.void
setLockStrategy
(MOLockStrategy lockStrategy) Sets the lock strategy for this server.void
setUpdateStrategy
(UpdateStrategy updateStrategy) Sets the update strategy forUpdatableManagedObject
s.static boolean
setValue
(MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.smi.VariableBinding newValueAndKey) Sets the value of a particular MIB object instance using theManagedObjectValueAccess
interface.toString()
boolean
unlock
(Object owner, ManagedObject managedObject) Unlocks a ManagedObject that has been locked by the specified owner.unregister
(ManagedObject mo, org.snmp4j.smi.OctetString context) Removes the registration of the supplied managed object for the specified context.static <R extends MOTableRow,
T extends MOTable<R, ? extends MOColumn, ? extends MOTableModel<R>>>
voidunregisterTableRowListener
(MOServer server, MOTableRowListener<R> listener) Unregister a singleMOTableRowListener
with all tables in the specifiedMOServer
.
-
Constructor Details
-
DefaultMOServer
public DefaultMOServer()
-
-
Method Details
-
lookup
Description copied from interface:MOServer
Lookup the first (lexicographically ordered) managed object that matches the supplied query. No locking will be performed, regardless of the setMOLockStrategy
. -
lookup
Description copied from interface:MOServer
Lookup the first (lexicographically ordered) managed object that matches the supplied query. Locking will be performed according to the setMOLockStrategy
before the lookup listener is fired. CAUTION: To make sure that the acquired lock is released after the using of the managed object has been finished, theMOServer.unlock(Object, ManagedObject)
method must be called then.- Specified by:
lookup
in interfaceMOServer
- Parameters:
query
- aMOQuery
instance.lockRequest
- theLockRequest
that holds the lock owner and the timeout for acquiring a lock and returns whether a lock has been acquired or not on behalf of this lookup operation.- Returns:
- the
ManagedObject
that matches the query andnull
if no such object exists.
-
getLockStrategy
Return the locking strategy for this server. The strategy defines if a lock is acquired before a looked upManagedObject
is returned (and before the corresponding lookup event is being fired) or not.- Returns:
- the managed object locking strategy instance used by this server. If
null
, no locking is performed at all (which is only recommended for static content servers). - Since:
- 2.4.0
-
setLockStrategy
Sets the lock strategy for this server. The strategy defines if a lock is acquired before a looked upManagedObject
is returned (and before the corresponding lookup event is being fired) or not. By default, only write access needs a lock.- Parameters:
lockStrategy
- aMOLockStrategy
instance ornull
to suppress any locking.- Since:
- 2.4.0
-
checkForUpdate
ChecksupdateStrategy
whether the queried managed object needs to be updated. This method is called on behalf oflookup(MOQuery query)
afterfireQueryEvent(org.snmp4j.agent.ManagedObject, org.snmp4j.agent.MOQuery)
and beforefireLookupEvent(org.snmp4j.agent.ManagedObject, org.snmp4j.agent.MOQuery)
is being called.- Parameters:
mo
- an UpdatableManagedObject instance.query
- the query that is interested in content ofmo
.- Since:
- 1.2
-
getManagedObject
public ManagedObject getManagedObject(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context, boolean fireLookupEvents) Returns theManagedObject
with the specifiedOID
as ID returned byRegisteredManagedObject.getID()
or the lower bound (regardless whether the ManagedObject's scope includes it or not) when registered in the supplied context.Note: The query used to lookup the managed object will indicate an intended read-only access for the
MOServerLookupEvent
s fired on behalf of this method.- Parameters:
key
- the OID identifying the key (lower bound) of theManagedObject
.context
- the optional context to look in. Anull
value searches in all contexts.fireLookupEvents
- iftrue
lookup and query events will be fired as if the managed objects has been looked up bylookup(MOQuery)
. In addition, if the looked up managed object is anUpdatableManagedObject
it will be locked if the lock strategy of this server requires it. The lock is active until the look up events have been fired completely. The lock operation waits without timeout for the lock to become available. Otherwise, no events will be fired at all.- Returns:
- the
ManagedObject
instance ornull
if such an instance does not exists. - Since:
- 2.3
-
getManagedObject
Returns theManagedObject
with the specifiedOID
as ID returned byRegisteredManagedObject.getID()
or the lower bound (regardless whether the ManagedObject's scope includes it or not) when registered in the supplied context. Note: The query used to lookup the managed object will indicate an intended read-only access for theMOServerLookupEvent
s fired on behalf of this method.- Parameters:
key
- the OID identifying the key (lower bound) of theManagedObject
.context
- the optional context to look in. Anull
value searches in all contexts.- Returns:
- the
ManagedObject
instance ornull
if such an instance does not exists. - Since:
- 1.1
-
getValue
public static org.snmp4j.smi.Variable getValue(MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID key) Returns the value of a particular MIB object instance using theManagedObjectValueAccess
interface. If aManagedObject
does not support this interface, its value cannot be returned andnull
will be returned instead. Note: This method does not perform any locking based on theMOLockStrategy
.- Parameters:
server
- theMOServer
where to lookup the value.context
- the optional context to look in. Anull
value searches in all contexts.key
- the OID identifying the variable instance to return.- Returns:
- the
Variable
associated withOID
andcontext
inserver
ornull
if no such variable exists. - Since:
- 1.4
-
setValue
public static boolean setValue(MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.smi.VariableBinding newValueAndKey) Sets the value of a particular MIB object instance using theManagedObjectValueAccess
interface. If aManagedObject
does not support this interface, its value cannot be set andfalse
will be returned. Note: This method does not perform any locking based on theMOLockStrategy
.- Parameters:
server
- theMOServer
where to lookup the value.context
- the optional context to look in. Anull
value searches in all contexts.newValueAndKey
- the OID identifying the variable instance to set and its new value.- Returns:
- the
true
if the value has been set successfully,false
otherwise. - Since:
- 1.4
-
fireLookupEvent
-
fireQueryEvent
-
getContexts
public org.snmp4j.smi.OctetString[] getContexts()Description copied from interface:MOServer
Returns the contexts known by the server.- Specified by:
getContexts
in interfaceMOServer
- Returns:
- an array of context names.
-
isContextSupported
public boolean isContextSupported(org.snmp4j.smi.OctetString context) Description copied from interface:MOServer
Checks whether the supplied context is supported (registered) by this server.- Specified by:
isContextSupported
in interfaceMOServer
- Parameters:
context
- a context name.- Returns:
true
if the context is support (thus has previously added byMOServer.addContext(org.snmp4j.smi.OctetString)
) andfalse
otherwise.
-
getRegistry
-
getUpdateStrategy
Gets the update strategy forUpdatableManagedObject
s. If the strategy isnull
no updates will be performed on behalf of calls tolookup(org.snmp4j.agent.MOQuery)
.- Returns:
- the current UpdateStrategy instance or
null
if no strategy is active. - Since:
- 1.2
- See Also:
-
setUpdateStrategy
Sets the update strategy forUpdatableManagedObject
s. If the strategy isnull
no updates will be performed on behalf of calls tolookup(MOQuery)
.- Parameters:
updateStrategy
- the new UpdateStrategy instance ornull
if no updates should be performed.- Since:
- 1.2
- See Also:
-
register
public void register(ManagedObject mo, org.snmp4j.smi.OctetString context) throws DuplicateRegistrationException Description copied from interface:MOServer
Registers a managed object for the specified context. A managed object can be registered for more than one context.- Specified by:
register
in interfaceMOServer
- Parameters:
mo
- aManagedObject
instance.context
- the context name for which to register themo
ornull
if the managed oject is to be registered for all contexts (including the default context).- Throws:
DuplicateRegistrationException
- if the registration conflicts (i.e. overlaps) with an already existing registration.
-
unregister
Description copied from interface:MOServer
Removes the registration of the supplied managed object for the specified context.- Specified by:
unregister
in interfaceMOServer
- Parameters:
mo
- aManagedObject
instance.context
- the context name for which to unregister themo
ornull
if the managed object is to be unregistered for all contexts (including the default context). In the latter case however, explicit registrations for a particular context will not be removed!- Returns:
- the removed
ManagedObject
instance ornull
if the removal failed.
-
addContext
public void addContext(org.snmp4j.smi.OctetString context) Description copied from interface:MOServer
Adds the supplied context to the server. The server however may silently ignore the request if local constraints do not allow to add the context (although this should be an exception case only).- Specified by:
addContext
in interfaceMOServer
- Parameters:
context
- anOctetString
representing the context name to add.
-
removeContext
public void removeContext(org.snmp4j.smi.OctetString context) Description copied from interface:MOServer
Removes a context from the server. Removing a context does not remove any managed objects from the server's registry.- Specified by:
removeContext
in interfaceMOServer
- Parameters:
context
- nOctetString
representing the context name to remove.
-
lock
Description copied from interface:MOServer
Locks a ManagedObject by the supplied owner. Once a ManagedObject is locked, a lookup attempt will block until it is unlocked or a predefined timeout occurs. -
lock
Description copied from interface:MOServer
Locks a ManagedObject by the supplied owner. Once a ManagedObject is locked, a lookup attempt will block until it is unlocked or a predefined timeout occurs.- Specified by:
lock
in interfaceMOServer
- Parameters:
owner
- an Object.managedObject
- the ManagedObject to lock.timeoutMillis
- the number of 1/1000 seconds to wait for the lock. 0 or less disables the timeout and waits forever until the lock is released by the current owner.- Returns:
true
if the lock could be acquired,false
otherwise, i.e. if an InterruptedException or timeout has occurred.
-
unlock
Description copied from interface:MOServer
Unlocks a ManagedObject that has been locked by the specified owner. If the ManagedObject is currently locked by another owner this method returns silently.Note: In debug log mode a message is locked if the lock owner does not match the current lock owner.
-
iterator
Description copied from interface:MOServer
Return a read-onlyIterator
over the content of this server. The iterator is thread safe and can be used while the server is being modified. The remove operation of the iterator is not supported.- Specified by:
iterator
in interfaceMOServer
- Returns:
- the
Iterator
on the Map.Entry instances managed by this server. EachEntry
consists of anMOScope
key instance and a correspondingManagedObject
value instance. If theManagedObject
has been registered for a specific context, then aMOContextScope
is returned as key, otherwise the managed objects ownMOScope
is returned.
-
addLookupListener
Description copied from interface:MOServer
Adds a managed object lookup listener for the supplied managed object to this managed object server. AMOServerLookupListener
is called before the managed object is returned byMOServer.lookup(MOQuery query)
.- Specified by:
addLookupListener
in interfaceMOServer
- Parameters:
listener
- aMOServerLookupListener
instance, for example a managed object that needs to update its state whenever it has been looked upmo
- theManagedObject
that triggers theMOServerLookupEvent
to be fired when it has been looked up.
-
removeLookupListener
Description copied from interface:MOServer
Removes a managed object lookup listener for the specified managed object.- Specified by:
removeLookupListener
in interfaceMOServer
- Parameters:
listener
- aMOServerLookupListener
instance.mo
- theManagedObject
that triggered theMOServerLookupEvent
to be fired when it has been looked up.- Returns:
true
if the listener could be removed orfalse
if such a listener is not registered.
-
addContextListener
Description copied from interface:MOServer
Adds a context listener to the server. The listener will be informed about context insertion and removal.- Specified by:
addContextListener
in interfaceMOServer
- Parameters:
l
- aContextListener
instance to be informed about context changes.
-
removeContextListener
Description copied from interface:MOServer
Removes a previously added context listener.- Specified by:
removeContextListener
in interfaceMOServer
- Parameters:
l
- aContextListener
instance.
-
fireContextChanged
-
toString
-
getRegisteredContexts
Description copied from interface:MOServer
Returns the contexts for which the suppliedManagedObject
has been registered.- Specified by:
getRegisteredContexts
in interfaceMOServer
- Parameters:
managedObject
- aManagedObject
instance.- Returns:
- an array of context strings, for which
managedObject
has been registered. If themanagedObject
has been registered for all contexts, anull
element is included in the array.
-
registerTableRowListener
public static <R extends MOTableRow,T extends MOTable<R, void registerTableRowListener? extends MOColumn, ? extends MOTableModel<R>>> (MOServer server, MOTableRowListener<R> listener) Register a singleMOTableRowListener
with all tables in the specifiedMOServer
. This overall registration can be used, for example, to apply table size limits to all tables in an agent. SeeMOTableSizeLimit
for details.Note: The server must not change its registration content while this method is being called, otherwise a
ConcurrentModificationException
might be thrown.- Type Parameters:
R
- theMOTableRow
type supported by the table row listener to register.T
- theMOTable
type supported by the table row listener to register.- Parameters:
server
- aMOServer
instance.listener
- theMOTableRowListener
instance to register.- Since:
- 1.4
-
unregisterTableRowListener
public static <R extends MOTableRow,T extends MOTable<R, void unregisterTableRowListener? extends MOColumn, ? extends MOTableModel<R>>> (MOServer server, MOTableRowListener<R> listener) Unregister a singleMOTableRowListener
with all tables in the specifiedMOServer
. This overall unregistration can be used, for example, to remove table size limits from all tables in an agent. SeeMOTableSizeLimit
for details. Note: The server must not change its registration content while this method is being called, otherwise aConcurrentModificationException
might be thrown.- Type Parameters:
R
- theMOTableRow
type supported by the table row listener to register.T
- theMOTable
type supported by the table row listener to register.- Parameters:
server
- aMOServer
instance.listener
- theMOTableRowListener
instance to unregister.- Since:
- 1.4
-