Developers guide

128
buffer = new BufferedReader(reader,1);
readerThread = new StdErrReader();
readerThread.start();
running = true;
logger.log( Level.INFO, "Linux SnmpTrapDaemon Started");
fireSnmpTrapDaemonStarted();
} catch (IOException e) {
logger.log( Level.INFO, "Could not start Linuz SnmpTrapDaemon, IO err",e);
}
} else {
logger.log( Level.INFO, "Linux SnmpTrapDaemon Stopped");
}
}
/**
* Stop listening to SNMP traps
* <p>
* Kill the <code>/usr/sbin/snmptrapd</code> process
* <p>
* This will trigger the {@link apt.masterswitch.snmp.SnmpTrapListener#snmpTrapDaemonStopped() }
* method to be called on registered {@link apt.masterswitch.snmp.SnmpTrapListener SnmpTrapListeners}
*/
public void stop() {
if( running ) {
running = false;
readerThread.requestStop();
proc.destroy();
proc = null;
buffer = null;
logger.log( Level.INFO, "Linux SnmpTrapDaemon Stopped");
fireSnmpTrapDaemonStopped();
} else {
log.log(Level.WARNING, "Cannot Stop snmptrapd, it is not running");
}
}
private class StdErrReader extends Thread {
private volatile boolean stopRequested;
public StdErrReader() {
stopRequested = false;
}
public void requestStop() {
stopRequested = true;
}
public void run() {
running = true;
while( !stopRequested ) {
String trapMsg = "";
try {
/**
* Execution of this thread will block
* here until a new line is read
*/
trapMsg = buffer.readLine();
} catch (IOException e) {
log.log(Level.WARNING, "I/O Error while reading stdout of snmptrapd",e );
}
log.log(Level.INFO, trapMsg );
fireSnmpTrapReceived();
}
try {
buffer.close();
} catch (IOException e) {
// The proc was probably killed
}
}