use of org.snmp4j.util.MultiThreadedMessageDispatcher in project LogHub by fbacchella.
the class SnmpTrap method configure.
@Override
public boolean configure(Properties properties) {
decoder = Receiver.NULLDECODER;
if (!reconfigured && properties.containsKey("mibdirs")) {
reconfigured = true;
String[] mibdirs = null;
try {
mibdirs = Arrays.stream((Object[]) properties.get("mibdirs")).map(i -> i.toString()).toArray(String[]::new);
formatter = OIDFormatter.register(mibdirs);
} catch (ClassCastException e) {
logger.error("mibdirs property is not a string array");
logger.catching(Level.DEBUG, e.getCause());
return false;
}
} else {
formatter = OIDFormatter.register();
}
threadPool = ThreadPool.create("Trap", 2);
MultiThreadedMessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
dispatcher.addCommandResponder(this);
dispatcher.addMessageProcessingModel(new MPv1());
dispatcher.addMessageProcessingModel(new MPv2c());
Address listenAddress = GenericAddress.parse(protocol + ":" + listen + "/" + port);
TransportMapping<?> transport;
try {
transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);
} catch (IOException e) {
logger.error("can't bind to {}: {}", listenAddress, e.getMessage());
return false;
}
snmp = new Snmp(dispatcher, transport);
try {
snmp.listen();
} catch (IOException e) {
logger.error("can't listen: {}", e.getMessage());
}
return super.configure(properties);
}
Aggregations