本文整理汇总了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);
}
示例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);
}