Developers guide
114
throw new MasterswitchException("Cannot initialise Masterswitch",e);
} catch (FileNotFoundException e) {
log.log(Level.WARNING, "Cannot load \""+MIB_FILENAME+"\", File not found ",e);
throw new MasterswitchException("Cannot initialise Masterswitch",e);
}
timer = new Timer(true);
// Initialise Trap Listener on port 162
log.log(Level.INFO, "Attempting to start SNMP Trap Daemon for event notification...");
// Java Snmp Trap Daemon
// SnmpTrapDaemon trapd = SnmpTrapDaemonImpl.getInstance();
SnmpTrapDaemon trapd = LinuxSnmpTrapDaemonImpl.instance;
trapd.addSnmpTrapListener(this);
trapd.start();
// If the trapd cannot be started it will fire a snmpTrapDaemonStopped()
// event. This SNMPMasterswitch will then use a polling technique for
// monitoring state changes on the masterswitch device.
// The apt.masterswitch.masterswitch object has successfully been loaded
loaded = true;
log.log(Level.INFO, "Masterswitch successfully loaded");
}
private boolean isLoaded() {
return loaded;
}
private synchronized void unload() {
if( watcherRunning ) {
timer.cancel();
watcherRunning = false;
}
try {
session.close();
// Shutdown the Trap Listener on port 162, if its running
SnmpTrapDaemon trapd = SnmpTrapDaemonImpl.getInstance();
// remove listener before stopping because
// trapDStopped event will cause the SNMPMasterswitch to
// start polling the masterswitch..
trapd.removeSnmpTrapListener(this);
trapd.stop();
} catch (Exception e1) {
log.log(Level.WARNING, "Could not close the snmp session while unloading");
}
session = null;
mibModule = null;
value = null;
timer = null;
loaded = false;
log.log(Level.INFO, "Masterswitch successfully unloaded");
}
private SnmpSyntax doSNMPGet( String oid ) throws MasterswitchException {
SnmpVarBind[] vblist = { new SnmpVarBind(oid) };
SnmpPduRequest pdu = new SnmpPduRequest(SnmpPduPacket.GET, vblist);
log.log(Level.FINE, "SNMP Get OID = "+oid);
return doSNMP( pdu );
}










