}
/** Processes the received message. */
private void bytesReceived(byte[] buffer) {
MessageBuffer msg = new MessageBuffer(buffer);
byte opcode = msg.getByte();
if (logger.isLoggable(Level.FINEST)) {
logger.log(
Level.FINEST,
"processing opcode 0x{0}",
Integer.toHexString(opcode));
}
switch (opcode) {
case SimpleSgsProtocol.LOGIN_REQUEST:
byte version = msg.getByte();
if (version != SimpleSgsProtocol.VERSION) {
if (logger.isLoggable(Level.SEVERE)) {
logger.log(Level.SEVERE,
"got protocol version:{0}, " +
"expected {1}", version, SimpleSgsProtocol.VERSION);
}
disconnect();
break;
}
final String name = msg.getString();
final String password = msg.getString();
try {
identity = acceptor.authenticate(name, password);
} catch (Exception e) {
logger.logThrow(
Level.FINEST, e,
"login authentication failed for name:{0}", name);
loginFailure("login failed", e);
break;
}
listener.newLogin(
identity, SimpleSgsProtocolImpl.this, new LoginHandler());
// Resume reading immediately
read();
break;
case SimpleSgsProtocol.SESSION_MESSAGE:
ByteBuffer clientMessage =
ByteBuffer.wrap(msg.getBytes(msg.limit() - msg.position()));
if (protocolHandler == null) {
// ignore message before authentication
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,
"Dropping early session message:{0} " +
"for protocol:{1}",
HexDumper.format(clientMessage, 0x50),
SimpleSgsProtocolImpl.this);
}
return;
}
// TBD: schedule a task to process this message?
protocolHandler.sessionMessage(clientMessage,
new RequestHandler());
break;
case SimpleSgsProtocol.CHANNEL_MESSAGE:
BigInteger channelRefId =
new BigInteger(1, msg.getBytes(msg.getShort()));
ByteBuffer channelMessage =
ByteBuffer.wrap(msg.getBytes(msg.limit() - msg.position()));
if (protocolHandler == null) {
// ignore message before authentication
if (logger.isLoggable(Level.FINE)) {
logger.log(
Level.FINE,