org.snmp4j.agent
Interface MOServer

All Known Implementing Classes:
DefaultMOServer

public interface MOServer

The managed object server interface defines the services that a repository of managed objects needs to provide for a command responder.

Version:
1.4
Author:
Frank Fock

Method Summary
 void addContext(org.snmp4j.smi.OctetString context)
          Adds the supplied context to the server.
 void addContextListener(ContextListener listener)
          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.
 org.snmp4j.smi.OctetString[] getContexts()
          Returns the contexts known by the server.
 org.snmp4j.smi.OctetString[] getRegisteredContexts(ManagedObject managedObject)
          Returns the contexts for which the supplied ManagedObject has been registered.
 boolean isContextSupported(org.snmp4j.smi.OctetString context)
          Checks whether the supplied context is supported (registered) by this server.
 java.util.Iterator<java.util.Map.Entry<MOScope,ManagedObject>> iterator()
          Returns a read-only Iterator over the content of this server.
 boolean lock(java.lang.Object owner, ManagedObject managedObject)
          Locks a ManagedObject by the supplied owner.
 boolean lock(java.lang.Object owner, ManagedObject managedObject, long timeoutMillis)
          Locks a ManagedObject by the supplied owner.
 ManagedObject lookup(MOQuery query)
          Lookups 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.
 void removeContext(org.snmp4j.smi.OctetString context)
          Removes a context from the server.
 void removeContextListener(ContextListener listener)
          Removes a previously added context listener.
 boolean removeLookupListener(MOServerLookupListener listener, ManagedObject mo)
          Removes a managed object lookup listener for the specified managed object.
 void unlock(java.lang.Object owner, ManagedObject managedObject)
          Unlocks a ManagedObject that has been locked by the specified owner.
 void unregister(ManagedObject mo, org.snmp4j.smi.OctetString context)
          Removes the registration of the supplied managed object for the specified context.
 

Method Detail

addContextListener

void addContextListener(ContextListener listener)
Adds a context listener to the server. The listener will be informed about context insertion and removal.

Parameters:
listener - a ContextListener instance to be informed about context changes.

removeContextListener

void removeContextListener(ContextListener listener)
Removes a previously added context listener.

Parameters:
listener - a ContextListener instance.

addContext

void addContext(org.snmp4j.smi.OctetString context)
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).

Parameters:
context - an OctetString representing the context name to add.

removeContext

void removeContext(org.snmp4j.smi.OctetString context)
Removes a context from the server. Removing a context does not remove any managed objects from the server's registry.

Parameters:
context - n OctetString representing the context name to remove.

register

void register(ManagedObject mo,
              org.snmp4j.smi.OctetString context)
              throws DuplicateRegistrationException
Registers a managed object for the specified context. A managed object can be registered for more than one context.

Parameters:
mo - a ManagedObject instance.
context - the context name for which to register the mo or null 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

void unregister(ManagedObject mo,
                org.snmp4j.smi.OctetString context)
Removes the registration of the supplied managed object for the specified context.

Parameters:
mo - a ManagedObject instance.
context - the context name for which to unregister the mo or null if the managed oject 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!

addLookupListener

void addLookupListener(MOServerLookupListener listener,
                       ManagedObject mo)
Adds a managed object lookup listener for the supplied managed object to this managed object server. A MOServerLookupListener is called before the managed object is returned by lookup(MOQuery query).

Parameters:
listener - a MOServerLookupListener instance, for example a managed object that needs to update its state whenever it has been looked up
mo - the ManagedObject that triggers the MOServerLookupEvent to be fired when it has been looked up.

removeLookupListener

boolean removeLookupListener(MOServerLookupListener listener,
                             ManagedObject mo)
Removes a managed object lookup listener for the specified managed object.

Parameters:
listener - a MOServerLookupListener instance.
mo - the ManagedObject that triggered the MOServerLookupEvent to be fired when it has been looked up.
Returns:
true if the listener could be removed or false if such a listener is not registered.

lookup

ManagedObject lookup(MOQuery query)
Lookups the first (lexicographically ordered) managed object that matches the supplied query.

Parameters:
query - a MOQuery instance.
Returns:
the ManagedObject that matches the query and null if no such object exists.

iterator

java.util.Iterator<java.util.Map.Entry<MOScope,ManagedObject>> iterator()
Returns a read-only Iterator 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.

Returns:
the Iterator on the Map.Entry instances managed by this server. Each Entry consists of an MOScope key instance and a corresponding ManagedObject value instance. If the ManagedObject has been registered for a specific context, then a MOContextScope is returned as key, otherwise the managed objects own MOScope is returned.

lock

boolean lock(java.lang.Object owner,
             ManagedObject managedObject)
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.

Parameters:
owner - an Object.
managedObject - the ManagedObject to lock.
Returns:
true if the lock could be acquired, false otherwise, i.e. if an InterruptedException has occurred.

lock

boolean lock(java.lang.Object owner,
             ManagedObject managedObject,
             long timeoutMillis)
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.

Parameters:
owner - an Object.
managedObject - the ManagedObject to lock.
timeoutMillis - the number of 1/1000 seconds to wait for the lock.
Returns:
true if the lock could be acquired, false otherwise, i.e. if an InterruptedException or timeout has occurred.
Since:
1.3

unlock

void unlock(java.lang.Object owner,
            ManagedObject managedObject)
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.

Parameters:
owner - an Object.
managedObject - the ManagedObject to unlock.

getContexts

org.snmp4j.smi.OctetString[] getContexts()
Returns the contexts known by the server.

Returns:
an array of context names.

isContextSupported

boolean isContextSupported(org.snmp4j.smi.OctetString context)
Checks whether the supplied context is supported (registered) by this server.

Parameters:
context - a context name.
Returns:
true if the context is support (thus has previously added by addContext(org.snmp4j.smi.OctetString)) and false otherwise.

getRegisteredContexts

org.snmp4j.smi.OctetString[] getRegisteredContexts(ManagedObject managedObject)
Returns the contexts for which the supplied ManagedObject has been registered.

Parameters:
managedObject - a ManagedObject instance.
Returns:
an array of context strings, for which managedObject has been registered. If the managedObject has bee registered for all contexts, a null element is included in the array.
Since:
1.4

Copyright 2005-2010 Frank Fock (SNMP4J.org)

Copyright © 2011 SNMP4J.org. All Rights Reserved.