public class FriendlyAgent
extends java.lang.Object
FriendlyAgent agentSNMP = new FriendlyAgent(TITLE, VERSION, prop); // Optional UncaughtExceptionListener agentSNMP.addUncaughtExceptionListener(new UncaughtExceptionListener() { public void uncaughtException(Thread t, Throwable e) { [process uncaught exception] } }); agentSNMP.initAgent(); agentSNMP.start();
There is no need to shutdown or close the SNMP agent. It catches JVM shutdown event and closes SNMP connections and agent threads.
Constructor and Description |
---|
FriendlyAgent(java.lang.String title,
java.lang.String version,
java.util.Properties prop)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFExceptionListener(FExceptionListener l)
Adds
FExceptionListener |
void |
addMIB(BaseMib mib)
Method to add user defined MIB to the agent.
|
void |
addShutdownListener(ShutdownListener l)
Adds
ShutdownListener |
void |
addTarget(TargetBase target)
Adds targets
TargetBase to the agent. |
void |
addUncaughtExceptionListener(UncaughtExceptionListener l)
Adds
UncaughtExceptionListener |
FNode |
getNode(org.snmp4j.smi.OID oid)
Returns node registered in one of agent's mib
|
FNotification |
getNotification(org.snmp4j.smi.OID oid)
Returns notification registered in one of agent's mib.
|
PersistStorage |
getPersistStorage()
Returns persistence storage.
|
FScalar |
getScalar(org.snmp4j.smi.OID oid)
Returns scalar registered in one of agent's mib
|
FTable |
getTable(org.snmp4j.smi.OID oid)
Returns table registered in one of agent's mib
|
void |
init()
Initializes SNMP agent.
|
boolean |
isRunning()
Returns state of the SNMP agent.
|
static java.util.Properties |
loadProps(java.lang.Class<?> clazz,
java.lang.String filename)
Helper method to load properties file.
|
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)
Use this method to report caught exception to MIB browser via SNMP.
|
void |
setPersistStorage(PersistStorage persistStorage)
Sets persistence storage.
|
void |
shutdown()
Shutdowns SNMP agent.
|
void |
start()
Starts SNMP agent.
|
void |
stop()
Stops SNMP agent.
|
public FriendlyAgent(java.lang.String title, java.lang.String version, java.util.Properties prop) throws FException
title
- application title.version
- application version.prop
- properties to initialize agent and with other.
application information.FException
- failure to create agent.public void addUncaughtExceptionListener(UncaughtExceptionListener l)
UncaughtExceptionListener
l
- UncaughtExceptionListener
objectpublic void removeUncaughtExceptionListener(UncaughtExceptionListener l)
UncaughtExceptionListener
l
- UncaughtExceptionListener
objectpublic void addFExceptionListener(FExceptionListener l)
FExceptionListener
l
- FExceptionListener
objectpublic void removeFExceptionListener(FExceptionListener l)
FExceptionListener
l
- FExceptionListener
objectpublic void addShutdownListener(ShutdownListener l)
ShutdownListener
l
- ShutdownListener
objectpublic void removeShutdownListener(ShutdownListener l)
ShutdownListener
l
- ShutdownListener
objectpublic void addMIB(BaseMib mib) throws FException
mib
- MIB object.FException
- failure to add MIB.public void addTarget(TargetBase target) throws FException
TargetBase
to the agent.
Usually targets are added via properties file,
see FConstant.KEY_V1_COMMUNITY
,
FConstant.KEY_V2_COMMUNITY
and FConstant.KEY_V3_USER
,
Alternative technique is to derive class from
TargetBase
class, implement required functionality and
add target with this method.
target
- target object.FException
- failure to add target.public void init() throws FException
start()
)FException
- wrapper exception with a cause exception which
may be IOException while loading persistence or properties problem,
DuplicateRegistrationException while loading managed objects,
BindException if address is already in use, FException for
loading initial values and initialization.public void start() throws FException
FException
- failure to start agent.public void stop() throws FException
FException
- failure to stop agent.public boolean isRunning()
public void shutdown()
public FNode getNode(org.snmp4j.smi.OID oid)
oid
- node OIDpublic FScalar getScalar(org.snmp4j.smi.OID oid)
oid
- node OIDpublic FTable getTable(org.snmp4j.smi.OID oid)
oid
- node OIDpublic FNotification getNotification(org.snmp4j.smi.OID oid)
oid
- node OID.public void setPersistStorage(PersistStorage persistStorage) throws FException
persistStorage
- persistence storage.FException
- failure to set persistence storage.public PersistStorage getPersistStorage()
public void reportException(java.lang.String comment, java.lang.Throwable e)
comment
- error message (empty or null)e
- exceptionpublic static java.util.Properties loadProps(java.lang.Class<?> clazz, java.lang.String filename) throws java.io.IOException
clazz
- use this class classloader to load properties.filename
- properties file name.java.io.IOException
- failure to load properties file.