本文整理汇总了Java中org.snmp4j.PDU.setErrorStatus方法的典型用法代码示例。如果您正苦于以下问题:Java PDU.setErrorStatus方法的具体用法?Java PDU.setErrorStatus怎么用?Java PDU.setErrorStatus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.snmp4j.PDU
的用法示例。
在下文中一共展示了PDU.setErrorStatus方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processPdu
import org.snmp4j.PDU; //导入方法依赖的package包/类
public void processPdu(CommandResponderEvent event) {
PDU pdu = event.getPDU();
// check PDU not null
if (pdu != null) {
// check for INFORM
// code take from the book "Essential SNMP"
if ((pdu.getType() != PDU.TRAP) && (pdu.getType() != PDU.V1TRAP) && (pdu.getType() != PDU.REPORT)
&& (pdu.getType() != PDU.RESPONSE)) {
// first response the inform-message and then process the
// message
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = event.getStateReference();
try {
event.getMessageDispatcher().returnResponsePdu(event.getMessageProcessingModel(),
event.getSecurityModel(),
event.getSecurityName(),
event.getSecurityLevel(), pdu,
event.getMaxSizeResponsePDU(), ref,
statusInformation);
if (LOG.isDebugEnabled()) {
LOG.debug("response to INFORM sent");
}
} catch (MessageException ex) {
getExceptionHandler().handleException(ex);
}
}
processPDU(pdu, event);
} else {
LOG.debug("Received invalid trap PDU: " + pdu);
}
}
示例2: processPdu
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* This method will be called whenever a pdu is received on the given port specified in the listen() method
*/
public synchronized void processPdu(CommandResponderEvent cmdRespEvent)
{
System.out.println("Received PDU...");
PDU pdu = cmdRespEvent.getPDU();
if (pdu != null)
{
System.out.println("Trap Type = " + pdu.getType());
System.out.println("Variable Bindings = " + pdu.getVariableBindings());
int pduType = pdu.getType();
if ((pduType != PDU.TRAP) && (pduType != PDU.V1TRAP) && (pduType != PDU.REPORT)
&& (pduType != PDU.RESPONSE))
{
pdu.setErrorIndex(0);
pdu.setErrorStatus(0);
pdu.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = cmdRespEvent.getStateReference();
try
{
System.out.println(cmdRespEvent.getPDU());
cmdRespEvent.getMessageDispatcher().returnResponsePdu(cmdRespEvent.getMessageProcessingModel(),
cmdRespEvent.getSecurityModel(), cmdRespEvent.getSecurityName(), cmdRespEvent.getSecurityLevel(),
pdu, cmdRespEvent.getMaxSizeResponsePDU(), ref, statusInformation);
}
catch (MessageException ex)
{
System.err.println("Error while sending response: " + ex.getMessage());
LogFactory.getLogger(SnmpRequest.class).error(ex);
}
}
}
}
示例3: processPdu
import org.snmp4j.PDU; //导入方法依赖的package包/类
@Override
public void processPdu(CommandResponderEvent e) {
PDU command = new PDU(e.getPDU());
IpAddress addr = ((IpAddress)e.getPeerAddress());
if (command != null) {
if (command.getType() == PDU.INFORM) {
PDU response = new PDU(command);
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
StatusInformation statusInformation = new StatusInformation();
StateReference ref = e.getStateReference();
try {
e.getMessageDispatcher().returnResponsePdu(e.getMessageProcessingModel(),
e.getSecurityModel(),
e.getSecurityName(),
e.getSecurityLevel(),
response,
e.getMaxSizeResponsePDU(),
ref,
statusInformation);
if (log().isDebugEnabled()) {
log().debug("Sent RESPONSE PDU to peer " + addr + " acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
} catch (MessageException ex) {
log().error("Error while sending RESPONSE PDU to peer " + addr + ": " + ex.getMessage() + "acknowledging receipt of INFORM (reqId=" + command.getRequestID() + ")");
}
}
}
if (e.getPDU() instanceof PDUv1) {
m_listener.trapReceived(new Snmp4JV1TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), (PDUv1)e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
} else {
m_listener.trapReceived(new Snmp4JV2TrapInformation(addr.getInetAddress(), new String(e.getSecurityName()), e.getPDU(), m_trapProcessorFactory.createTrapProcessor()));
}
}
示例4: processGet
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* @param request
* @return
*/
@SuppressWarnings("unchecked")
private PDU processGet(PDU request) {
PDU response = request;
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
Vector<VariableBinding> varBinds = response.getVariableBindings();
for(int i = 0; i < varBinds.size(); i++) {
VariableBinding varBind = varBinds.get(i);
VariableBinding nextVarBind = m_agent.get(varBind.getOid());
if (nextVarBind == null) {
if (response instanceof PDUv1) {
if (response.getErrorIndex() == 0) {
response.setErrorIndex(i+1);
response.setErrorStatus(PDU.noSuchName);
}
} else {
varBind.setVariable(Null.endOfMibView);
}
} else {
response.set(i, nextVarBind);
}
}
return response;
}
示例5: processGetNext
import org.snmp4j.PDU; //导入方法依赖的package包/类
/**
* @param request
* @return
*/
@SuppressWarnings("unchecked")
private PDU processGetNext(PDU request) {
PDU response = request;
response.setErrorIndex(0);
response.setErrorStatus(0);
response.setType(PDU.RESPONSE);
Vector<VariableBinding> varBinds = response.getVariableBindings();
for(int i = 0; i < varBinds.size(); i++) {
VariableBinding varBind = varBinds.get(i);
VariableBinding nextVarBind = m_agent.getNext(varBind.getOid());
if (nextVarBind == null) {
if (response instanceof PDUv1) {
if (response.getErrorIndex() == 0) {
response.setErrorIndex(i+1);
response.setErrorStatus(PDU.noSuchName);
}
} else {
varBind.setVariable(Null.endOfMibView);
}
} else {
response.set(i, nextVarBind);
}
}
return response;
}