I am looking for Apache Storm's source code and I encountered something which I never seen: CLOSE_MESSAGE((short)-100) or CLOSE_MESSAGE((short)-100). Why one should subtract someNumber from short type? What does it mean? Here is actual code:
enum ControlMessage {
CLOSE_MESSAGE((short)-100),
EOB_MESSAGE((short)-201),
OK_RESPONSE((short)-200),
FAILURE_RESPONSE((short)-400),
SASL_TOKEN_MESSAGE_REQUEST((short)-202),
SASL_COMPLETE_REQUEST((short)-203);
private short code;
//private constructor
private ControlMessage(short code) {
this.code = code;
}
/**
* Return a control message per an encoded status code
* @param encoded
* @return
*/
static ControlMessage mkMessage(short encoded) {
for(ControlMessage cm: ControlMessage.values()) {
if(encoded == cm.code) return cm;
}
return null;
}
int encodeLength() {
return 2; //short
}
/**
* encode the current Control Message into a channel buffer
* @throws Exception
*/
ChannelBuffer buffer() throws IOException {
ChannelBufferOutputStream bout = new ChannelBufferOutputStream(ChannelBuffers.directBuffer(encodeLength()));
write(bout);
bout.close();
return bout.buffer();
}
void write(ChannelBufferOutputStream bout) throws IOException {
bout.writeShort(code);
}
}