/** * Opens a new peer connection to the receiver and sends the message through it. * * @param peer * @param message * @param config * @return */ public static FutureResponse connectAndSend(final Peer peer, final Message message) { final FutureResponse futureResponse = new FutureResponse(message); final FuturePeerConnection fpc = peer.createPeerConnection(message.recipient()); fpc.addListener( new BaseFutureAdapter<FuturePeerConnection>() { public void operationComplete(final FuturePeerConnection futurePeerConnection) throws Exception { if (futurePeerConnection.isSuccess()) { // successfully created a connection to the other peer final PeerConnection peerConnection = futurePeerConnection.object(); // send the message send(peerConnection, peer.peerBean(), peer.connectionBean(), futureResponse); } else { futureResponse.failed(fpc); } } }); return futureResponse; }