public void join() throws NodeException {
RemoteNodeConnection connection =
new RemoteNodeJoinerConnection(remoteNodeInfo, ioContext, sm);
setConnection(connection);
Msg msg = new Msg();
MsgHeader header = msg.getHeader();
header.addHeader(MsgHeaderConstants.SRC_NODE, localNodeInfo);
header.addHeader(MsgHeaderConstants.DEST_NODE, remoteNodeInfo);
// Only set to comply with a valid request.
header.addHeader(MsgHeaderConstants.DEST_NODES, remoteNodeInfo);
header.addHeader(MsgHeaderConstants.SRC_ENDPOINT, "");
header.addHeader(MsgHeaderConstants.CORRELATION_ID,
new RequestSender.RequestID((byte) 0));
header.addHeader(MsgHeaderConstants.BODY_TYPE, MsgBody.Type.REQUEST);
header.addHeader(MsgHeaderConstants.TOPOLOGY_VERSION, new Integer(0));
msg.getBody().setContent(localNodeInfo);
final FutureResult result = new FutureResult();
setMsgProducerOut(new MsgOutInterceptor() {
public void push(Msg aMsg) {
result.set(aMsg);
}
});
getMsgConsumerOut().push(msg);
Msg reply;
try {
// waits 3 seconds for a reply.
reply = (Msg) result.get();
reply = (Msg) result.timedGet(3000);
} catch (TimeoutException e) {
throw new NodeException("Join request submitted by " +
localNodeInfo + " to " + remoteNodeInfo + " has timed out.");
} catch (InterruptedException e) {
throw new NodeException(e);
} catch (InvocationTargetException e) {
throw new NodeException(e);
}
Boolean isOK = (Boolean) reply.getBody().getContent();
if ( Boolean.FALSE == isOK ) {
throw new NodeException(remoteNodeInfo + " has refused the " +
"join request submitted by " + localNodeInfo);
}
manager.registerRemoteNode(this);