Package org.snmp4j.agent.agentx.subagent
Class SubagentXConfigManager
java.lang.Object
org.snmp4j.agent.agentx.subagent.SubagentXConfigManager
- All Implemented Interfaces:
Runnable
,org.snmp4j.agent.mo.util.VariableProvider
public abstract class SubagentXConfigManager
extends Object
implements Runnable, org.snmp4j.agent.mo.util.VariableProvider
The
SubagentXConfigManager
is the main component of a SNMP4J AgentX Subagent.
It puts together agent configuration and agent components like command
processor, message dispatcher, managed objects and server.- Since:
- 3.0.0
- Version:
- 3.0.0
- Author:
- Frank Fock
-
Nested Class Summary
Modifier and TypeClassDescriptionclass
static class
-
Field Summary
Modifier and TypeFieldDescriptionprotected AgentXCommandListener
protected List
<org.snmp4j.agent.AgentStateListener<SubagentXConfigManager>> protected org.snmp4j.agent.io.MOInputFactory
protected org.snmp4j.smi.OctetString
protected AgentXMessageDispatcher
protected org.snmp4j.agent.mo.MOFactory
protected org.snmp4j.agent.NotificationOriginator
protected int
protected org.snmp4j.agent.io.MOPersistenceProvider
protected org.snmp4j.agent.mo.MOPriorityProvider
protected SubagentXConfigManager.AgentState
protected org.snmp4j.agent.MOServer[]
protected org.snmp4j.agent.mo.util.MOTableSizeLimit
<org.snmp4j.agent.mo.MOTableRow> protected org.snmp4j.util.WorkerPool
-
Constructor Summary
ConstructorDescriptionSubagentXConfigManager
(AgentXCommandListener agentXCommandListener, AgentXMessageDispatcher messageDispatcher, org.snmp4j.agent.MOServer[] moServers, org.snmp4j.util.WorkerPool workerPool, org.snmp4j.agent.io.MOInputFactory configurationFactory, org.snmp4j.agent.io.MOPersistenceProvider persistenceProvider, org.snmp4j.agent.mo.MOFactory moFactory) Creates a SNMP agent configuration which can be run by callingrun()
later. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAgentStateListener
(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) void
Configures components and managed objects.boolean
Continues processing of SNMP requests by coupling message dispatcher and agent.protected void
protected void
Fire notifications after agent start, i.e.protected org.snmp4j.smi.OctetString
getContext
(org.snmp4j.agent.MOGroup mibGroup, org.snmp4j.smi.OctetString defaultContext) This method can be overwritten by a subagent to specify the contexts each MIB module (group) will be registered to.org.snmp4j.smi.OctetString
Returns the default context - which is the context that is used by the base agent to register its MIB objects.int
Returns the currently active import mode for theMOPersistenceProvider
.org.snmp4j.agent.mo.MOPriorityProvider
Gets the priority provider defining the order of storing and restoring persistent data.org.snmp4j.agent.MOServer
getServer
(org.snmp4j.smi.OctetString context) Get theMOServer
associated with the given context.org.snmp4j.agent.MOServer[]
org.snmp4j.agent.AgentState
getState()
Returns the state of the agent.org.snmp4j.smi.Variable
getVariable
(String name) org.snmp4j.util.WorkerPool
Gets the worker pool of this agent.void
Initialize the agent by registering all MIB modules.protected void
launch()
Launch the agent by registering and launching (i.e., set to listen mode) transport mappings.abstract void
Establish AgentX connection to one or more AgentX master agents by implementing this method.protected void
Launch the transport mappings.protected static void
launchTransportMappings
(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) Puts a list of transport mappings into listen mode.protected void
Hook method for overriding in sub-classes that is called byinitialize()
beforeregisterMIBs(OctetString)
.protected void
registerMIBs
(org.snmp4j.smi.OctetString context) Register the initialized MIB modules in the specified context of the agent.void
Registers a shutdown hookThread
at theRuntime
instance.boolean
removeAgentStateListener
(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) boolean
Restore a previously persistently saved state - if available.void
run()
Initializes, configures, restores agent state, and then launches the SNMP agent depending on its current run state.boolean
Save the state of the agent persistently - if necessary persistent storage is available.void
setPersistenceImportMode
(int importMode) Sets the import mode for theMOPersistenceProvider
.void
setPriorityProvider
(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Sets theMOPriorityProvider
that defines in which orderManagedObject
s of this sub-agent are stored and restored.void
setTableSizeLimit
(int sizeLimit) Sets the table size limit for the tables in this agent.void
setTableSizeLimits
(Properties sizeLimits) Sets the table size limits for the tables in this agent.void
shutdown()
Shutdown the agent by closing the internal SNMP session - including the transport mappings provided through the configuredMessageDispatcher
and then store the agent state to persistent storage (if available).protected static void
stopTransportMappings
(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) Closes a list of transport mappings.void
Suspends processing of SNMP requests.protected void
unregisterMIBs
(org.snmp4j.smi.OctetString context) Unregister the initialized MIB modules from the default context of the agent.
-
Field Details
-
agent
-
workerPool
protected org.snmp4j.util.WorkerPool workerPool -
servers
protected org.snmp4j.agent.MOServer[] servers -
dispatcher
-
notificationOriginator
protected org.snmp4j.agent.NotificationOriginator notificationOriginator -
configuration
protected org.snmp4j.agent.io.MOInputFactory configuration -
persistenceProvider
protected org.snmp4j.agent.io.MOPersistenceProvider persistenceProvider -
persistenceImportMode
protected int persistenceImportMode -
priorityProvider
protected org.snmp4j.agent.mo.MOPriorityProvider priorityProvider -
moFactory
protected org.snmp4j.agent.mo.MOFactory moFactory -
defaultContext
protected org.snmp4j.smi.OctetString defaultContext -
runState
-
tableSizeLimit
protected org.snmp4j.agent.mo.util.MOTableSizeLimit<org.snmp4j.agent.mo.MOTableRow> tableSizeLimit -
agentStateListeners
-
-
Constructor Details
-
SubagentXConfigManager
public SubagentXConfigManager(AgentXCommandListener agentXCommandListener, AgentXMessageDispatcher messageDispatcher, org.snmp4j.agent.MOServer[] moServers, org.snmp4j.util.WorkerPool workerPool, org.snmp4j.agent.io.MOInputFactory configurationFactory, org.snmp4j.agent.io.MOPersistenceProvider persistenceProvider, org.snmp4j.agent.mo.MOFactory moFactory) Creates a SNMP agent configuration which can be run by callingrun()
later.- Parameters:
agentXCommandListener
- theAgentXCommandListener
that handles the AgentX packages and that is able to close allAgentXSession
s.messageDispatcher
- the MessageDispatcher to use. The message dispatcher must be configured outside, i.e. transport mappings have to be added before this constructor is being called.moServers
- the managed object server(s) that serve the managed objects available to this agent.workerPool
- theWorkerPool
to be used to process incoming request.configurationFactory
- aMOInputFactory
that creates aMOInput
stream with containing serialized ManagedObject information with the agent's configuration ornull
otherwise.persistenceProvider
- the primaryMOPersistenceProvider
to be used to load and store persistent MOs.moFactory
- theMOFactory
to be used to createManagedObject
s created by this config manager. Ifnull
theDefaultMOFactory
will be used.
-
-
Method Details
-
getWorkerPool
public org.snmp4j.util.WorkerPool getWorkerPool()Gets the worker pool of this agent.- Returns:
- the internal worker pool.
-
run
public void run()Initializes, configures, restores agent state, and then launches the SNMP agent depending on its current run state. For example, ifinitialize()
has not yet been called it will be called before the agent is being configured in the next step.See also
initialize()
,configure()
,restoreState()
, andlaunch()
. -
addAgentStateListener
public void addAgentStateListener(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) -
removeAgentStateListener
public boolean removeAgentStateListener(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) -
fireAgentStateChange
protected void fireAgentStateChange() -
getServer
public org.snmp4j.agent.MOServer getServer(org.snmp4j.smi.OctetString context) Get theMOServer
associated with the given context.- Parameters:
context
- a SNMPv3 context ornull
(or emptyOctetString
) for the default context.- Returns:
- the associated
MOServer
for the context that acutally also supports the context ornull
otherwise.
-
getServers
public org.snmp4j.agent.MOServer[] getServers() -
getState
public org.snmp4j.agent.AgentState getState()Returns the state of the agent.- Returns:
- a
AgentState
instance.
-
launch
protected void launch()Launch the agent by registering and launching (i.e., set to listen mode) transport mappings. -
launchAgentXSessions
Establish AgentX connection to one or more AgentX master agents by implementing this method.- Throws:
IOException
- if the session(s) cannot be established due to IO error and the agent should not advance to the stateAgentState.STATE_RUNNING
.
-
fireLaunchNotifications
protected void fireLaunchNotifications()Fire notifications after agent start, i.e. sending a coldStart trap. -
continueProcessing
public boolean continueProcessing()Continues processing of SNMP requests by coupling message dispatcher and agent. To succeed, the current state of the agent must beAgentState.STATE_SUSPENDED
.- Returns:
true
if the running state could be restored,false
otherwise.
-
suspendProcessing
public void suspendProcessing()Suspends processing of SNMP requests. This call decouples message dispatcher and agent. All transport mappings remain unchanged and thus all ports remain opened. -
shutdown
public void shutdown()Shutdown the agent by closing the internal SNMP session - including the transport mappings provided through the configuredMessageDispatcher
and then store the agent state to persistent storage (if available). -
registerShutdownHook
public void registerShutdownHook()Registers a shutdown hookThread
at theRuntime
instance. -
launchTransportMappings
Launch the transport mappings. By defaultlaunchTransportMappings(Collection)
is called with the transport mappings of the dispatcher.- Throws:
IOException
- if a transport mapping throws anIOException
ofTransportMapping.listen()
.
-
launchTransportMappings
protected static void launchTransportMappings(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) throws IOException Puts a list of transport mappings into listen mode.- Parameters:
transportMappings
- a list ofTransportMapping
instances.- Throws:
IOException
- if a transport cannot listen to incoming messages.
-
stopTransportMappings
protected static void stopTransportMappings(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) throws IOException Closes a list of transport mappings.- Parameters:
transportMappings
- a list ofTransportMapping
instances.- Throws:
IOException
- if a transport cannot be closed.
-
saveState
public boolean saveState()Save the state of the agent persistently - if necessary persistent storage is available.- Returns:
true
if state has been saved successfully,false
is returned if an error occurred or nopersistenceProvider
is set. The error details can be found in therunState
object.
-
restoreState
public boolean restoreState()Restore a previously persistently saved state - if available.- Returns:
true
if the agent state could be restored successfully,false
otherwise.
-
configure
public void configure()Configures components and managed objects. -
linkCounterListener
protected void linkCounterListener()Hook method for overriding in sub-classes that is called byinitialize()
beforeregisterMIBs(OctetString)
. This method does nothing by default. -
initialize
public void initialize()Initialize the agent by registering all MIB modules. -
setTableSizeLimits
Sets the table size limits for the tables in this agent. If this method is called while the agent's registration is being changed, aConcurrentModificationException
might be thrown.- Parameters:
sizeLimits
- a set of properties as defined byMOTableSizeLimit
.- Since:
- 1.4
-
setTableSizeLimit
public void setTableSizeLimit(int sizeLimit) Sets the table size limit for the tables in this agent. If this method is called while the agent's registration is being changed, aConcurrentModificationException
might be thrown.- Parameters:
sizeLimit
- the maximum size (numer of rows) of tables allowed for this agent.- Since:
- 1.4
-
getDefaultContext
public org.snmp4j.smi.OctetString getDefaultContext()Returns the default context - which is the context that is used by the base agent to register its MIB objects. By default it isnull
which causes the objects to be registered virtually for all contexts. In that case, subagents for example my not register their own objects under the same subtree(s) in any context. To allow subagents to register their own instances of those MIB modules, an emptyOctetString
should be used as default context instead.- Returns:
null
or anOctetString
(normally the empty string) denoting the context used for registering default MIBs.
-
getContext
protected org.snmp4j.smi.OctetString getContext(org.snmp4j.agent.MOGroup mibGroup, org.snmp4j.smi.OctetString defaultContext) This method can be overwritten by a subagent to specify the contexts each MIB module (group) will be registered to.- Parameters:
mibGroup
- a group ofManagedObject
s (i.e., a MIB module).defaultContext
- the context to be used by default (i.e., thenull
context)- Returns:
- the context for which the module should be registered.
-
registerMIBs
protected void registerMIBs(org.snmp4j.smi.OctetString context) throws org.snmp4j.agent.DuplicateRegistrationException Register the initialized MIB modules in the specified context of the agent.- Parameters:
context
- the context to register the internal MIB modules. This should benull
by default.- Throws:
org.snmp4j.agent.DuplicateRegistrationException
- if some of the MIB modules registration regions conflict with already registered regions.
-
unregisterMIBs
protected void unregisterMIBs(org.snmp4j.smi.OctetString context) Unregister the initialized MIB modules from the default context of the agent.- Parameters:
context
- the context where the MIB modules have been previously registered.
-
getPriorityProvider
public org.snmp4j.agent.mo.MOPriorityProvider getPriorityProvider()Gets the priority provider defining the order of storing and restoring persistent data.- Returns:
- a
MOPriorityProvider
instance.
-
setPriorityProvider
public void setPriorityProvider(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Sets theMOPriorityProvider
that defines in which orderManagedObject
s of this sub-agent are stored and restored. A defined order can be important for initializing dependent objects and to avoid security issues during restore operations.- Parameters:
priorityProvider
- aMOPriorityProvider
ornull
if the default lexicographic order by OID should be applied.- Since:
- 3.5.0
-
setPersistenceImportMode
public void setPersistenceImportMode(int importMode) Sets the import mode for theMOPersistenceProvider
.- Parameters:
importMode
- one of the import modes defined byImportMode
.
-
getPersistenceImportMode
public int getPersistenceImportMode()Returns the currently active import mode for theMOPersistenceProvider
.- Returns:
- one of the import modes defined by
ImportMode
.
-
getVariable
- Specified by:
getVariable
in interfaceorg.snmp4j.agent.mo.util.VariableProvider
-