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
Nested ClassesModifier and TypeClassDescriptionclassstatic class -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AgentXCommandListenerprotected List<org.snmp4j.agent.AgentStateListener<SubagentXConfigManager>> protected org.snmp4j.agent.io.MOInputFactoryprotected org.snmp4j.smi.OctetStringprotected AgentXMessageDispatcherprotected org.snmp4j.agent.mo.MOFactoryprotected org.snmp4j.agent.NotificationOriginatorprotected intprotected org.snmp4j.agent.io.MOPersistenceProviderprotected org.snmp4j.agent.mo.MOPriorityProviderprotected SubagentXConfigManager.AgentStateprotected org.snmp4j.agent.MOServer[]protected org.snmp4j.agent.mo.util.MOTableSizeLimit<org.snmp4j.agent.mo.MOTableRow> protected org.snmp4j.util.WorkerPool -
Constructor Summary
ConstructorsConstructorDescriptionSubagentXConfigManager(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 TypeMethodDescriptionvoidaddAgentStateListener(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) voidConfigures components and managed objects.booleanContinues processing of SNMP requests by coupling message dispatcher and agent.protected voidprotected voidFire notifications after agent start, i.e.protected org.snmp4j.smi.OctetStringgetContext(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.OctetStringReturns the default context - which is the context that is used by the base agent to register its MIB objects.intReturns the currently active import mode for theMOPersistenceProvider.org.snmp4j.agent.mo.MOPriorityProviderGets the priority provider defining the order of storing and restoring persistent data.org.snmp4j.agent.MOServergetServer(org.snmp4j.smi.OctetString context) Get theMOServerassociated with the given context.org.snmp4j.agent.MOServer[]org.snmp4j.agent.AgentStategetState()Returns the state of the agent.org.snmp4j.smi.VariablegetVariable(String name) org.snmp4j.util.WorkerPoolGets the worker pool of this agent.voidInitialize the agent by registering all MIB modules.protected voidlaunch()Launch the agent by registering and launching (i.e., set to listen mode) transport mappings.abstract voidEstablish AgentX connection to one or more AgentX master agents by implementing this method.protected voidLaunch the transport mappings.protected static voidlaunchTransportMappings(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) Puts a list of transport mappings into listen mode.protected voidHook method for overriding in sub-classes that is called byinitialize()beforeregisterMIBs(OctetString).protected voidregisterMIBs(org.snmp4j.smi.OctetString context) Register the initialized MIB modules in the specified context of the agent.voidRegisters a shutdown hookThreadat theRuntimeinstance.booleanremoveAgentStateListener(org.snmp4j.agent.AgentStateListener<SubagentXConfigManager> agentStateListener) booleanRestore a previously persistently saved state - if available.voidrun()Initializes, configures, restores agent state, and then launches the SNMP agent depending on its current run state.booleanSave the state of the agent persistently - if necessary persistent storage is available.voidsetPersistenceImportMode(int importMode) Sets the import mode for theMOPersistenceProvider.voidsetPriorityProvider(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Sets theMOPriorityProviderthat defines in which orderManagedObjects of this sub-agent are stored and restored.voidsetTableSizeLimit(int sizeLimit) Sets the table size limit for the tables in this agent.voidsetTableSizeLimits(Properties sizeLimits) Sets the table size limits for the tables in this agent.voidshutdown()Shutdown the agent by closing the internal SNMP session - including the transport mappings provided through the configuredMessageDispatcherand then store the agent state to persistent storage (if available).protected static voidstopTransportMappings(Collection<? extends org.snmp4j.TransportMapping<?>> transportMappings) Closes a list of transport mappings.voidSuspends processing of SNMP requests.protected voidunregisterMIBs(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- theAgentXCommandListenerthat handles the AgentX packages and that is able to close allAgentXSessions.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- theWorkerPoolto be used to process incoming request.configurationFactory- aMOInputFactorythat creates aMOInputstream with containing serialized ManagedObject information with the agent's configuration ornullotherwise.persistenceProvider- the primaryMOPersistenceProviderto be used to load and store persistent MOs.moFactory- theMOFactoryto be used to createManagedObjects created by this config manager. IfnulltheDefaultMOFactorywill 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 theMOServerassociated with the given context.- Parameters:
context- a SNMPv3 context ornull(or emptyOctetString) for the default context.- Returns:
- the associated
MOServerfor the context that acutally also supports the context ornullotherwise.
-
getServers
public org.snmp4j.agent.MOServer[] getServers() -
getState
public org.snmp4j.agent.AgentState getState()Returns the state of the agent.- Returns:
- a
AgentStateinstance.
-
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:
trueif the running state could be restored,falseotherwise.
-
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 configuredMessageDispatcherand then store the agent state to persistent storage (if available). -
registerShutdownHook
public void registerShutdownHook()Registers a shutdown hookThreadat theRuntimeinstance. -
launchTransportMappings
Launch the transport mappings. By defaultlaunchTransportMappings(Collection)is called with the transport mappings of the dispatcher.- Throws:
IOException- if a transport mapping throws anIOExceptionofTransportMapping.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 ofTransportMappinginstances.- 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 ofTransportMappinginstances.- 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:
trueif state has been saved successfully,falseis returned if an error occurred or nopersistenceProvideris set. The error details can be found in therunStateobject.
-
restoreState
public boolean restoreState()Restore a previously persistently saved state - if available.- Returns:
trueif the agent state could be restored successfully,falseotherwise.
-
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, aConcurrentModificationExceptionmight 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, aConcurrentModificationExceptionmight 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 isnullwhich 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 emptyOctetStringshould be used as default context instead.- Returns:
nullor 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 ofManagedObjects (i.e., a MIB module).defaultContext- the context to be used by default (i.e., thenullcontext)- 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 benullby 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
MOPriorityProviderinstance.
-
setPriorityProvider
public void setPriorityProvider(org.snmp4j.agent.mo.MOPriorityProvider priorityProvider) Sets theMOPriorityProviderthat defines in which orderManagedObjects 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- aMOPriorityProviderornullif 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:
getVariablein interfaceorg.snmp4j.agent.mo.util.VariableProvider
-