* @param message
* @param config
* @return
*/
public static FutureResponse connectAndSend(final Peer peer, final Message message, final ConnectionConfiguration config) {
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(), config, futureResponse);
} else {
futureResponse.failed(fpc);
}
}
});
return futureResponse;