private Protocol checkProtocol(Protocol candidateProtocol)
throws IOException, ProtocolException {
candidateProtocol.write
(candidateProtocol.new ClientVersion(), channel);
ServerVersion serverVersion =
candidateProtocol.read(channel, Protocol.ServerVersion.class);
if (serverVersion.getVersion() != candidateProtocol.getVersion()) {
String message = "Server requested protocol version:"
+ serverVersion.getVersion()
+ " but the client version is " +
candidateProtocol.getVersion();
logger.info(message);
throw new ProtocolException(message);
}