@Override public String getSourceType() { return listener.getSourceType(); }
/** * This method should be call to identify the probe used to store a received * external input. It uses result from identifyHost and identifyProbe to * find it. * * @param message the external input * @return the probe where values will be stored */ protected PassiveProbe<KeyType> findProbe(Message message) { String hostname = identifyHost(message); String probename = identifyProbe(message); log(Level.DEBUG, "looking for %s in %s", message, probes); if(!probes.containsKey(hostname)) { log(Level.WARN, "unregistered sender: %s", hostname); return null; } PassiveProbe<KeyType> pp = probes.get(hostname).get(probename); if(pp == null) { log(Level.WARN, "unregistered probe: %s", probename); return null; } return pp; }
@Override public void stop() { super.stop(); try { snmp.close(); } catch (IOException e) { } snmp = null; }
@Override public void run() { long lastsleep = 500; while (Listener.this.isStarted() && !isInterrupted()) { Date startListen = new Date(); try { Listener.this.listen(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } catch (Exception e) { Date failedListen = new Date(); if((failedListen.getTime() - startListen.getTime() < lastsleep)) lastsleep *= 2; else lastsleep = 500; try { Thread.sleep(lastsleep); } catch (InterruptedException e1) { Thread.currentThread().interrupt(); break; } log(Level.ERROR, e, "Listener thread failed: %s", e.getMessage()); } } } };
public void configure() { setName(jrds.Util.parseTemplate(getPd().getProbeName(), this)); if(listener != null) { listener.register(this); } }
@Override public boolean start() { try { TransportMapping<?> transport = null; if(UDP.equals(proto)) { UdpAddress listenAddress = new UdpAddress(port); transport = new DefaultUdpTransportMapping(listenAddress, true); } if(transport != null) { snmp = new Snmp(transport); snmp.addCommandResponder(trapReceiver); transport.listen(); } else { log(Level.ERROR, "unsupported UDP listener protocol: %s", proto); return false; } return super.start(); } catch (IOException e) { log(Level.ERROR, e, "failed to start the trap listener: %s", e.getMessage()); return false; } }