int length = socketChannel.read(byteBufferSize);
if (length > 0) {
if (byteBufferSize.hasRemaining()) {
if ((System.currentTimeMillis() - beginTime) > timeoutMillis) {
// 接收应答超时
throw new RemotingTimeoutException(addr, timeoutMillis);
}
}
}
else {
throw new RemotingTimeoutException(addr, timeoutMillis);
}
// 比较土
Thread.sleep(1);
}
// 接收应答 BODY
int size = byteBufferSize.getInt(0);
ByteBuffer byteBufferBody = ByteBuffer.allocate(size);
while (byteBufferBody.hasRemaining()) {
int length = socketChannel.read(byteBufferBody);
if (length > 0) {
if (byteBufferBody.hasRemaining()) {
if ((System.currentTimeMillis() - beginTime) > timeoutMillis) {
// 接收应答超时
throw new RemotingTimeoutException(addr, timeoutMillis);
}
}
}
else {
throw new RemotingTimeoutException(addr, timeoutMillis);
}
// 比较土
Thread.sleep(1);
}
// 对应答数据解码
byteBufferBody.flip();
return RemotingCommand.decode(byteBufferBody);
}
catch (IOException e) {
e.printStackTrace();
if (sendRequestOK) {
throw new RemotingTimeoutException(addr, timeoutMillis);
}
else {
throw new RemotingSendRequestException(addr);
}
}