SourceForge.net Logo

org.netsnmp.util
Class ValueCollector

java.lang.Object
  |
  +--org.netsnmp.util.ValueCollector
All Implemented Interfaces:
EventListener, NetSNMPAction

public class ValueCollector
extends Object
implements NetSNMPAction

Utility class, based on the GET_NEXT request, to collect values from a column of objects. For example:

 ValueCollector c = new ValueCollector(String host, String community, new DefaultOID("IF-MIB::ifIndex")) ;
 ints [] ifIndicies = c.ints() ;
 
This would collect all of the indexes for installed interfaces.

Author:
Andrew E. Page aepage@users.sourceforge.net

Constructor Summary
ValueCollector(NetSNMPSession copySession, OID baseOID)
          Create a new instance of a ValueCollector using an exisiting session's peer, community and version.
ValueCollector(String host, String community, OID baseOID)
          Create a new instance of a ValueCollector
 
Method Summary
 boolean actionPerformed(int result, NetSNMPSession session, PDU pdu, Object o)
          Called when a session receives a pdu result
 int[] ints()
          wait for the results, and convert them to integers
 boolean isReady()
           
static void main(String[] args)
           
protected  void onComplete()
          routine called when query has been completed.
 String[] strings()
           
 String toString()
           
 ASNValue[] values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ValueCollector

public ValueCollector(String host,
                      String community,
                      OID baseOID)
               throws NetSNMPSendError
Create a new instance of a ValueCollector

Parameters:
host - host to query
community - community to use
baseOID - OID to begin query

ValueCollector

public ValueCollector(NetSNMPSession copySession,
                      OID baseOID)
               throws NetSNMPSendError
Create a new instance of a ValueCollector using an exisiting session's peer, community and version.

Method Detail

strings

public String[] strings()
                 throws RuntimeException,
                        Error
RuntimeException
Error

values

public ASNValue[] values()

ints

public int[] ints()
           throws RuntimeException,
                  Error
wait for the results, and convert them to integers

RuntimeException
Error

toString

public String toString()
Overrides:
toString in class Object

isReady

public boolean isReady()
Returns:
whether or not the indexes have been collected. Can be used to poll the status of this object rather than having to wait for it.

onComplete

protected void onComplete()
routine called when query has been completed. Base class routine is essentially a no-op. Override to provide an asynchronous notification of complettion
 Example:
 
 class myValueCollector extends ValueCollector {
 protected void onComplete() {
    // completion action
 }


actionPerformed

public boolean actionPerformed(int result,
                               NetSNMPSession session,
                               PDU pdu,
                               Object o)
                        throws Throwable
Description copied from interface: NetSNMPAction
Called when a session receives a pdu result

Specified by:
actionPerformed in interface NetSNMPAction
Parameters:
result - SNMP Supporting library specific code
session - Session PDU was received on
pdu - The pdu received
o - Object supplied by caller to send method
Returns:
TRUE if other listeners are to be called, FALSE if not
Throws:
Throwable - Exception to be caught by the internal thread
See Also:
NetSNMPAction.actionPerformed(int, NetSNMPSession, PDU, Object)

main

public static void main(String[] args)
                 throws Throwable
Throwable

SourceForge.net Logo