Developers guide
119
log.log(Level.WARNING, "An unexpected error occured with the SNMP Session");
log.log(Level.WARNING, "The error code is " + err);
value = null;
waitingForResponse = false;
// Wake up the blocking thread
synchronized(session) {
session.notifyAll();
}
}
public void snmpTrapDaemonStarted() {
log.log(Level.INFO, "Listening to SNMP traps...");
if( watcherRunning ) {
timer.cancel();
watcherRunning = false;
}
}
public void snmpTrapDaemonStopped() {
log.log(Level.INFO, "Not listening to SNMP traps");
log.log(Level.INFO, "Periodically polling Masterswitch for event notification");
timer.scheduleAtFixedRate( new MasterswitchWatcher(), 3000,3000 );
watcherRunning = true;
}
public void snmpTrapReceived() {
/**
* This simple implementation just says 'something'
* changed whenever we receive a trap.
*
* It could be improved by analysing the trap to see
* exactly what happened and generate a more specific event
*/
fireStateChanged();
}
/**
*
* The run method of this class will be periodically
* called to notify masterswitchListeners if anything has changed.
*
*/
private class MasterswitchWatcher extends TimerTask {
private String[] outletNames;
private String[] outletStates;
public MasterswitchWatcher() {
outletNames = new String[8];
outletStates = new String[8];
// Populate the cached values
try {
for (int i = 0; i < outletNames.length; i++) {
outletNames[i] = getOutletName(i+1);
}
for (int i = 0; i < outletStates.length; i++) {
outletStates[i] = getOutletState(i+1);
}
} catch (MasterswitchException e) {
log.log(Level.WARNING, "Problem while checking if the Masterswitch has changed state",e);
}
}
public void run() {
log.log( Level.INFO, "Checking Masterswitch for changes...");
try {
for (int i = 0; i < outletNames.length; i++) {
String currName = getOutletName(i+1);
if( !outletNames[i].equals( currName ) ) {
outletNames[i] = currName;










