com.adventnet.snmp.beans
Class SnmpPoller

java.lang.Object
  |
  +--com.adventnet.snmp.beans.SnmpServer
        |
        +--com.adventnet.snmp.beans.SnmpTarget
              |
              +--com.adventnet.snmp.beans.SnmpPoller
All Implemented Interfaces:
CustomizerTemplate, java.util.EventListener, java.lang.Runnable, java.io.Serializable, java.beans.VetoableChangeListener

public class SnmpPoller
extends SnmpTarget
implements java.lang.Runnable, java.beans.VetoableChangeListener

This class is an SNMP Poller bean for automatic polling of one or more variables from a given remote agent. After each poll, it generates events, i.e. ResultEvent objects, for which listeners can be registered.It can be used with bean builders and other applications, where you can set up SNMP polling and automatic updates.

The SnmpPoller bean is a sub-class of the SnmpTarget bean. It uses SnmpTarget for polling the data. The class using SnmpPoller should instantiate SnmpPoller and set up the properties like hostname, port, version, community of the agent, etc., to match the agent that needs to be queried. Set the ObjectID to be polled and add one or more listeners for receiving the polled data. The result data can also be plotted in Graph (LineGraph or BarGraph).

	SnmpPoller poller = new SnmpPoller(); // Instantiate SnmpPoller.  
	poller.setObjectID("1.3.0");  //the OID to be polled  
	poller.setTargetHost("localhost"); //the host name or IP address of the machine.  
	poller.setPollInterval(10); //polling interval in seconds. Default is 5 seconds.
	poller.setSendTimeoutEvents(true);  // to receive timeout events. 
	ResultAdapter listener = new ResultAdapter() { 
 		public void setResult(ResultEvent evt) { 
			if(evt.isSuccess())	{
				System.err.println("SnmpPoller Response: "+evt.getValue(0)); 
			}
			else	{
				System.out.println("Error String : " + evt.getErrorString());
			}
		} 
	}; 
	poller.addResultListener(listener);
 

In some cases it may be required that the poller should not start polling automatically. To achieve this:

 	poller.setAutoActive(false); //to avoid polling getting started automatically
 
Now the poller will not start polling automatically. To start polling the data:
	poller.restartPolling(); //to start polling the SNMP data.
 

For polling multiple OIDs,

	 poller.setObjectIDList(oids); 
	ResultListener listener = new ResultListener() { 
		public void setResult(ResultEvent evt) { 
			if(evt.isSuccess())	{
				System.out.println("SnmpPoller Response: ");
				for(int i=0;i
 

Different SnmpPoller instances on the same JVM, will reuse the SnmpAPI, SnmpSession and MibOperations instance. So, for releasing these resources, releaseResources() method should be called on every SnmpPoller instance created and when this method is called on the final instance of SnmpPoller, these will be garbage collected.

See the superclass SnmpTarget, for details on parameters and more on methods for setting up the poller parameters.

See Also:
SnmpTarget, ResultEvent, ResultListener, Serialized Form

Field Summary
 
Fields inherited from class com.adventnet.snmp.beans.SnmpTarget
serialize, SNMPGET, SNMPGETBULK, SNMPGETNEXT, SNMPINFORM, SNMPREPORT, SNMPRESPONSE, SNMPSET, SNMPTRAP, SNMPV2TRAP, VERSION1, VERSION2C, VERSION3
 
Fields inherited from class com.adventnet.snmp.beans.SnmpServer
AUTH_NO_PRIV, AUTH_PRIV, CBC_3DES, CBC_DES, CFB_AES_128, CFB_AES_192, CFB_AES_256, MD5_AUTH, NO_AUTH, NO_AUTH_NO_PRIV, NO_PRIV, oidList, SHA_AUTH
 
Constructor Summary
SnmpPoller()
          This constructor is used for polling data applications.
SnmpPoller(java.applet.Applet applet)
          This constructor is used for applets.
SnmpPoller(int protocol, ProtocolOptions options)
          This constructor is used for applications which use protocols other than UDP/IP.
 
Method Summary
 void addResultListener(ResultListener l)
          add a listener for events from this poller.
protected  void finalize()
          this cleans up if no one is using
protected  void genEvent(SnmpPDU pdu)
          generate the events to the listeners
 boolean getAbsoluteCounters()
          To get whether the value returned by the poller will be the absolute value or the difference between successive counters.
 boolean getPollingStatus()
          returns whether the polling of some data is going on or not.
 int getPollInterval()
          get the current polling interval in seconds
 boolean isAutoActive()
          returns whether the poller will be started automatically i.e.
 void pausePolling()
          stops the polling.
 void removeResultListener(ResultListener l)
          Remove a listener for events from this poller.
 void restartPolling()
          Restart the SNMP polling.
 void run()
          the work done by the polling thread.
 void setAbsoluteCounters(boolean absoluteCounters)
          sets whether counter values should be absolute - applies only for single variable requests.
 void setAutoActive(boolean isAutoActive)
          To make the poller to start polling automatically after setting either OID or poll interval or after adding the first result listener.
 void setObjectID(int index, java.lang.String s)
          Set the object ID value at index based on specified string
 void setObjectID(java.lang.String s)
          Set the object ID specified by the String value.
 void setObjectIDList(java.lang.String[] s)
          Set the list of object IDs based on the specified string array.
 void setPollInterval(int i)
          set the polling interval in seconds
 void stopPolling()
          Stop the polling and Stops the thread - disables the data collection from the agent and event generation.
 void vetoableChange(java.beans.PropertyChangeEvent evt)
          Sets the properties constrained properties.
 
Methods inherited from class com.adventnet.snmp.beans.SnmpTarget
addLogClient, addLogClient, addObjectID, addSnmpOID, addSnmpPropertyListener, addUserError, addV3HandShakeResultListener, enableDebugForPDU, genTimeoutEvent, getAttemptComplete, getAttemptPartial, getAuthPassword, getAuthProtocol, getCommunity, getCompleteResponse, getContextID, getContextName, getDebug, getEngineID, getErrorCode, getErrorCodes, getErrorIndex, getErrorString, getExceptionCode, getExceptionCodes, getIgnoreSpecificControlCodes, getMaxNumRows, getMaxRepetitions, getMibModules, getMibOperations, getNonRepeaters, getObjectID, getObjectID, getObjectIDList, getPduErrorIndex, getPrincipal, getPrivPassword, getPrivProtocol, getRetries, getSecurityLevel, getSecurityModel, getSendTimeoutEvents, getSnmpOID, getSnmpOIDList, getSnmpVersion, getTargetHost, getTargetPort, getTimeout, getUserErrorCode, getUserErrorString, getVarBindCount, getWriteCommunity, isInSubTree, isSerialize, loadMibs, releaseResources, removeLogClient, removeSnmpPropertyListener, removeV3HandShakeListener, setAttemptComplete, setAttemptPartial, setAuthPassword, setAuthProtocol, setClientID, setCommunity, setContextID, setContextName, setDebug, setEngineID, setIgnoreSpecificControlCodes, setMaxNumRows, setMaxRepetitions, setMibModules, setNonRepeaters, setParams, setParams, setPrincipal, setPrivPassword, setPrivProtocol, setRetries, setSecurityLevel, setSecurityModel, setSendTimeoutEvents, setSnmpOID, setSnmpOIDList, setSnmpVersion, setTargetHost, setTargetPort, setTimeout, setVarBindCount, setWriteCommunity, snmpGet, snmpGet, snmpGetAllList, snmpGetAllVariableBindings, snmpGetAllVariables, snmpGetBulkList, snmpGetBulkVariableBindings, snmpGetBulkVariables, snmpGetList, snmpGetList, snmpGetNext, snmpGetNext, snmpGetNextList, snmpGetNextList, snmpGetNextVariable, snmpGetNextVariableBinding, snmpGetNextVariableBindings, snmpGetNextVariables, snmpGetVariable, snmpGetVariableBinding, snmpGetVariableBindings, snmpGetVariables, snmpSendInformAcknowledgement, snmpSendInformRequest, snmpSendInformRequest, snmpSendNotification, snmpSendNotification, snmpSendTrap, snmpSendTrap, snmpSet, snmpSet, snmpSetList, snmpSetVariable, snmpSetVariableList, snmpSetVariables
 
Methods inherited from class com.adventnet.snmp.beans.SnmpServer
async_create_v3_tables, create_v3_tables, genEvent, getCharacterEncoding, getHostAddress, getLocalAddresses, getMibPath, getOverwriteCMI, getPacketBufferSize, getSecLevelForTimeSync, getSecurityProvider, getSecurityTable, getSerializedMibFileName, getSimpleDateFormat, getSnmpEngineID, getSnmpEngineTable, getTimeoutInMilliSec, getTimeToWait, getUSMTable, getV3ConfigTable, getV3MsgMaxSize, initJdbcParams, initSecurityProvider, isBroadcastFeatureEnable, isLoadFromCompiledMibs, isLoadFromSerializedMibs, isLoadMibsFromDatabase, isOverwriteCMI, isOverwriteMibsInDatabase, isReadDesc, isSendPDUByGroup, isSerializeMibs, isSetAutoInformResponse, isSupportedSecurityModel, isV3DatabaseFlag, isValidateUser, manage_v3_tables, managing_v3_tables, reestablish, restoreDefaultTimeoutPolicy, setAutoInformResponse, setBroadcastFeatureEnable, setCharacterEncoding, setErrorFlagEnable, setLoadFromCompiledMibs, setLoadFromSerializedMibs, setLoadMibsFromDatabase, setMibOperations, setMibPath, setOverwriteCMI, setOverwriteMibsInDatabase, setPacketBufferSize, setReadDesc, setReceiveBufferSize, setSecLevelForTimeSync, setSendPDUByGroup, setSerializedMibFileName, setSerializeMibs, setSimpleDateFormat, setSnmpEngineBoots, setSnmpEngineID, setTimeoutInMilliSec, setTimeoutPolicy, setTimeToWait, setV3ConfigTable, setV3DatabaseFlag, setV3MsgMaxSize, setWaitTimeToRetry, validateUser
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.adventnet.snmp.beans.CustomizerTemplate
create_v3_tables, getSnmpEngineTable, getUSMTable, initSecurityProvider, isSupportedSecurityModel, manage_v3_tables
 

Constructor Detail

SnmpPoller

public SnmpPoller()
This constructor is used for polling data applications.


SnmpPoller

public SnmpPoller(java.applet.Applet applet)
This constructor is used for applets.


SnmpPoller

public SnmpPoller(int protocol,
                  ProtocolOptions options)
This constructor is used for applications which use protocols other than UDP/IP.

Method Detail

run

public void run()
the work done by the polling thread. The following ErrorCodes can be set: SNMP_NOT_INIT, INVALID_VERSION, OID_NOT_SPECIFIED, REQ_TIMEDOUT, EMPTY_VAR_BIND, IP_ADDR_NOT_SPECIFIED, SESSION_REMOTE_HOST_UNKNOWN, SECURITYEXP_CONNECTING_REMOTE_HOST, UNKNOWN_ERR, SNMPERROR'S defined in ErrorMessages v3 only INVALID_CONTEXT_NAME ,INVALID_CONTEXT_ID.

Specified by:
run in interface java.lang.Runnable
See Also:
ErrorMessages, SnmpTarget.getErrorCode(), SnmpTarget.getErrorString()

finalize

protected void finalize()
                 throws java.lang.Throwable
this cleans up if no one is using

Overrides:
finalize in class SnmpServer
Throws:
java.lang.Throwable - in case of finalization errors

getPollingStatus

public boolean getPollingStatus()
returns whether the polling of some data is going on or not. If polling has stopped or if the polling thread has died,it will return false.


stopPolling

public void stopPolling()
Stop the polling and Stops the thread - disables the data collection from the agent and event generation. Prior to 2.1 release, stop polling only stops the polling and not the thread. To pause the polling stopping the thread use pausePolling.


pausePolling

public void pausePolling()
stops the polling. Does not stop the thread - disables the data collection from the agent and event generation.


restartPolling

public void restartPolling()
Restart the SNMP polling. If the thread has died for any reason, reinstantiate the polling thread and start it again.


isAutoActive

public boolean isAutoActive()
returns whether the poller will be started automatically i.e. Once if the objectID or poll interval is set or the first result listener is added. By default this method will return true and hence after setting objectID using setObjectID or after setting the poll interval using setPollInterval(poll interval) or after adding the result listener using addResultListener() the Poller will start Polling automatically. To avoid this, setAutoActive to false can be used. In such case restartPolling can be used to start Polling.


setAutoActive

public void setAutoActive(boolean isAutoActive)
To make the poller to start polling automatically after setting either OID or poll interval or after adding the first result listener. Boolean true should be passed to this method. If the poller should not start polling by itself,then false should be passed in which such case, polling should be initiated using restartpolling method.


getPollInterval

public int getPollInterval()
get the current polling interval in seconds


setPollInterval

public void setPollInterval(int i)
set the polling interval in seconds


getAbsoluteCounters

public boolean getAbsoluteCounters()
To get whether the value returned by the poller will be the absolute value or the difference between successive counters.

Returns:
true if the poller will return the absolute value of the counters and false if the poller will return the difference between the successive counter values.

setObjectID

public void setObjectID(java.lang.String s)
Set the object ID specified by the String value.

Overrides:
setObjectID in class SnmpTarget
Parameters:
s - the oid to be set.

setObjectID

public void setObjectID(int index,
                        java.lang.String s)
Set the object ID value at index based on specified string

Overrides:
setObjectID in class SnmpTarget
Parameters:
index - index where the oid is to be set in the oidlist
s - oid to be set.

setObjectIDList

public void setObjectIDList(java.lang.String[] s)
Set the list of object IDs based on the specified string array.

Overrides:
setObjectIDList in class SnmpTarget
Parameters:
s - a String array of OIDs.

setAbsoluteCounters

public void setAbsoluteCounters(boolean absoluteCounters)
sets whether counter values should be absolute - applies only for single variable requests. This has an impact only on the results of the counter data types only. If it is set to true, the poller will return the absolute value of the counter. If it is set to false, the result returned will be a difference between successive counter values. This will be useful for plotting the counter values. For multi-oid requests, it's up to the listener to process the counters correctly.


genEvent

protected void genEvent(SnmpPDU pdu)
generate the events to the listeners

Overrides:
genEvent in class SnmpTarget

addResultListener

public void addResultListener(ResultListener l)
add a listener for events from this poller. The listener listens for events from any or all SNMP requests.

Overrides:
addResultListener in class SnmpTarget

removeResultListener

public void removeResultListener(ResultListener l)
Remove a listener for events from this poller.

Overrides:
removeResultListener in class SnmpTarget

vetoableChange

public void vetoableChange(java.beans.PropertyChangeEvent evt)
Sets the properties constrained properties. PropertyChangeEvent.getNewValue() expects a Hashtable of constrainted properties. Constrained property set are: SNMP Version with key VERSION Host Name with key HOST Port Number with key PORT Polling Interval with key POLL Timeout value with key TIMEOUT Retries value with key RETRIES Auth Protocol with key AUTHPROT User Name with key USERNAME Auth Password with key AUTHPASS Privacy Password with key PRIVPASS

Specified by:
vetoableChange in interface java.beans.VetoableChangeListener
Overrides:
vetoableChange in class SnmpTarget


Copyright (c)ZOHO Corp. 1996-2012