- try (final Snmp snmp = new Snmp(dispatcher, snmpTarget)) {
- snmp.addCommandResponder(this);
- snmpTarget.listen();
- LOG.debug("Listening on {}", snmpTarget);
- wait();
- } catch (final InterruptedException | IOException ex) {
- Thread.currentThread().interrupt();
- }
- }
-
- /**
- * This method will be called whenever a pdu is received on the given port
- * specified in the listen() method.
- */
- @Override
- public synchronized void processPdu(final CommandResponderEvent cmdRespEvent) {
- LOG.info("Received PDU");
- final PDU pdu = cmdRespEvent.getPDU();
- if (pdu == null) {
- LOG.warn("Ignoring PDU.");
- return;
- }
-
- final UdpAddress address = (UdpAddress) cmdRespEvent.getPeerAddress();
- final ZoneId optZoneId = timeZoneOffsetService.getTimeZone(address.getInetAddress().getHostAddress());
- final String timeZone = Optional.ofNullable(optZoneId)
- .map(zoneId -> "UTC" + LocalDateTime.now().atZone(zoneId).getOffset().toString()).orElse(null);
-
- mapper.toEvent(address, timeZone, pdu)
- .flatMapCompletable(vesEventNotifier::notifyEvents)
- .doOnSubscribe(result -> LOG.debug("SNMP Trap processing started"))
- .doOnComplete(() -> LOG.debug("SNMP Trap processed successfully"))
- .doOnError(error -> LOG.error("Failed to process SNMP Trap", error))
- .subscribe();
+ do {
+ try (final var snmp = new Snmp(dispatcher, snmpTarget)) {
+ snmp.addCommandResponder(commandResponder);
+ snmpTarget.listen();
+ LOG.debug("Listening on {}", snmpTarget);
+ wait();
+ } catch (final InterruptedException | IOException ex) {
+ Thread.currentThread().interrupt();
+ }
+ } while (snmpTarget.isListening());