SnmpTableListenerImpl.java
上传用户:aonuowh
上传日期:2021-05-23
资源大小:35390k
文件大小:2k
源码类别:

SNMP编程

开发平台:

C/C++

  1. /* $Id: SnmpTableListenerImpl.java,v 1.3 2002/09/09 05:45:01 tonyjpaul Exp $ */
  2. /*
  3.  * @(#)SnmpTableListenerImpl.java
  4.  * Copyright (c) 1996-2002 AdventNet, Inc. All Rights Reserved.
  5.  * Please read the COPYRIGHTS file for more 
  6.  */
  7. import java.util.*;
  8. import com.adventnet.snmp.snmp2.*;
  9. import com.adventnet.snmp.mibs.*;
  10. import com.adventnet.snmp.beans.*;
  11. public class SnmpTableListenerImpl extends 
  12. com.adventnet.snmp.corba._SnmpTableListenerImplBase 
  13. {
  14.         public SnmpTableListenerImpl( com.adventnet.snmp.corba.SnmpTable tbl )
  15.         {
  16.             this.table = tbl;
  17.         }
  18.             
  19.     // This method is called when trap is received by SnmpTrapReceiver
  20.     public void tableChanged(com.adventnet.snmp.corba.TableEvent tblEvent) {
  21.     try {
  22.         StringBuffer sb = new StringBuffer();
  23.         
  24.         if ( tblEvent.startRow == 0) {  // we're being notified of first row
  25.         for (int i=0;i<table.getColumnCount();i++)  // print column names
  26.             sb.append(table.getColumnName(i)+" t");
  27.         System.out.println(sb.toString());
  28.         }
  29.             
  30.         if (table.getRowCount() == 0) { // no rows and we're being notified
  31.         System.err.println("Request failed or timed out. n"+
  32.                    table.getErrorString());
  33.         } else { // print the rows we're getting
  34.         sb = new StringBuffer();
  35.         for (int j= tblEvent.startRow;j<=tblEvent.endRow;j++) { 
  36.             for (int i=0;i<table.getColumnCount();i++) 
  37.             sb.append(table.getValueAt(j,i)+" t");
  38.         }
  39.         System.out.println(sb.toString());
  40.         }
  41.     } catch (Exception ex) {
  42.         System.err.println("Failed: "+ ex);
  43.         ex.printStackTrace();
  44.     }
  45.     } 
  46.     com.adventnet.snmp.corba.SnmpTable table;    
  47.     
  48. }
  49.     
  50.     //System.out.println("Got a trap" ); 
  51.         //com.adventnet.snmp.beans.SnmpTableEvent event = ((SnmpTableEventImpl)tblEvent).tableEvent;
  52.         //System.out.println( "Table Event: " );
  53.         //System.out.println( "First Row: " + tblEvent.startRow );
  54.         //System.out.println( "Last Row: " + tblEvent.endRow );
  55.         //System.out.println( "Column : " + tblEvent.column );
  56.         //System.out.println( "Type: " + tblEvent.Type );