Topic: 请高手帮我看看这段aglet程序

  Print this page

1.请高手帮我看看这段aglet程序 Copy to clipboard
Posted by: yuyingtongzhi
Posted on: 2006-08-24 11:55

package examples.patterns;

import org.netsnmp.* ;
import org.netsnmp.ASN.* ;

import com.ibm.aglet.*;

import examples.patterns.FingerSlave.MyListener;

public class FingerTest extends Aglet {
  /**
   *
   */
  private static final long serialVersionUID = 6830194584086806953L;
  static OID sysDescrOID ;
  
  public void onCreation(Object init){
    
    System.out.println("Agent created,I want to read snmp data"+init);
  }
  
  public void run(){
    System.out.println(" I am reading ");
    try {
      getSnmpInfo();
    } catch (MIBItemNotFound e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (NetSNMPSendError e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (IllegalStateException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    } catch (InterruptedException e) {
      // TODO 自动生成 catch 块
      e.printStackTrace();
    }
    
    
  }
  
  public void onDisposing(){
    System.out.println("Agent quitting,I have read snmp data");
  }
  
  
  static void getSnmpInfo() throws MIBItemNotFound, NetSNMPSendError, IllegalStateException, InterruptedException {
  
   NetSNMPSession sess ;
   //NetSNMPAction myListener = new MyListener() ;
  
   String host, community ;

     host="localhost";
     //host="202.197.54.215";
   community="public";         

   sess = new NetSNMPSession(host, community) ;
      
      //sess.addListener(myListener) ;
      
  
      //sysDescrOID = new DefaultOID("SNMPv2-MIB::sysDescr.0") ;
  
      //PDU pdu = new PDU(NetSNMP.MSG_GET) ;
  
   //pdu.addNullEntry(sysDescrOID) ;
  
   //synchronized( myListener ) {
     /*
      * send the pdu to the remote agent
      */
            //sess.send(pdu, null) ;
            /*
             * wait for the result. Waits until the 'notify' method
             * is called on the myListener object and the actionPerformed
             * method returns.
             */
            //myListener.wait() ;
        //  } // synchronized
  
   }
  
  static class MyListener implements NetSNMPAction {
  
    /*
     * This method will be called from within the NetSNMP thread
     * that processes SNMP transactions.
     *
     * By synchronizing this method, and calling 'send' from within a
     * synchronized {} block synchronized on this object we guarantee
     * that this method does not start until the main thread has sent
     * its pdu and is 'waiting' for the response to be processed.
     */
public synchronized boolean actionPerformed(int result, NetSNMPSession sess, PDU rcvPdu, Object o) {
ASNValue val = rcvPdu.findValue(sysDescrOID) ;

/*
* notifies a thread calling the 'wait' method on this object
* to return. However, that wait call will not return until
* this method returns, releasing the 'synchronized' lock.
*/
this.notify() ;

/*
* Check to make sure that we got a response.
*/
if( result == NetSNMP.STAT_TIMEOUT ) {
System.err.println("Timeout no response") ;
return false ; // don't call other registered listeners
}

System.out.println("got sysDescr = " + val) ;
return true ; // continue to call other registered listeners
}
}  
}

在aglet平台上运行后,总是出现如下所示的错误 ,是因为语句sess = new NetSNMPSession(host, community) 造成的,该语句是建立一个SNMP 连接
如果将SNMP操作这段提出来单独做成一个程序运行是成功的,不知道为什么在aglet里面运行就不行了

agleterror.bmp (883.99k)

2.Re:请高手帮我看看这段aglet程序 [Re: yuyingtongzhi] Copy to clipboard
Posted by: yuyingtongzhi
Posted on: 2006-08-24 11:56



(缩略图,点击图片链接看原图)


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923