if (monitor.getType() != NodeType.MONITOR) {
throw EnvironmentFailureException.unexpectedState
("Node type must be Monitor not: " + monitor.getType());
}
MasterValue masterValue = Learner.findMaster(electionsProtocol,
helperSockets,
logger,
null,
formatter);
InetSocketAddress masterAddress =
new InetSocketAddress(masterValue.getHostName(),
masterValue.getPort());
MessageExchange me = groupProtocol.new MessageExchange
(masterAddress,
GroupService.SERVICE_NAME,
groupProtocol.new EnsureNode(monitor));
me.run();
ResponseMessage resp = me.getResponseMessage();
if (resp instanceof EnsureOK) {
EnsureOK okResp = (EnsureOK) resp;
monitor.getNameIdPair().update(okResp.getNameIdPair());
return new RepNodeImpl(new NameIdPair(masterValue.getNodeName()),
NodeType.ELECTABLE,
masterValue.getHostName(),
masterValue.getPort());
}
throw getException(resp);
}