[SNMP4J] How can I deal with cable disconnect when visit table?

Leon Li liysh at exavio.com.cn
Thu Jul 28 08:41:33 CEST 2005


I use command  "snmp4j -v 2c -c public -Ot agentaddress 1.3.6.1.4.1.19057.x.x.x(table entry OID)"
and when command is executing, I plug out cable.this command will wait and no response for a long time.
I can only use Ctrl-C to break.

I add some print infomation("getTable passed") in table() of SnmpRequest.java 
and then run it.I found stop at counter.wait() and there's no notify() invoked.

Is there method to deal with this case?

  public void table() throws IOException {
    Snmp snmp = createSnmpSession();
    this.target = createTarget();
    target.setVersion(version);
    target.setAddress(address);
    target.setRetries(retries);
    target.setTimeout(timeout);
    snmp.listen();

    TableUtils tableUtils = new TableUtils(snmp, this);
    tableUtils.setMaxNumRowsPerPDU(maxRepetitions);
    Counter32 counter = new Counter32();

    OID[] columns = new OID[vbs.size()];
    for (int i=0; i<columns.length; i++) {
      columns[i] = ((VariableBinding)vbs.get(i)).getOid();
    }
    long startTime = System.currentTimeMillis();
    synchronized (counter) {

      TableListener listener;
      if (operation == TABLE) {
        listener = new TextTableListener();
      }
      else {
        listener = new CVSTableListener(System.currentTimeMillis());
      }
      if (useDenseTableOperation) {
        tableUtils.getDenseTable(target, columns, listener, counter,
                                 lowerBoundIndex, upperBoundIndex);
      }
      else {
        tableUtils.getTable(target, columns, listener, counter,
                            lowerBoundIndex, upperBoundIndex);
        System.out.println("getTable passed");//added by Leo
      }
      try {
        counter.wait();
      }
      catch (InterruptedException ex) {
       ex.printStackTrace();
      }
    }
    System.out.println("Table received in "+
                       (System.currentTimeMillis()-startTime)+" milliseconds.");
    snmp.close();
  }


More information about the SNMP4J mailing list