Developers guide
115
private SnmpSyntax doSNMPSet( String oid, SnmpSyntax data ) throws MasterswitchException {
SnmpVarBind[] vblist = { new SnmpVarBind(oid,data) };
SnmpPduRequest pdu = new SnmpPduRequest(SnmpPduPacket.SET, vblist);
log.log(Level.FINE, "SNMP Set OID = "+oid+": " + data);
return doSNMP( pdu );
}
private SnmpSyntax doSNMP( SnmpPduRequest pdu ) throws MasterswitchException {
pdu.setRequestId(SnmpPduPacket.nextSequence());
// get a lock on the session object,
// this ensures that another pdu cannot be sent until
// the previous one has been received.
synchronized(session) {
try {
waitingForResponse = true;
session.send(pdu);
while( waitingForResponse ) {
session.wait();
}
// This should be woken up by an SnmpHandlerMethod which has
// setup the "value" variable which contains the result of
// the SNMP request, Also the thread which received the response
// must waitingForResponse = false
} catch (Exception e ) {
e.printStackTrace();
}
}
if( value == null ) {
// There was an error
log.log(Level.INFO, "SNMP returned a Null value");
throw new MasterswitchException("An SNMP error prevented communication with the Masterswitch");
}
return value;
}
public synchronized String getOutletName(int outlet) throws MasterswitchException {
checkOutlet(outlet);
String oid = mibModule.getNode(sPDUOutletName).getOID().toJavaValue() + "."+outlet;
String outletName = doSNMPGet(oid).toString();
return outletName;
}
public synchronized String getOutletState(int outlet) throws MasterswitchException {
checkOutlet(outlet);
String oid = mibModule.getNode(sPDUOutletCtl).getOID().toJavaValue() + "."+outlet;
SnmpInt32 outletState = (SnmpInt32)doSNMPGet(oid);
int outletSnmpState = outletState.getValue();
String outletStateStr = outletIntToOutletStr( outletSnmpState );
return outletStateStr;
}
/**
* This converts an outlet state as an integer constant defined in
* {@link apt.masterswitch.snmp.SNMPMasterswitch } to an equivalent
* String constant as defined
* in {@link apt.masterswitch.Masterswitch }
* <p>
* Note: String constants are used to make error messages more readable.
*/
private String outletIntToOutletStr(int outletInt ) {
if( outletInt == SNMP_OUTLET_ON ) {
return OUTLET_ON;










