diff --git a/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java b/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java index 4c22556d7..a8024cc62 100644 --- a/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java +++ b/examples/src/main/java/org/bitcoinj/examples/FetchTransactions.java @@ -22,10 +22,10 @@ import org.bitcoinj.params.TestNet3Params; import org.bitcoinj.store.BlockStore; import org.bitcoinj.store.MemoryBlockStore; import org.bitcoinj.utils.BriefLogFormatter; -import com.google.common.util.concurrent.ListenableFuture; import java.net.InetAddress; import java.util.List; +import java.util.concurrent.Future; /** * Downloads the given transaction and its dependencies from a peers memory pool then prints them out. @@ -45,7 +45,7 @@ public class FetchTransactions { Peer peer = peerGroup.getConnectedPeers().get(0); Sha256Hash txHash = Sha256Hash.wrap(args[0]); - ListenableFuture future = peer.getPeerMempoolTransaction(txHash); + Future future = peer.getPeerMempoolTransaction(txHash); System.out.println("Waiting for node to send us the requested transaction: " + txHash); Transaction tx = future.get(); System.out.println(tx); diff --git a/examples/src/main/java/org/bitcoinj/examples/PrintPeers.java b/examples/src/main/java/org/bitcoinj/examples/PrintPeers.java index 81bb5329c..29813b915 100644 --- a/examples/src/main/java/org/bitcoinj/examples/PrintPeers.java +++ b/examples/src/main/java/org/bitcoinj/examples/PrintPeers.java @@ -28,13 +28,12 @@ import org.bitcoinj.net.NioClientManager; import org.bitcoinj.params.MainNetParams; import org.bitcoinj.utils.BriefLogFormatter; import com.google.common.util.concurrent.Futures; -import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; /** @@ -77,13 +76,13 @@ public class PrintPeers { final Object lock = new Object(); final long[] bestHeight = new long[1]; - List> futures = new ArrayList<>(); + List> futures = new ArrayList<>(); NioClientManager clientManager = new NioClientManager(); for (final InetAddress addr : addrs) { InetSocketAddress address = new InetSocketAddress(addr, params.getPort()); final Peer peer = new Peer(params, new VersionMessage(params, 0), new PeerAddress(params, address), null); - final SettableFuture future = SettableFuture.create(); + final CompletableFuture future = new CompletableFuture<>(); // Once the connection has completed version handshaking ... peer.addConnectedEventListener((p, peerCount) -> { // Check the chain height it claims to have. @@ -102,18 +101,18 @@ public class PrintPeers { } } // Now finish the future and close the connection - future.set(null); + future.complete(null); peer.close(); }); peer.addDisconnectedEventListener((p, peerCount) -> { if (!future.isDone()) System.out.println("Failed to talk to " + addr); - future.set(null); + future.complete(null); }); clientManager.openConnection(address, peer); futures.add(future); } // Wait for every tried connection to finish. - Futures.successfulAsList(futures).get(); + CompletableFuture.allOf(futures.toArray( new CompletableFuture[0])).join(); } }