Java开发网 Java开发网
注册 | 登录 | 帮助 | 搜索 | 排行榜 | 发帖统计  

您没有登录

» Java开发网 » Java EE 综合讨论区  

按打印兼容模式打印这个话题 打印话题    把这个话题寄给朋友 寄给朋友    该主题的所有更新都将Email到你的邮箱 订阅主题
flat modethreaded modego to previous topicgo to next topicgo to back
作者 请高手帮我看看这段aglet程序
yuyingtongzhi





发贴: 4
积分: 0
于 2006-08-24 11:55 user profilesend a private message to usersearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
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)




请求JAVA学习方向?????

话题树型展开
人气 标题 作者 字数 发贴时间
8403 请高手帮我看看这段aglet程序 yuyingtongzhi 3521 2006-08-24 11:55
7854 Re:请高手帮我看看这段aglet程序 yuyingtongzhi 0 2006-08-24 11:56

flat modethreaded modego to previous topicgo to next topicgo to back
  已读帖子
  新的帖子
  被删除的帖子
Jump to the top of page

   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