当前位置: 首页>>代码示例>>Java>>正文


Java ResponseEvent.getRequest方法代码示例

本文整理汇总了Java中org.snmp4j.event.ResponseEvent.getRequest方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseEvent.getRequest方法的具体用法?Java ResponseEvent.getRequest怎么用?Java ResponseEvent.getRequest使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.snmp4j.event.ResponseEvent的用法示例。


在下文中一共展示了ResponseEvent.getRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onResponse

import org.snmp4j.event.ResponseEvent; //导入方法依赖的package包/类
public void onResponse(ResponseEvent event) {
    // Always cancel async request when response has been received
    // otherwise a memory leak is created! Not canceling a request
    // immediately can be useful when sending a request to a broadcast address.
    ((Snmp)event.getSource()).cancel(event.getRequest(), this);

    // check for valid response
    if (event.getRequest() == null || event.getResponse() == null) {
        // ignore null requests/responses
        LOG.debug("Received invalid SNMP event. Request: " + event.getRequest() + " / Response: " + event.getResponse());
        return;
    }
    
    PDU pdu = event.getResponse();
    processPDU(pdu);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:SnmpOIDPoller.java

示例2: sendGetPDU

import org.snmp4j.event.ResponseEvent; //导入方法依赖的package包/类
/**
 * Send PDU to H3C, then waiting response event will be caught by listener.
 *
 * @param snmp
 * @param userTarget
 * @param pdu
 * @throws IOException
 * @throws InterruptedException
 */
private void sendGetPDU(Snmp snmp, UserTarget userTarget, ScopedPDU pdu)
        throws IOException, InterruptedException {

    final CountDownLatch latch = new CountDownLatch(1);
    ResponseListener listener = new ResponseListener() {

        @Override
        public void onResponse(ResponseEvent event) {
            ((Snmp) event.getSource()).cancel(event.getRequest(), this);
            PDU response = event.getResponse();
            PDU request = event.getRequest();
            LOG.debug("[request]: {}", request);

            if (response == null) {
                LOG.error("[ERROR]: response is null");

            } else if (response.getErrorStatus() != 0) {
                LOG.error("[ERROR]: response status {}, Text: {}",
                        response.getErrorStatus(),
                        response.getErrorStatusText());
            } else {
                LOG.debug("Received response Success!");
                for (int i = 0; i < response.size(); i++) {
                    VariableBinding vb = response.get(i);
                    LOG.info("{} = {}",
                            vb.getOid(),
                            vb.getVariable());
                }
                LOG.debug("SNMP Async GetList OID finished. ");
                latch.countDown();
            }
        }
    };
    snmp.send(pdu, userTarget, null, listener);
    LOG.debug("async send pdu wait for response...");

    boolean wait = latch.await(3, TimeUnit.SECONDS);
    LOG.debug("latch.await =:" + wait);
}
 
开发者ID:asdf2014,项目名称:yuzhouwan,代码行数:49,代码来源:SnmpH3C.java


注:本文中的org.snmp4j.event.ResponseEvent.getRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。