// TODO(peis): Fix this, we should not assert here.
@Override
  public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg)
      throws IOException {
    switch (msg.getType()) {
      case RPC_BLOCK_READ_REQUEST:
        assert msg instanceof RPCBlockReadRequest;
        mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
        break;
      case RPC_BLOCK_WRITE_REQUEST:
        assert msg instanceof RPCBlockWriteRequest;
        mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
        break;
      case RPC_FILE_READ_REQUEST:
        assert msg instanceof RPCFileReadRequest;
        mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
        break;
      case RPC_FILE_WRITE_REQUEST:
        assert msg instanceof RPCFileWriteRequest;
        mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
        break;
      case RPC_ERROR_RESPONSE:
        // TODO(peis): Fix this, we should not assert here.
        assert msg instanceof RPCErrorResponse;
        LOG.error("Received an error response from the client: " + msg.toString());
        break;
      default:
        RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
        ctx.writeAndFlush(resp);
        // TODO(peis): Fix this. We should not throw an exception here.
        throw new IllegalArgumentException(
            "No handler implementation for rpc msg type: " + msg.getType());
    }
  }
break;
case RPC_ERROR_RESPONSE:
// TODO(peis): Fix this, we should not assert here.
assert msg instanceof RPCErrorResponse;
LOG.error("Received an error response from the client: " + msg.toString());
break;
case RPC_FILE_READ_REQUEST:
assert msg instanceof RPCFileReadRequest;
mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
break;
case RPC_FILE_WRITE_REQUEST:
assert msg instanceof RPCFileWriteRequest;
mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
break;
case RPC_ERROR_RESPONSE:
// TODO(peis): Fix this, we should not assert here.
assert msg instanceof RPCErrorResponse;
LOG.error("Received an error response from the client: " + msg.toString());
break;
default:
RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
ctx.writeAndFlush(resp);
// TODO(peis): Fix this. We should not throw an exception here.
throw new IllegalArgumentException(
"No handler implementation for rpc msg type: " + msg.getType());
}
public void channelRead0(final ChannelHandlerContext ctx, final RPCMessage msg)
throws IOException {
switch (msg.getType()) {
case RPC_BLOCK_READ_REQUEST:
assert msg instanceof RPCBlockReadRequest;
mBlockHandler.handleBlockReadRequest(ctx, (RPCBlockReadRequest) msg);
break;
case RPC_BLOCK_WRITE_REQUEST:
assert msg instanceof RPCBlockWriteRequest;
mBlockHandler.handleBlockWriteRequest(ctx, (RPCBlockWriteRequest) msg);
break;
case RPC_FILE_READ_REQUEST:
assert msg instanceof RPCFileReadRequest;
mUnderFileSystemHandler.handleFileReadRequest(ctx, (RPCFileReadRequest) msg);
break;
case RPC_FILE_WRITE_REQUEST:
assert msg instanceof RPCFileWriteRequest;
mUnderFileSystemHandler.handleFileWriteRequest(ctx, (RPCFileWriteRequest) msg);
break;
case RPC_ERROR_RESPONSE:
// TODO(peis): Fix this, we should not assert here.
assert msg instanceof RPCErrorResponse;
LOG.error("Received an error response from the client: " + msg.toString());
break;
default:
RPCErrorResponse resp = new RPCErrorResponse(RPCResponse.Status.UNKNOWN_MESSAGE_ERROR);
ctx.writeAndFlush(resp);
// TODO(peis): Fix this. We should not throw an exception here.
throw new IllegalArgumentException(
"No handler implementation for rpc msg type: " + msg.getType());
}
}