Package org.snmp4j.agent.agentx.subagent
Class AgentXSharedMOTableSupport<R extends org.snmp4j.agent.mo.MOTableRow,A extends org.snmp4j.smi.Address>
java.lang.Object
org.snmp4j.agent.agentx.subagent.AgentXSharedMOTableSupport<R,A>
- All Implemented Interfaces:
EventListener,org.snmp4j.agent.mo.MOTableRowListener<R>
public class AgentXSharedMOTableSupport<R extends org.snmp4j.agent.mo.MOTableRow,A extends org.snmp4j.smi.Address>
extends Object
implements org.snmp4j.agent.mo.MOTableRowListener<R>
The
AgentXSharedMOTableSupport provides helper functions for shared table implementations to register
rows and indexes at a master agent.- Version:
- 2.2
- Author:
- Frank Fock
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumAgentXSharedMOTableSupport.IndexStrategyspecifies how index values are generated. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intAllocate a specified index.static final intAllocate any (new or used) index and return it.static final intAllocate and return a new index (never used before).protected SubAgentXIndexRegistryThe index sub-agent registry. -
Constructor Summary
ConstructorsConstructorDescriptionAgentXSharedMOTableSupport(AgentX agentX, AgentXSession<A> session, org.snmp4j.smi.OctetString context) Creates a shared table support object for a AgentX connection, session, and context.AgentXSharedMOTableSupport(AgentX agentX, AgentXSession<A> session, org.snmp4j.smi.OctetString context, byte priority, byte indexAllocationMode) Creates a shared table support object for a AgentX connection, session, and context. -
Method Summary
Modifier and TypeMethodDescriptionintallocateIndex(org.snmp4j.smi.OctetString context, org.snmp4j.agent.mo.MOTableIndex indexDef, byte indexAllocationMode, org.snmp4j.smi.OID allocatedIndex) Allocate a new or any index at the master agent and return its value inallocateIndex.intdeallocateIndex(org.snmp4j.smi.OctetString context, org.snmp4j.agent.mo.MOTableIndex indexDef, org.snmp4j.smi.OID allocatedIndex) Deallocate an index at the master agent.Gets theAgentXprotocol.org.snmp4j.smi.OctetStringGets the context.protected bytegetEffectiveIndexMode(org.snmp4j.agent.mo.MOTableRowEvent<R> event) Gets the effective index allocation mode for a table event.protected bytegetEffectivePriority(org.snmp4j.agent.mo.MOTableRowEvent<R> event) Gets the effective priority for a table event.byteGets the index mode.Gets the index strategy of this shared table support.byteGets the priority for the region registrations made by this table support.Gets the AgentX session used by this shared table support object.protected inthandleIndexAllocationError(org.snmp4j.agent.mo.MOTableIndex indexDef, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID allocatedIndex, AgentXResponsePDU resp) Handle an index allocation error.intregisterRow(org.snmp4j.agent.mo.MOTable<?, ?, ?> table, R row2Register) Register a row at the master.intregisterRow(org.snmp4j.agent.mo.MOTable<?, ?, ?> table, R row2Register, byte priority) Register the necessary regions for a table row.voidrowChanged(org.snmp4j.agent.mo.MOTableRowEvent<R> event) Process shared table row events.voidsetContext(org.snmp4j.smi.OctetString context) voidsetIndexMode(byte indexMode) Sets the index mode to be used by this shared table support object.voidsetIndexStrategy(AgentXSharedMOTableSupport.IndexStrategy indexStrategy) Sets the index strategy for this shared table support.voidsetPriority(byte priority) Sets the priority for the region registrations made by this table support.voidsetSession(AgentXSession<A> session) Sets the AgentX session to be used for this shared table support.intunregisterRow(org.snmp4j.agent.mo.MOTable<?, ?, ?> table, R row2Unregister) Removes the region registration of a table row.intunregisterRow(org.snmp4j.agent.mo.MOTable<?, ?, ?> table, R row2Unregister, byte priority) Removes the region registration of a table row.
-
Field Details
-
INDEX_MODE_ALLOCATE
public static final int INDEX_MODE_ALLOCATEAllocate a specified index.- See Also:
-
INDEX_MODE_ANY_INDEX
public static final int INDEX_MODE_ANY_INDEXAllocate any (new or used) index and return it.- See Also:
-
INDEX_MODE_NEW_INDEX
public static final int INDEX_MODE_NEW_INDEXAllocate and return a new index (never used before).- See Also:
-
indexRegistry
The index sub-agent registry.
-
-
Constructor Details
-
AgentXSharedMOTableSupport
public AgentXSharedMOTableSupport(AgentX agentX, AgentXSession<A> session, org.snmp4j.smi.OctetString context) Creates a shared table support object for a AgentX connection, session, and context.- Parameters:
agentX- an AgentX connection.session- an AgentXSession session (does not need to be open at creation time).context- a context ("" by default).
-
AgentXSharedMOTableSupport
public AgentXSharedMOTableSupport(AgentX agentX, AgentXSession<A> session, org.snmp4j.smi.OctetString context, byte priority, byte indexAllocationMode) Creates a shared table support object for a AgentX connection, session, and context.- Parameters:
agentX- an AgentX connection.session- an AgentXSession session (does not need to be open at creation time).context- a context ("" by default).priority- the registration priority used for this shared table support.indexAllocationMode- the index allocation mode to be used as default for this shared table.
-
-
Method Details
-
rowChanged
Process shared table row events. If index mode isINDEX_MODE_ALLOCATEthis method will do nothing if the associated AgentX session is closed. For other index modes, the event's veto status will be set to the AgentX errorAgentXProtocol.AGENTX_NOT_OPEN.If the index OID of a created row has zero length then, depending on the current index mode, a new or any new index is allocated at the master agent.
- Specified by:
rowChangedin interfaceorg.snmp4j.agent.mo.MOTableRowListener<R extends org.snmp4j.agent.mo.MOTableRow>- Parameters:
event- aMOTableRowEventindicating a row change in an AgentX shared table.
-
getEffectiveIndexMode
Gets the effective index allocation mode for a table event.- Parameters:
event- the table event with the reference to the shared table.- Returns:
INDEX_MODE_ALLOCATE,INDEX_MODE_ANY_INDEX, andINDEX_MODE_NEW_INDEX.
-
getEffectivePriority
Gets the effective priority for a table event.- Parameters:
event- the table event with the reference to the shared table.- Returns:
- the effective priority.
-
allocateIndex
public int allocateIndex(org.snmp4j.smi.OctetString context, org.snmp4j.agent.mo.MOTableIndex indexDef, byte indexAllocationMode, org.snmp4j.smi.OID allocatedIndex) Allocate a new or any index at the master agent and return its value inallocateIndex. For the index strategiesAgentXSharedMOTableSupport.IndexStrategy.firstSubIndexOnlyandAgentXSharedMOTableSupport.IndexStrategy.anyNonAllocatedSubIndexa local index registry maintains a reference to all allocated index values. If an allocation fails, the index value is removed from the registry.- Parameters:
context- the context for which to allocate the index. Specify an emptyOctetStringfor the default context.indexDef- the index definition with OID values for sub-index definitions.indexAllocationMode- one ofAgentXProtocol.FLAG_ANY_INDEX,AgentXProtocol.FLAG_NEW_INDEX, or 0 (if index value is supplied byallocateIndex).allocatedIndex- the index value to allocate or ifindexAllocationModeis not zero then an (arbitrary non-null OID) which returns the allocated new index value. IfallocateIndexis an instance ofAnyNewIndexOIDorNewIndexOIDthe index value of the row will be replaced by a globally unique index value allocated by the master agent. The caller is responsible for changing the row's index in the table model of the shared table.- Returns:
AgentXProtocol.AGENTX_SUCCESSif the index could be allocated or an AgentX protocol error code if allocation failed andallocateIndexis not altered.
-
handleIndexAllocationError
protected int handleIndexAllocationError(org.snmp4j.agent.mo.MOTableIndex indexDef, org.snmp4j.smi.OctetString context, org.snmp4j.smi.OID allocatedIndex, AgentXResponsePDU resp) Handle an index allocation error. By default, this method simply returns the AgentX error status from the master agent response. By overwriting this method, sub-classes may ignore such errors (for example, if using some of the "always..." index strategies.- Parameters:
indexDef- the index definition for the index whose sub-index allocation failed.context- the context of the allocation.allocatedIndex- the index OID of the sub-index that failed to allocate.resp- the AgentX reponse from the master agent.- Returns:
- an AgentX error status or
AgentXProtocol.AGENTX_SUCCESSto ignore the error. - Since:
- 2.1
-
deallocateIndex
public int deallocateIndex(org.snmp4j.smi.OctetString context, org.snmp4j.agent.mo.MOTableIndex indexDef, org.snmp4j.smi.OID allocatedIndex) Deallocate an index at the master agent.- Parameters:
context- the context for which to allocate the index. Specify an emptyOctetStringfor the default context.indexDef- the index definition with OID values for sub-index definitions.allocatedIndex- the index value of the previously allocated index.- Returns:
AgentXProtocol.AGENTX_SUCCESSif the index could be deallocated or an AgentX protocol error code if deallocation failed.
-
registerRow
Register a row at the master.- Parameters:
table- the table owning the row.row2Register- the row to register.- Returns:
- the AgentX status of the registration.
-
registerRow
Register the necessary regions for a table row.- Parameters:
table- the MOTable to register rows for.row2Register- the row to register.priority- the priority (default is 127). A smaller value takes precedence over larger values.- Returns:
- the AgentX status of the registration.
- Since:
- 2.1
-
unregisterRow
Removes the region registration of a table row. the MOTable to register rows for.- Parameters:
table- the table to be modified.row2Unregister- the row to unregister.- Returns:
- the AgentX status of the registration.
-
unregisterRow
Removes the region registration of a table row.- Parameters:
table- the MOTable to register rows for.row2Unregister- the row to unregister.priority- the priority (default is 127). A smaller value takes precedence over larger values.- Returns:
- the AgentX status of the registration.
- Since:
- 2.1
-
setPriority
public void setPriority(byte priority) Sets the priority for the region registrations made by this table support.- Parameters:
priority- the priority (default is 127). A smaller value takes precedence over larger values.
-
setSession
Sets the AgentX session to be used for this shared table support.- Parameters:
session- anAgentXSessioninstance.
-
setIndexMode
public void setIndexMode(byte indexMode) Sets the index mode to be used by this shared table support object.INDEX_MODE_ALLOCATEsimply allocates index values at the master agent, whereasINDEX_MODE_ANY_INDEXfetches any currently unique index value from the master agent for a new row andINDEX_MODE_NEW_INDEXfetches a new index (never used before by the master).- Parameters:
indexMode- an index mode to be used for shared tables supported by this object.
-
setContext
public void setContext(org.snmp4j.smi.OctetString context) -
getPriority
public byte getPriority()Gets the priority for the region registrations made by this table support.- Returns:
- a priority.
-
getSession
Gets the AgentX session used by this shared table support object.- Returns:
- an
AgentXSessioninstance ornullif there is no connection/session established with the master agent.
-
getIndexMode
public byte getIndexMode()Gets the index mode.- Returns:
INDEX_MODE_ALLOCATE,INDEX_MODE_ANY_INDEX, andINDEX_MODE_NEW_INDEX.
-
getContext
public org.snmp4j.smi.OctetString getContext()Gets the context.- Returns:
- the SNMPv3 context.
-
getAgentX
Gets theAgentXprotocol.- Returns:
- an
AgentXinstance.
-
getIndexStrategy
Gets the index strategy of this shared table support.- Returns:
- an
AgentXSharedMOTableSupport.IndexStrategyinstance. - Since:
- 2.1
-