/** * Pings a peer. * * @param peerAddress The peer address of the remote peer. * @param isUDP Set to true if UDP should be used, false for TCP. * @return The future response */ public FutureResponse ping(PeerAddress peerAddress, final boolean isUDP) { final RequestHandler<FutureResponse> request = peer.pingRPC().ping(peerAddress, connectionConfiguration); if (isUDP) { FutureChannelCreator fcc = peer.connectionBean().reservation().create(1, 0); fcc.addListener( new BaseFutureAdapter<FutureChannelCreator>() { @Override public void operationComplete(final FutureChannelCreator future) throws Exception { if (future.isSuccess()) { FutureResponse futureResponse = request.sendUDP(future.channelCreator()); Utils.addReleaseListener(future.channelCreator(), futureResponse); } else { request.futureResponse().failed(future); } } }); } else { FutureChannelCreator fcc = peer.connectionBean().reservation().create(0, 1); fcc.addListener( new BaseFutureAdapter<FutureChannelCreator>() { @Override public void operationComplete(final FutureChannelCreator future) throws Exception { if (future.isSuccess()) { FutureResponse futureResponse = request.sendTCP(future.channelCreator()); Utils.addReleaseListener(future.channelCreator(), futureResponse); } else { request.futureResponse().failed(future); } } }); } return request.futureResponse(); }
public FutureResponse pingPeerConnection(final PeerConnection peerConnection) { final RequestHandler<FutureResponse> request = peer.pingRPC().ping(peerConnection.remotePeer(), connectionConfiguration); FutureChannelCreator futureChannelCreator = peerConnection.acquire(request.futureResponse()); futureChannelCreator.addListener( new BaseFutureAdapter<FutureChannelCreator>() { @Override public void operationComplete(FutureChannelCreator future) throws Exception { if (future.isSuccess()) { request.futureResponse().request().keepAlive(true); request.sendTCP(peerConnection); } else { request.futureResponse().failed(future); } } }); return request.futureResponse(); }