org.friendlysnmp
Class AgentWorker

java.lang.Object
  extended by org.friendlysnmp.AgentWorker

public class AgentWorker
extends java.lang.Object

This class is an SNMP4J agent proxy. It initializes underlying SNMP4J agent and registers MIBs. A user could use this class directly or via (recommended) a friendly agent class FriendlyAgent which exposes minimal set of publicly available methods.

Version:
$Revision: 1.78 $
See Also:
FriendlyAgent

Nested Class Summary
static class AgentWorker.ExceptionType
          Enumeration of exception types
 
Constructor Summary
AgentWorker(java.lang.String appTitle, java.lang.String appVersion, java.util.Properties propApp)
          Constructor
 
Method Summary
protected  void addCommunities(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB communityMIB)
          Adds community to security name mappings needed for SNMPv1 and SNMPv2c.
 void addFExceptionListener(FExceptionListener l)
          Adds FExceptionListener
protected  void addNotificationTargets(org.snmp4j.agent.mo.snmp.SnmpTargetMIB targetMIB, org.snmp4j.agent.mo.snmp.SnmpNotificationMIB notificationMIB)
          Adds initial notification targets and filters.
protected  void addShutdownHook()
          Adds shutdown hook to intercept JVM shutdown event.
 void addShutdownListener(ShutdownListener l)
          Adds ShutdownListener
 void addTarget(TargetBase target)
          Adds TargetBase objects to the collection of targets without actual initialization of the added target.
 void addUncaughtExceptionListener(UncaughtExceptionListener l)
          Adds UncaughtExceptionListener
protected  void addUsmUser(org.snmp4j.security.USM usm)
          Adds all the necessary initial users to the USM.
protected  void addViews(org.snmp4j.agent.mo.snmp.VacmMIB vacmMIB)
          Adds initial VACM configuration.
 void exceptionThrown(FException e)
          Sends exception to all registered listeners in the application.
 void exceptionThrown(FTable table, FException e)
          Sends exception to the registered listeners in the application with a message that a problem is found while updating the table.
 void exceptionThrown(java.lang.String msg, FException e)
          Sends exception to the registered listener in the application
 org.snmp4j.agent.CommandProcessor getAgent()
          Returns agent: CommandProcessor object.
 FConfig getConfig()
          Returns configuration object
 int getIgnoreUpdateMs()
          Returns ignore updates interval (in milliseconds).
 FNode getNode(org.snmp4j.smi.OID oid)
           
 FNotification getNotification(org.snmp4j.smi.OID oid)
           
 PersistStorage getPersistStorage()
          Returns default persistence storage object.
 FScalar getScalar(org.snmp4j.smi.OID oid)
           
 org.snmp4j.agent.DefaultMOServer getServer()
          Returns server object.
 FID getSnmpEngineBootsFID()
          Returns FID of the snmpEngineBoots scalar.
 FTable getTable(org.snmp4j.smi.OID oid)
           
 TransportSnmp getTransport()
          Returns transport
 TransportDomain getTransportDomain()
          Returns transport domain
 void initAgent()
          This method performs all essential actions as org.snmp4j.agent.BaseAgent.init() does.
protected  void initMessageDispatcher()
          Initializes the message dispatcher (MessageDispatcherImpl) with the transport mappings.
protected  void initSecurityModels()
          Initializes security models.
protected  void initTransportMappings()
          Initializes the transport mappings (ports) to be used by the agent.
 boolean isRunning()
           
protected  void registerManagedObjects()
          Register managed objects in registered MIBs at the agent's server.
 void removeFExceptionListener(FExceptionListener l)
          Removes FExceptionListener
 void removeShutdownListener(ShutdownListener l)
          Removes ShutdownListener
 void removeUncaughtExceptionListener(UncaughtExceptionListener l)
          Removes UncaughtExceptionListener
 void reportException(java.lang.String comment, java.lang.Throwable e)
          Call this method to report a caught exception in the application to the MIB browser.
 void sendNotification(org.snmp4j.smi.OID oid, org.snmp4j.smi.VariableBinding[] vbs)
          Sends notification.
 void startAgent()
          Starts the agent.
 void stopAgent()
          Stops the agent by closing the SNMP session and associated transport mappings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AgentWorker

public AgentWorker(java.lang.String appTitle,
                   java.lang.String appVersion,
                   java.util.Properties propApp)
            throws FException
Constructor

Parameters:
appTitle - application title
appVersion - application version
propApp - properties
Throws:
FException
Method Detail

initAgent

public void initAgent()
               throws java.io.IOException,
                      FException
This method performs all essential actions as org.snmp4j.agent.BaseAgent.init() does.

Throws:
java.io.IOException - loading persistence or properties problem
org.snmp4j.agent.DuplicateRegistrationException - loading managed objects problem
FException - loading initial values and initialization

startAgent

public void startAgent()
                throws FException
Starts the agent.

Throws:
FException

stopAgent

public void stopAgent()
               throws FException
Stops the agent by closing the SNMP session and associated transport mappings.

Throws:
FException

isRunning

public boolean isRunning()

addShutdownHook

protected void addShutdownHook()
Adds shutdown hook to intercept JVM shutdown event.

See Also:
BaseAgent.addShutdownHook()

getSnmpEngineBootsFID

public FID getSnmpEngineBootsFID()
Returns FID of the snmpEngineBoots scalar.

Returns:
FID of the snmpEngineBoots scalar.

addUncaughtExceptionListener

public void addUncaughtExceptionListener(UncaughtExceptionListener l)
Adds UncaughtExceptionListener

Parameters:
l - UncaughtExceptionListener object

removeUncaughtExceptionListener

public void removeUncaughtExceptionListener(UncaughtExceptionListener l)
Removes UncaughtExceptionListener

Parameters:
l - UncaughtExceptionListener object

addFExceptionListener

public void addFExceptionListener(FExceptionListener l)
Adds FExceptionListener

Parameters:
l - FExceptionListener object

removeFExceptionListener

public void removeFExceptionListener(FExceptionListener l)
Removes FExceptionListener

Parameters:
l - FExceptionListener object

addShutdownListener

public void addShutdownListener(ShutdownListener l)
Adds ShutdownListener

Parameters:
l - ShutdownListener object

removeShutdownListener

public void removeShutdownListener(ShutdownListener l)
Removes ShutdownListener

Parameters:
l - ShutdownListener object

exceptionThrown

public void exceptionThrown(FException e)
Sends exception to all registered listeners in the application.

Parameters:
e - exception
See Also:
FExceptionListener

exceptionThrown

public void exceptionThrown(FTable table,
                            FException e)
Sends exception to the registered listeners in the application with a message that a problem is found while updating the table.

Parameters:
table - the table with the exception
e - exception

exceptionThrown

public void exceptionThrown(java.lang.String msg,
                            FException e)
Sends exception to the registered listener in the application

Parameters:
msg - message with details about the exception, or null
e - exception

sendNotification

public void sendNotification(org.snmp4j.smi.OID oid,
                             org.snmp4j.smi.VariableBinding[] vbs)
Sends notification. Normally this method is called from FNotification objects. Do not call this method directly.

Parameters:
oid -
vbs -
Throws:
FException

reportException

public void reportException(java.lang.String comment,
                            java.lang.Throwable e)
Call this method to report a caught exception in the application to the MIB browser.

Parameters:
comment - error message
e - exception

getIgnoreUpdateMs

public int getIgnoreUpdateMs()
Returns ignore updates interval (in milliseconds).

Returns:
ignore updates interval (in milliseconds).

getTransport

public TransportSnmp getTransport()
Returns transport

Returns:
transport

getTransportDomain

public TransportDomain getTransportDomain()
Returns transport domain

Returns:
transport domain

addTarget

public void addTarget(TargetBase target)
               throws FException
Adds TargetBase objects to the collection of targets without actual initialization of the added target.

Parameters:
target - target
Throws:
FException

getConfig

public FConfig getConfig()
Returns configuration object

Returns:
configuration object

getPersistStorage

public PersistStorage getPersistStorage()
Returns default persistence storage object.

Returns:
default persistence storage object

getNode

public FNode getNode(org.snmp4j.smi.OID oid)

getScalar

public FScalar getScalar(org.snmp4j.smi.OID oid)

getTable

public FTable getTable(org.snmp4j.smi.OID oid)

getNotification

public FNotification getNotification(org.snmp4j.smi.OID oid)

addCommunities

protected void addCommunities(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB communityMIB)
Adds community to security name mappings needed for SNMPv1 and SNMPv2c.

Parameters:
communityMIB - the SnmpCommunityMIB holding coexistence configuration for community based security models.
See Also:
BaseAgent.addCommunities(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB)

addViews

protected void addViews(org.snmp4j.agent.mo.snmp.VacmMIB vacmMIB)
Adds initial VACM configuration.

Parameters:
vacmMIB - the VacmMIB holding the agent's view configuration.
See Also:
BaseAgent.addViews(org.snmp4j.agent.mo.snmp.VacmMIB)

addUsmUser

protected void addUsmUser(org.snmp4j.security.USM usm)
Adds all the necessary initial users to the USM.

Parameters:
usm - the USM instance used by this agent.
See Also:
BaseAgent.addUsmUser(org.snmp4j.security.USM)

addNotificationTargets

protected void addNotificationTargets(org.snmp4j.agent.mo.snmp.SnmpTargetMIB targetMIB,
                                      org.snmp4j.agent.mo.snmp.SnmpNotificationMIB notificationMIB)
Adds initial notification targets and filters.

Parameters:
targetMIB - the SnmpTargetMIB holding the target configuration.
notificationMIB - the SnmpNotificationMIB holding the notification (filter) configuration.
See Also:
BaseAgent.addNotificationTargets(org.snmp4j.agent.mo.snmp.SnmpTargetMIB, org.snmp4j.agent.mo.snmp.SnmpNotificationMIB)

registerManagedObjects

protected void registerManagedObjects()
Register managed objects in registered MIBs at the agent's server.

See Also:
BaseAgent.registerManagedObjects()

initTransportMappings

protected void initTransportMappings()
                              throws java.io.IOException
Initializes the transport mappings (ports) to be used by the agent.

Throws:
java.io.IOException
See Also:
BaseAgent.initTransportMappings()

initSecurityModels

protected void initSecurityModels()
Initializes security models. See also: org.snmp4j.agent.AgentConfigManager#initSecurityModels()


initMessageDispatcher

protected void initMessageDispatcher()
Initializes the message dispatcher (MessageDispatcherImpl) with the transport mappings. See also: org.snmp4j.agent.AgentConfigManager#initMessageDispatcherWithMPs()


getAgent

public org.snmp4j.agent.CommandProcessor getAgent()
Returns agent: CommandProcessor object.

Returns:
agent.

getServer

public org.snmp4j.agent.DefaultMOServer getServer()
Returns server object.

Returns:
server.