- java.lang.Object
-
- org.snmp4j.agent.DefaultMOServer
-
-
Constructor Summary
Constructors Constructor Description DefaultMOServer()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContext(org.snmp4j.smi.OctetString context)Adds the supplied context to the server.voidaddContextListener(ContextListener l)Adds a context listener to the server.voidaddLookupListener(MOServerLookupListener listener, ManagedObject<?> mo)Adds a managed object lookup listener for the supplied managed object to this managed object server.protected voidcheckForUpdate(UpdatableManagedObject<?> mo, MOQuery query)ChecksupdateStrategywhether the queried managed object needs to be updated.protected voidfireContextChanged(ContextEvent event)protected voidfireLookupEvent(ManagedObject<?> mo, MOServerLookupEvent event)protected voidfireQueryEvent(ManagedObject<?> mo, MOServerLookupEvent event)org.snmp4j.smi.OctetString[]getContexts()Returns the contexts known by the server.MOLockStrategygetLockStrategy()Return the locking strategy for this server.ManagedObject<?>getManagedObject(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context)Returns theManagedObjectwith the specifiedOIDas ID returned byRegisteredManagedObject.getID()or the lower bound (regardless whether the ManagedObject's scope includes it or not) when registered in the supplied context.ManagedObject<?>getManagedObject(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context, boolean fireLookupEvents)Returns theManagedObjectwith the specifiedOIDas 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 suppliedManagedObjecthas been registered.SortedMap<MOScope,ManagedObject<?>>getRegistry()UpdateStrategygetUpdateStrategy()Gets the update strategy forUpdatableManagedObjects.static org.snmp4j.smi.VariablegetValue(MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID key)Returns the value of a particular MIB object instance using theManagedObjectValueAccessinterface.booleanisContextSupported(org.snmp4j.smi.OctetString context)Checks whether the supplied context is supported (registered) by this server.Iterator<Map.Entry<MOScope,ManagedObject<?>>>iterator()Return a read-onlyIteratorover the content of this server.booleanlock(Object owner, ManagedObject<?> managedObject)Locks a ManagedObject by the supplied owner.booleanlock(Object owner, ManagedObject<?> managedObject, long timeoutMillis)Locks a ManagedObject by the supplied owner.ManagedObjectlookup(MOQuery query)Lookup the first (lexicographically ordered) managed object that matches the supplied query.<MO extends ManagedObject<?>>
MOlookup(MOQuery query, LockRequest lockRequest, MOServerLookupEvent lookupEvent, Class<MO> managedObjectType)Lookup the first (lexicographically ordered) managed object that matches the supplied query and implements the givenManagedObjectclass.voidregister(ManagedObject<?> mo, org.snmp4j.smi.OctetString context)Registers a managed object for the specified context.static voidregisterChangeListener(MOServer server, MOChangeListener listener, MOFilter moFilter)Register a singleMOChangeListenerwith all objects matching the given filter in the specifiedMOServer.static <R extends MOTableRow,T extends MOTable<R,? extends MOColumn,? extends MOTableModel<R>>>
voidregisterTableRowListener(MOServer server, MOTableRowListener<R> listener)Register a singleMOTableRowListenerwith all tables in the specifiedMOServer.voidremoveContext(org.snmp4j.smi.OctetString context)Removes a context from the server.voidremoveContextListener(ContextListener l)Removes a previously added context listener.booleanremoveLookupListener(MOServerLookupListener listener, ManagedObject<?> mo)Removes a managed object lookup listener for the specified managed object.voidsetLockStrategy(MOLockStrategy lockStrategy)Sets the lock strategy for this server.voidsetUpdateStrategy(UpdateStrategy updateStrategy)Sets the update strategy forUpdatableManagedObjects.static booleansetValue(MOServer server, org.snmp4j.smi.OctetString context, org.snmp4j.smi.VariableBinding newValueAndKey)Sets the value of a particular MIB object instance using theManagedObjectValueAccessinterface.StringtoString()booleanunlock(Object owner, ManagedObject<?> managedObject)Unlocks a ManagedObject that has been locked by the specified owner.ManagedObject<?>unregister(ManagedObject<?> mo, org.snmp4j.smi.OctetString context)Removes the registration of the supplied managed object for the specified context.static voidunregisterChangeListener(MOServer server, MOChangeListener listener, MOFilter moFilter)Unregister a singleMOChangeListenerfrom all objects matching the given filter in the specifiedMOServer.static <R extends MOTableRow,T extends MOTable<R,? extends MOColumn,? extends MOTableModel<R>>>
voidunregisterTableRowListener(MOServer server, MOTableRowListener<R> listener)Unregister a singleMOTableRowListenerwith all tables in the specifiedMOServer.-
Methods inherited from interface org.snmp4j.agent.MOServer
lookup, lookup, lookup, registerNew
-
-
-
-
Method Detail
-
lookup
public ManagedObject lookup(MOQuery query)
Description copied from interface:MOServerLookup the first (lexicographically ordered) managed object that matches the supplied query. No locking will be performed, regardless of the setMOLockStrategy.
-
lookup
public <MO extends ManagedObject<?>> MO lookup(MOQuery query, LockRequest lockRequest, MOServerLookupEvent lookupEvent, Class<MO> managedObjectType)
Lookup the first (lexicographically ordered) managed object that matches the supplied query and implements the givenManagedObjectclass. Locking will be performed according to the setMOLockStrategybefore 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, theunlock(Object, ManagedObject)method must be called then.- Specified by:
lookupin interfaceMOServer- Type Parameters:
MO- theManagedObjecttype to lookup.- Parameters:
query- aMOQueryinstance.lockRequest- theLockRequestthat 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.lookupEvent- provides additional information about the intended use and optionally a callback to be informed about the completion of the use, including a reference to its result.managedObjectType- theManagedObjecttype filter. Only objects of this type will be looked up and returned.- Returns:
- the
ManagedObjectthat matches the query andnullif no such object exists. - Since:
- 3.1
-
getLockStrategy
public MOLockStrategy getLockStrategy()
Return the locking strategy for this server. The strategy defines if a lock is acquired before a looked upManagedObjectis 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
public void setLockStrategy(MOLockStrategy lockStrategy)
Sets the lock strategy for this server. The strategy defines if a lock is acquired before a looked upManagedObjectis returned (and before the corresponding lookup event is being fired) or not. By default, only write access needs a lock.- Parameters:
lockStrategy- aMOLockStrategyinstance ornullto suppress any locking.- Since:
- 2.4.0
-
checkForUpdate
protected void checkForUpdate(UpdatableManagedObject<?> mo, MOQuery query)
ChecksupdateStrategywhether 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.MOServerLookupEvent)and beforefireLookupEvent(org.snmp4j.agent.ManagedObject<?>, org.snmp4j.agent.MOServerLookupEvent)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 theManagedObjectwith the specifiedOIDas 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
MOServerLookupEvents fired on behalf of this method.- Parameters:
key- the OID identifying the key (lower bound) of theManagedObject.context- the optional context to look in. Anullvalue searches in all contexts.fireLookupEvents- iftruelookup 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 anUpdatableManagedObjectit 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
ManagedObjectinstance ornullif such an instance does not exists. - Since:
- 2.3
-
getManagedObject
public ManagedObject<?> getManagedObject(org.snmp4j.smi.OID key, org.snmp4j.smi.OctetString context)
Returns theManagedObjectwith the specifiedOIDas 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
MOServerLookupEvents fired on behalf of this method.- Parameters:
key- the OID identifying the key (lower bound) of theManagedObject.context- the optional context to look in. Anullvalue searches in all contexts.- Returns:
- the
ManagedObjectinstance ornullif 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 theManagedObjectValueAccessinterface. If aManagedObjectdoes not support this interface, its value cannot be returned andnullwill be returned instead. Note: This method does not perform any locking based on theMOLockStrategy.- Parameters:
server- theMOServerwhere to lookup the value.context- the optional context to look in. Anullvalue searches in all contexts.key- the OID identifying the variable instance to return.- Returns:
- the
Variableassociated withOIDandcontextinserverornullif 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 theManagedObjectValueAccessinterface. If aManagedObjectdoes not support this interface, its value cannot be set andfalsewill be returned. Note: This method does not perform any locking based on theMOLockStrategy.- Parameters:
server- theMOServerwhere to lookup the value.context- the optional context to look in. Anullvalue searches in all contexts.newValueAndKey- the OID identifying the variable instance to set and its new value.- Returns:
- the
trueif the value has been set successfully,falseotherwise. - Since:
- 1.4
-
fireLookupEvent
protected void fireLookupEvent(ManagedObject<?> mo, MOServerLookupEvent event)
-
fireQueryEvent
protected void fireQueryEvent(ManagedObject<?> mo, MOServerLookupEvent event)
-
getContexts
public org.snmp4j.smi.OctetString[] getContexts()
Description copied from interface:MOServerReturns the contexts known by the server.- Specified by:
getContextsin interfaceMOServer- Returns:
- an array of context names.
-
isContextSupported
public boolean isContextSupported(org.snmp4j.smi.OctetString context)
Description copied from interface:MOServerChecks whether the supplied context is supported (registered) by this server.- Specified by:
isContextSupportedin interfaceMOServer- Parameters:
context- a context name.- Returns:
trueif the context is support (thus has previously added byMOServer.addContext(org.snmp4j.smi.OctetString)) andfalseotherwise.
-
getRegistry
public SortedMap<MOScope,ManagedObject<?>> getRegistry()
-
getUpdateStrategy
public UpdateStrategy getUpdateStrategy()
Gets the update strategy forUpdatableManagedObjects. If the strategy isnullno updates will be performed on behalf of calls tolookup(org.snmp4j.agent.MOQuery).- Returns:
- the current UpdateStrategy instance or
nullif no strategy is active. - Since:
- 1.2
- See Also:
lookup(org.snmp4j.agent.MOQuery)
-
setUpdateStrategy
public void setUpdateStrategy(UpdateStrategy updateStrategy)
Sets the update strategy forUpdatableManagedObjects. If the strategy isnullno updates will be performed on behalf of calls tolookup(MOQuery).- Parameters:
updateStrategy- the new UpdateStrategy instance ornullif no updates should be performed.- Since:
- 1.2
- See Also:
lookup(MOQuery)
-
register
public void register(ManagedObject<?> mo, org.snmp4j.smi.OctetString context) throws DuplicateRegistrationException
Description copied from interface:MOServerRegisters a managed object for the specified context. A managed object can be registered for more than one context.- Specified by:
registerin interfaceMOServer- Parameters:
mo- aManagedObjectinstance.context- the context name for which to register themoornullif 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
public ManagedObject<?> unregister(ManagedObject<?> mo, org.snmp4j.smi.OctetString context)
Description copied from interface:MOServerRemoves the registration of the supplied managed object for the specified context.- Specified by:
unregisterin interfaceMOServer- Parameters:
mo- aManagedObjectinstance.context- the context name for which to unregister themoornullif 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
ManagedObjectinstance ornullif the removal failed.
-
addContext
public void addContext(org.snmp4j.smi.OctetString context)
Description copied from interface:MOServerAdds 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:
addContextin interfaceMOServer- Parameters:
context- anOctetStringrepresenting the context name to add.
-
removeContext
public void removeContext(org.snmp4j.smi.OctetString context)
Description copied from interface:MOServerRemoves a context from the server. Removing a context does not remove any managed objects from the server's registry.- Specified by:
removeContextin interfaceMOServer- Parameters:
context- nOctetStringrepresenting the context name to remove.
-
lock
public boolean lock(Object owner, ManagedObject<?> managedObject)
Description copied from interface:MOServerLocks 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
public boolean lock(Object owner, ManagedObject<?> managedObject, long timeoutMillis)
Description copied from interface:MOServerLocks 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:
lockin 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:
trueif the lock could be acquired,falseotherwise, i.e. if an InterruptedException or timeout has occurred.
-
unlock
public boolean unlock(Object owner, ManagedObject<?> managedObject)
Description copied from interface:MOServerUnlocks 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
public Iterator<Map.Entry<MOScope,ManagedObject<?>>> iterator()
Description copied from interface:MOServerReturn a read-onlyIteratorover 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:
iteratorin interfaceMOServer- Returns:
- the
Iteratoron the Map.Entry instances managed by this server. EachEntryconsists of anMOScopekey instance and a correspondingManagedObjectvalue instance. If theManagedObjecthas been registered for a specific context, then aMOContextScopeis returned as key, otherwise the managed objects ownMOScopeis returned.
-
addLookupListener
public void addLookupListener(MOServerLookupListener listener, ManagedObject<?> mo)
Description copied from interface:MOServerAdds a managed object lookup listener for the supplied managed object to this managed object server. AMOServerLookupListeneris called before the managed object is returned byMOServer.lookup(MOQuery query).- Specified by:
addLookupListenerin interfaceMOServer- Parameters:
listener- aMOServerLookupListenerinstance, for example a managed object that needs to update its state whenever it has been looked upmo- theManagedObjectthat triggers theMOServerLookupEventto be fired when it has been looked up.
-
removeLookupListener
public boolean removeLookupListener(MOServerLookupListener listener, ManagedObject<?> mo)
Description copied from interface:MOServerRemoves a managed object lookup listener for the specified managed object.- Specified by:
removeLookupListenerin interfaceMOServer- Parameters:
listener- aMOServerLookupListenerinstance.mo- theManagedObjectthat triggered theMOServerLookupEventto be fired when it has been looked up.- Returns:
trueif the listener could be removed orfalseif such a listener is not registered.
-
addContextListener
public void addContextListener(ContextListener l)
Description copied from interface:MOServerAdds a context listener to the server. The listener will be informed about context insertion and removal.- Specified by:
addContextListenerin interfaceMOServer- Parameters:
l- aContextListenerinstance to be informed about context changes.
-
removeContextListener
public void removeContextListener(ContextListener l)
Description copied from interface:MOServerRemoves a previously added context listener.- Specified by:
removeContextListenerin interfaceMOServer- Parameters:
l- aContextListenerinstance.
-
fireContextChanged
protected void fireContextChanged(ContextEvent event)
-
getRegisteredContexts
public org.snmp4j.smi.OctetString[] getRegisteredContexts(ManagedObject<?> managedObject)
Description copied from interface:MOServerReturns the contexts for which the suppliedManagedObjecthas been registered.- Specified by:
getRegisteredContextsin interfaceMOServer- Parameters:
managedObject- aManagedObjectinstance.- Returns:
- an array of context strings, for which
managedObjecthas been registered. If themanagedObjecthas been registered for all contexts, anullelement is included in the array.
-
registerTableRowListener
public static <R extends MOTableRow,T extends MOTable<R,? extends MOColumn,? extends MOTableModel<R>>> void registerTableRowListener(MOServer server, MOTableRowListener<R> listener)
Register a singleMOTableRowListenerwith all tables in the specifiedMOServer. This overall registration can be used, for example, to apply table size limits to all tables in an agent. SeeMOTableSizeLimitfor details.Note: The server must not change its registration content while this method is being called, otherwise a
ConcurrentModificationExceptionmight be thrown.- Type Parameters:
R- theMOTableRowtype supported by the table row listener to register.T- theMOTabletype supported by the table row listener to register.- Parameters:
server- aMOServerinstance.listener- theMOTableRowListenerinstance to register.- Since:
- 1.4
-
unregisterTableRowListener
public static <R extends MOTableRow,T extends MOTable<R,? extends MOColumn,? extends MOTableModel<R>>> void unregisterTableRowListener(MOServer server, MOTableRowListener<R> listener)
Unregister a singleMOTableRowListenerwith all tables in the specifiedMOServer. This overall unregistration can be used, for example, to remove table size limits from all tables in an agent. SeeMOTableSizeLimitfor details.Note: The server must not change its registration content while this method is being called, otherwise a
ConcurrentModificationExceptionmight be thrown.- Type Parameters:
R- theMOTableRowtype supported by the table row listener to register.T- theMOTabletype supported by the table row listener to register.- Parameters:
server- aMOServerinstance.listener- theMOTableRowListenerinstance to unregister.- Since:
- 1.4
-
registerChangeListener
public static void registerChangeListener(MOServer server, MOChangeListener listener, MOFilter moFilter)
Register a singleMOChangeListenerwith all objects matching the given filter in the specifiedMOServer. This overall registration can be used, for example, to listen for object changes.Note: The server must not change its registration content while this method is being called, otherwise a
ConcurrentModificationExceptionmight be thrown.- Parameters:
server- aMOServerinstance.listener- theMOTableRowListenerinstance to register.moFilter- an optional filter to select objects which should register the provided listener.- Since:
- 3.0
-
unregisterChangeListener
public static void unregisterChangeListener(MOServer server, MOChangeListener listener, MOFilter moFilter)
Unregister a singleMOChangeListenerfrom all objects matching the given filter in the specifiedMOServer.Note: The server must not change its registration content while this method is being called, otherwise a
ConcurrentModificationExceptionmight be thrown.- Parameters:
server- aMOServerinstance.listener- theMOTableRowListenerinstance to unregister.moFilter- an optional filter to select objects which should no longer register the provided listener.- Since:
- 3.0
-
-