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


Java CommandResponderEvent.getPeerAddress方法代码示例

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


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

示例1: processPdu

import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
/**
 * Will be called whenever a {@link PDU} is received on the given port
 * specified in the listen() method. It extracts a {@link Variable}
 * according to the configured OID prefix and sends its value to the event
 * bus.
 */
public void processPdu(CommandResponderEvent event) {
	Address addr = event.getPeerAddress();
	if (addr == null) {
		return;
	}
	
	String s = addr.toString().split("/")[0];
	if (s == null) {
		logger.error("TRAP: failed to translate address {}", addr);
		dispatchPdu(addr, event.getPDU());
	} else {
		// Need to change the port to 161, which is what the bindings are configured for since
		// at least some SNMP devices send traps from a random port number. Otherwise the trap
		// won't be found as the address check will fail. It feels like there should be a better
		// way to do this!!!
		Address address = GenericAddress.parse("udp:" + s + "/161");
		dispatchPdu(address, event.getPDU());
	}
}
 
开发者ID:andrey-desman,项目名称:openhab-hdl,代码行数:26,代码来源:SnmpBinding.java

示例2: processPdu

import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
/**
 * Will be called whenever a {@link PDU} is received on the given port
 * specified in the listen() method. It extracts a {@link Variable}
 * according to the configured OID prefix and sends its value to the event
 * bus.
 */
@Override
public void processPdu(CommandResponderEvent event) {
    Address addr = event.getPeerAddress();
    if (addr == null) {
        return;
    }

    String s = addr.toString().split("/")[0];
    if (s == null) {
        logger.error("TRAP: failed to translate address {}", addr);
        dispatchPdu(addr, event.getPDU());
    } else {
        // Need to change the port to 161, which is what the bindings are configured for since
        // at least some SNMP devices send traps from a random port number. Otherwise the trap
        // won't be found as the address check will fail. It feels like there should be a better
        // way to do this!!!
        Address address = GenericAddress.parse("udp:" + s + "/161");
        dispatchPdu(address, event.getPDU());
    }
}
 
开发者ID:openhab,项目名称:openhab1-addons,代码行数:27,代码来源:SnmpBinding.java

示例3: newTarget

import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
private SnmpTarget newTarget(CommandResponderEvent event) {
  SnmpTargetBase target = newTarget(event.getMessageProcessingModel());
  Address address = event.getPeerAddress();
  String uri = address.toString();
  int i = uri.indexOf('/');
  if (i == -1) i = uri.length();
  target.setAddress(uri.substring(0, i));
  return target;
}
 
开发者ID:soulwing,项目名称:tnm4j,代码行数:10,代码来源:Snmp4jNotificationEventFactory.java

示例4: processPdu

import org.snmp4j.CommandResponderEvent; //导入方法依赖的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()));
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:38,代码来源:Snmp4JTrapNotifier.java

示例5: processPdu

import org.snmp4j.CommandResponderEvent; //导入方法依赖的package包/类
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()));
    }
}
 
开发者ID:vishwaabhinav,项目名称:OpenNMS,代码行数:37,代码来源:Snmp4JTrapNotifier.java


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