// Home | Go Back //
import com.ireasoning.protocol.*;
import com.ireasoning.protocol.snmp.*;
public class snmpasyncget extends snmp implements Listener
{
public static void main(String[] args)
{
snmpasyncget s = new snmpasyncget();
s.parseOptions(args, "snmpasyncget");
s.get();
}
private void get()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
session.setRetries(0);
session.setTimeoutForAsyncRequests(5000); if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword, _privProtocol, _privPassword, _context, null);
}
session.addListener(this);
SnmpPdu pdu = session.asyncSnmpGetRequest(_oids); }
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
private void get2()
{
try
{
SnmpSession session = new SnmpSession(_host, _port, _community,
_community, _version);
session.setTimeoutForAsyncRequests(5000); if(_isSnmpV3)
{
session.setV3Params(_user, _authProtocol, _authPassword, _privProtocol, _privPassword, _context, null);
}
session.addListener(this);
SnmpVarBind[] vblist = new SnmpVarBind[_oids.length];
for (int i = 0; i < vblist.length ; i++)
{
vblist[i] = new SnmpVarBind(_oids[i]);
}
SnmpPdu pdu = new SnmpPdu(SnmpConst.GET, vblist);
session.asyncSend(pdu); }
catch(Exception e)
{
System.out.println(e);
e.printStackTrace();
}
}
public void handleMsg(Object session, Msg msg)
{ if(msg.getType() == Msg.ERROR_TYPE)
{
ErrorMsg err = (ErrorMsg) msg;
if(err.getErrorCode () == ErrorMsg.TIMEOUT_ERROR)
{
TimeoutErrorMsg timeoutError = (TimeoutErrorMsg) err;
System.out.println( "Time out. Request ID is " + timeoutError.getRequestID());
}
else
{
System.out.println( "Got an error:" );
System.out.println( err.getException() );
}
}
else
{
SnmpPdu pdu = (SnmpPdu) msg;
print(pdu);
}
((SnmpSession)session).close(); }
protected void printExample(String programName)
{
System.out.println( "java " + programName + " localhost .1.3.6.1.2.1.1.1.0");
}
}