Upgrade to Guava 16.0.1.

Resolves issue 375.
This commit is contained in:
Andreas Schildbach
2014-04-06 15:54:17 +02:00
committed by Mike Hearn
parent 9a54a7753d
commit 6087e43377
24 changed files with 210 additions and 82 deletions

View File

@@ -151,7 +151,7 @@
<!-- classifier is "null" if not present -->
<urns>
<urn>com.google.code.findbugs:jsr305:1.3.9:jar:null:compile:40719ea6961c0cb6afaeb6a921eaa1f6afd4cfdf</urn>
<urn>com.google.guava:guava:13.0.1:jar:null:compile:0d6f22b1e60a2f1ef99e22c9f5fde270b2088365</urn>
<urn>com.google.guava:guava:16.0.1:jar:null:compile:5fa98cd1a63c99a44dd8d3b77e4762b066a5d0c5</urn>
<urn>com.google.protobuf:protobuf-java:2.5.0:jar:null:compile:a10732c76bfacdbd633a7eb0f7968b1059a65dfa</urn>
<urn>com.h2database:h2:1.3.167:jar:null:compile:d3867d586f087e53eb12fc65e5693d8ee9a5da17</urn>
<urn>com.lambdaworks:scrypt:1.3.3:jar:null:compile:06d6813de41e177189e1722717979b4fb5454b1d</urn>
@@ -254,7 +254,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0.1</version>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>

View File

@@ -1,5 +1,6 @@
/**
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -14,7 +15,6 @@
* limitations under the License.
*/
package com.google.bitcoin.core;
import com.google.bitcoin.net.ClientConnectionManager;
@@ -682,7 +682,8 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
protected void startUp() throws Exception {
// This is run in a background thread by the Service implementation.
vPingTimer = new Timer("Peer pinging thread", true);
channels.startAndWait();
channels.startAsync();
channels.awaitRunning();
triggerConnections();
}
@@ -691,7 +692,8 @@ public class PeerGroup extends AbstractExecutionThreadService implements Transac
// This is run on a separate thread by the Service implementation.
vPingTimer.cancel();
// Blocking close of all sockets.
channels.stopAndWait();
channels.stopAsync();
channels.awaitTerminated();
for (PeerDiscovery peerDiscovery : peerDiscoverers) {
peerDiscovery.shutdown();
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,6 +25,8 @@ import com.google.bitcoin.store.WalletProtobufSerializer;
import com.google.common.util.concurrent.AbstractIdleService;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.Service;
import java.io.File;
import java.io.FileInputStream;
@@ -228,26 +231,29 @@ public class WalletAppKit extends AbstractIdleService {
onSetupCompleted();
if (blockingStartup) {
vPeerGroup.startAndWait();
vPeerGroup.startAsync();
vPeerGroup.awaitRunning();
// Make sure we shut down cleanly.
installShutdownHook();
// TODO: Be able to use the provided download listener when doing a blocking startup.
final DownloadListener listener = new DownloadListener();
vPeerGroup.startBlockChainDownload(listener);
listener.await();
} else {
Futures.addCallback(vPeerGroup.start(), new FutureCallback<State>() {
vPeerGroup.startAsync();
vPeerGroup.addListener(new Service.Listener() {
@Override
public void onSuccess(State result) {
public void running() {
final PeerEventListener l = downloadListener == null ? new DownloadListener() : downloadListener;
vPeerGroup.startBlockChainDownload(l);
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
public void failed(State from, Throwable failure) {
throw new RuntimeException(failure);
}
});
}, MoreExecutors.sameThreadExecutor());
}
} catch (BlockStoreException e) {
throw new IOException(e);
@@ -264,7 +270,8 @@ public class WalletAppKit extends AbstractIdleService {
if (autoStop) Runtime.getRuntime().addShutdownHook(new Thread() {
@Override public void run() {
try {
WalletAppKit.this.stopAndWait();
WalletAppKit.this.stopAsync();
WalletAppKit.this.awaitTerminated();
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -276,7 +283,8 @@ public class WalletAppKit extends AbstractIdleService {
protected void shutDown() throws Exception {
// Runs in a separate thread.
try {
vPeerGroup.stopAndWait();
vPeerGroup.stopAsync();
vPeerGroup.awaitTerminated();
vWallet.saveToFile(vWalletFile);
vStore.close();

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -48,7 +49,7 @@ public class NioClient implements MessageWriteTarget {
@Override
public void connectionClosed() {
upstreamParser.connectionClosed();
manager.stop();
manager.stopAsync();
}
@Override
@@ -90,7 +91,8 @@ public class NioClient implements MessageWriteTarget {
*/
public NioClient(final SocketAddress serverAddress, final StreamParser parser,
final int connectTimeoutMillis) throws IOException {
manager.startAndWait();
manager.startAsync();
manager.awaitRunning();
handler = new Handler(parser, connectTimeoutMillis);
manager.openConnection(serverAddress, handler);
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -142,7 +143,8 @@ public class PaymentChannelServerListener {
return new ServerHandler(new InetSocketAddress(inetAddress, port), timeoutSeconds).socketProtobufHandler;
}
}, new InetSocketAddress(port));
server.startAndWait();
server.startAsync();
server.awaitRunning();
}
/**
@@ -176,6 +178,7 @@ public class PaymentChannelServerListener {
* wallet.</p>
*/
public void close() {
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Matt Corallo.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -142,7 +143,7 @@ public class BitcoindComparisonTool {
bitcoindChainHead = params.getGenesisBlock().getHash();
// Connect to bitcoind and make sure it has no blocks
peers.start();
peers.startAsync();
peers.setMaxConnections(1);
peers.downloadBlockChain();

View File

@@ -1,3 +1,20 @@
/**
* Copyright 2012 Matt Corallo
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.bitcoin.core;
import com.google.bitcoin.core.TransactionConfidence.ConfidenceType;
@@ -101,7 +118,8 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
peerGroup.addWallet(wallet);
blockChain.addWallet(wallet);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
// Create a peer.
InboundMessageQueuer p1 = connectPeer(1);
@@ -143,7 +161,7 @@ public class FilteredBlockAndPartialMerkleTreeTests extends TestWithPeerGroup {
// Peer 1 goes away.
closePeer(peerOf(p1));
peerGroup.stop();
peerGroup.stopAsync();
super.tearDown();
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,12 +99,14 @@ public class PeerGroupTest extends TestWithPeerGroup {
public void tearDown() throws Exception {
super.tearDown();
Utils.finishMockSleep();
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
}
@Test
public void listener() throws Exception {
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.addEventListener(listener);
// Create a couple of peers.
@@ -147,7 +150,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
public void shutdown() {
}
});
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
latch.await();
// Check that we did indeed throw an exception. If we got here it means we threw and then PeerGroup tried
// again a bit later.
@@ -157,7 +161,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void receiveTxBroadcast() throws Exception {
// Check that when we receive transactions on all our peers, we do the right thing.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
@@ -190,13 +195,15 @@ public class PeerGroupTest extends TestWithPeerGroup {
inbound(p2, new NotFoundMessage(unitTestParams, getdata.getItems()));
pingAndWait(p2);
assertEquals(value, wallet.getBalance(Wallet.BalanceType.ESTIMATED));
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
}
@Test
public void singleDownloadPeer1() throws Exception {
// Check that we don't attempt to retrieve blocks on multiple peers.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
@@ -232,7 +239,7 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Peer 2 fetches it next time it hears an inv (should it fetch immediately?).
inbound(p2, inv);
assertTrue(outbound(p2) instanceof GetDataMessage);
peerGroup.stop();
peerGroup.stopAsync();
}
@Test
@@ -240,7 +247,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Check that we don't attempt multiple simultaneous block chain downloads, when adding a new peer in the
// middle of an existing chain download.
// Create a couple of peers.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
@@ -269,14 +277,15 @@ public class PeerGroupTest extends TestWithPeerGroup {
InboundMessageQueuer p2 = connectPeer(2);
Message message = (Message)outbound(p2);
assertNull(message == null ? "" : message.toString(), message);
peerGroup.stop();
peerGroup.stopAsync();
}
@Test
public void transactionConfidence() throws Exception {
// Checks that we correctly count how many peers broadcast a transaction, so we can establish some measure of
// its trustworthyness assuming an untampered with internet connection.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
final Transaction[] event = new Transaction[2];
peerGroup.addEventListener(new AbstractPeerEventListener() {
@@ -338,7 +347,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
// The wallet was already added to the peer in setup.
final int WEEK = 86400 * 7;
final long now = Utils.currentTimeSeconds();
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000);
Wallet w2 = new Wallet(params);
ECKey key1 = new ECKey();
@@ -358,7 +368,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void noPings() throws Exception {
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.setPingIntervalMsec(0);
VersionMessage versionMessage = new VersionMessage(params, 2);
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
@@ -370,7 +381,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void pings() throws Exception {
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.setPingIntervalMsec(100);
VersionMessage versionMessage = new VersionMessage(params, 2);
versionMessage.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
@@ -388,7 +400,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void downloadPeerSelection() throws Exception {
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
VersionMessage versionMessage2 = new VersionMessage(params, 2);
versionMessage2.clientVersion = FilteredBlock.MIN_PROTOCOL_VERSION;
versionMessage2.localServices = VersionMessage.NODE_NETWORK;
@@ -420,7 +433,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void peerTimeoutTest() throws Exception {
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.setConnectTimeoutMillis(100);
final SettableFuture<Void> peerConnectedFuture = SettableFuture.create();
@@ -459,7 +473,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
});
peerGroup.setMaxConnections(3);
Utils.setMockSleep(true);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
handleConnectToPeer(0);
handleConnectToPeer(1);
@@ -512,7 +527,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
// Cover bug 513. When a relevant transaction with a p2pubkey output is found, the Bloom filter should be
// recalculated to include that transaction hash but not re-broadcast as the remote nodes should have followed
// the same procedure. However a new node that's connected should get the fresh filter.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
final ECKey key = wallet.getKeys().get(0);
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
@@ -542,7 +558,8 @@ public class PeerGroupTest extends TestWithPeerGroup {
@Test
public void testBloomResendOnNewKey() throws Exception {
// Check that when we add a new key to the wallet, the Bloom filter is re-calculated and re-sent.
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
// Create a couple of peers.
InboundMessageQueuer p1 = connectPeer(1);
InboundMessageQueuer p2 = connectPeer(2);

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -89,8 +90,10 @@ public class TestWithNetworkConnections {
blockChain = new BlockChain(unitTestParams, wallet, blockStore);
startPeerServers();
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER)
channels.startAndWait();
if (clientType == ClientType.NIO_CLIENT_MANAGER || clientType == ClientType.BLOCKING_CLIENT_MANAGER) {
channels.startAsync();
channels.awaitRunning();
}
socketAddress = new InetSocketAddress("127.0.0.1", 1111);
}
@@ -118,7 +121,8 @@ public class TestWithNetworkConnections {
};
}
}, new InetSocketAddress("127.0.0.1", 2000 + i));
peerServers[i].startAndWait();
peerServers[i].startAsync();
peerServers[i].awaitRunning();
}
public void tearDown() throws Exception {
@@ -132,7 +136,8 @@ public class TestWithNetworkConnections {
}
protected void stopPeerServer(int i) {
peerServers[i].stopAndWait();
peerServers[i].stopAsync();
peerServers[i].awaitTerminated();
}
protected InboundMessageQueuer connect(Peer peer, VersionMessage versionMessage) throws Exception {

View File

@@ -1,5 +1,6 @@
/**
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -58,13 +59,15 @@ public class TransactionBroadcastTest extends TestWithPeerGroup {
// Fix the random permutation that TransactionBroadcast uses to shuffle the peers.
TransactionBroadcast.random = new Random(0);
peerGroup.setMinBroadcastConnections(2);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
}
@After
public void tearDown() throws Exception {
super.tearDown();
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
}
@Test

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -53,10 +54,10 @@ public class NetworkAbstractionTests {
this.clientType = clientType;
if (clientType == 0) {
channels = new NioClientManager();
channels.start();
channels.startAsync();
} else if (clientType == 1) {
channels = new BlockingClientManager();
channels.start();
channels.startAsync();
} else
channels = null;
}
@@ -117,7 +118,8 @@ public class NetworkAbstractionTests {
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
}
}, new InetSocketAddress("localhost", 4243));
server.startAndWait();
server.startAsync();
server.awaitRunning();
ProtobufParser<Protos.TwoWayChannelMessage> clientHandler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@@ -154,7 +156,8 @@ public class NetworkAbstractionTests {
serverConnectionClosed.get();
clientConnectionClosed.get();
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
assertFalse(server.isRunning());
}
@@ -199,7 +202,8 @@ public class NetworkAbstractionTests {
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 10);
}
}, new InetSocketAddress("localhost", 4243));
server.startAndWait();
server.startAsync();
server.awaitRunning();
openConnection(new InetSocketAddress("localhost", 4243), new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@@ -254,7 +258,8 @@ public class NetworkAbstractionTests {
clientConnection2Closed.get();
serverConnection2Closed.get();
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
}
@Test
@@ -289,7 +294,8 @@ public class NetworkAbstractionTests {
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 0x10000, 0);
}
}, new InetSocketAddress("localhost", 4243));
server.startAndWait();
server.startAsync();
server.awaitRunning();
ProtobufParser<Protos.TwoWayChannelMessage> clientHandler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@@ -397,7 +403,8 @@ public class NetworkAbstractionTests {
serverConnectionClosed.get();
clientConnectionClosed.get();
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
}
@Test
@@ -451,7 +458,8 @@ public class NetworkAbstractionTests {
}, Protos.TwoWayChannelMessage.getDefaultInstance(), 1000, 0);
}
}, new InetSocketAddress("localhost", 4243));
server.startAndWait();
server.startAsync();
server.awaitRunning();
ProtobufParser<Protos.TwoWayChannelMessage> client1Handler = new ProtobufParser<Protos.TwoWayChannelMessage>(
new ProtobufParser.Listener<Protos.TwoWayChannelMessage>() {
@@ -538,16 +546,18 @@ public class NetworkAbstractionTests {
// Try to create a race condition by triggering handlerThread closing and client3 closing at the same time
// This often triggers ClosedByInterruptException in handleKey
server.stop();
server.stopAsync();
server.selector.wakeup();
client3.closeConnection();
client3ConnectionClosed.get();
serverConnectionClosed3.get();
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
client2ConnectionClosed.get();
serverConnectionClosed2.get();
server.stopAndWait();
server.stopAsync();
server.awaitTerminated();
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -73,7 +74,8 @@ public class ExamplePaymentChannelClient {
wallet().addExtension(new StoredPaymentChannelClientStates(wallet(), peerGroup()));
}
};
appKit.startAndWait();
appKit.startAsync();
appKit.awaitRunning();
// We now have active network connections and a fully synced wallet.
// Add a new key which will be used for the multisig contract.
appKit.wallet().addKey(myKey);
@@ -103,7 +105,8 @@ public class ExamplePaymentChannelClient {
log.info("Waiting ...");
Thread.sleep(60 * 60 * 1000); // 1 hour.
log.info("Stopping ...");
appKit.stopAndWait();
appKit.stopAsync();
appKit.awaitTerminated();
}
private void openAndSend(int timeoutSecs, InetSocketAddress server, String channelID) throws IOException, ValueOutOfRangeException, InterruptedException {

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +58,8 @@ public class ExamplePaymentChannelServer implements PaymentChannelServerListener
wallet().addExtension(storedStates);
}
};
appKit.startAndWait();
appKit.startAsync();
appKit.awaitRunning();
System.out.println(appKit.wallet());

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +38,8 @@ public class FetchBlock {
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain = new BlockChain(params, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
PeerAddress addr = new PeerAddress(InetAddress.getLocalHost(), params.getPort());
peerGroup.addAddress(addr);
peerGroup.waitForPeers(1).get();
@@ -48,6 +50,6 @@ public class FetchBlock {
System.out.println("Waiting for node to send us the requested block: " + blockHash);
Block block = future.get();
System.out.println(block);
peerGroup.stop();
peerGroup.stopAsync();
}
}

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,7 +39,8 @@ public class FetchTransactions {
BlockStore blockStore = new MemoryBlockStore(params);
BlockChain chain = new BlockChain(params, blockStore);
PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost(), params.getPort()));
peerGroup.waitForPeers(1).get();
Peer peer = peerGroup.getConnectedPeers().get(0);
@@ -56,6 +58,7 @@ public class FetchTransactions {
}
System.out.println("Done.");
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
}
}

View File

@@ -1,5 +1,6 @@
/**
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -74,7 +75,8 @@ public class ForwardingService {
}
// Download the block chain and wait until it's done.
kit.startAndWait();
kit.startAsync();
kit.awaitRunning();
// We want to know when we receive money.
kit.wallet().addEventListener(new AbstractWalletEventListener() {

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,7 +58,7 @@ public class PeerMonitor {
public PeerMonitor() {
setupNetwork();
setupGUI();
peerGroup.start();
peerGroup.startAsync();
}
private void setupNetwork() {
@@ -113,7 +114,8 @@ public class PeerMonitor {
@Override
public void windowClosing(WindowEvent windowEvent) {
System.out.println("Shutting down ...");
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
System.out.println("Shutdown complete.");
System.exit(0);
}

View File

@@ -1,5 +1,6 @@
/**
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -61,9 +62,9 @@ public class PrivateKeys {
final PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost()));
peerGroup.start();
peerGroup.startAsync();
peerGroup.downloadBlockChain();
peerGroup.stop();
peerGroup.stopAsync();
// And take them!
System.out.println("Claiming " + Utils.bitcoinValueToFriendlyString(wallet.getBalance()) + " coins");

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2011 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +42,7 @@ public class RefreshWallet {
final PeerGroup peerGroup = new PeerGroup(params, chain);
peerGroup.addAddress(new PeerAddress(InetAddress.getLocalHost()));
peerGroup.start();
peerGroup.startAsync();
wallet.addEventListener(new AbstractWalletEventListener() {
@Override
@@ -53,7 +54,7 @@ public class RefreshWallet {
// Now download and process the block chain.
peerGroup.downloadBlockChain();
peerGroup.stop();
peerGroup.stopAsync();
wallet.saveToFile(file);
System.out.println("\nDone!\n");
System.out.println(wallet.toString());

View File

@@ -1,3 +1,20 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.bitcoin.tools;
import com.google.bitcoin.core.*;
@@ -58,7 +75,8 @@ public class BuildCheckpoints {
}
}, Threading.SAME_THREAD);
peerGroup.startAndWait();
peerGroup.startAsync();
peerGroup.awaitRunning();
peerGroup.downloadBlockChain();
checkState(checkpoints.size() > 0);
@@ -85,7 +103,8 @@ public class BuildCheckpoints {
digestOutputStream.close();
fileOutputStream.close();
peerGroup.stopAndWait();
peerGroup.stopAsync();
peerGroup.awaitTerminated();
store.close();
// Sanity check the created file.

View File

@@ -1,5 +1,6 @@
/*
* Copyright 2012 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -452,7 +453,8 @@ public class WalletTool {
}
setup();
peers.startAndWait();
peers.startAsync();
peers.awaitRunning();
// Wait for peers to connect, the tx to be sent to one of them and for it to be propagated across the
// network. Once propagation is complete and we heard the transaction back from all our peers, it will
// be committed to the wallet.
@@ -557,7 +559,8 @@ public class WalletTool {
ListenableFuture<PaymentSession.Ack> future = session.sendPayment(ImmutableList.of(req.tx), null, null);
if (future == null) {
// No payment_url for submission so, broadcast and wait.
peers.startAndWait();
peers.startAsync();
peers.awaitRunning();
peers.broadcastTransaction(req.tx).get();
} else {
PaymentSession.Ack ack = future.get();
@@ -651,7 +654,7 @@ public class WalletTool {
break;
}
peers.start();
peers.startAsync();
try {
latch.await();
} catch (InterruptedException e) {
@@ -713,7 +716,8 @@ public class WalletTool {
setup();
int startTransactions = wallet.getTransactions(true).size();
DownloadListener listener = new DownloadListener();
peers.startAndWait();
peers.startAsync();
peers.awaitRunning();
peers.startBlockChainDownload(listener);
try {
listener.await();
@@ -734,7 +738,8 @@ public class WalletTool {
private static void shutdown() {
try {
if (peers == null) return; // setup() never called so nothing to do.
peers.stopAndWait();
peers.stopAsync();
peers.awaitTerminated();
saveWallet(walletFile);
store.close();
wallet = null;

View File

@@ -1,3 +1,20 @@
/*
* Copyright 2013 Google Inc.
* Copyright 2014 Andreas Schildbach
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.bitcoin.tools;
import com.google.bitcoin.core.*;
@@ -27,6 +44,6 @@ public class WatchMempool {
}
}
});
peerGroup.start();
peerGroup.startAsync();
}
}

View File

@@ -37,7 +37,7 @@
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>13.0</version>
<version>16.0.1</version>
</dependency>
<dependency>
<groupId>com.aquafx-project</groupId>

View File

@@ -92,8 +92,9 @@ public class Main extends Application {
// or progress widget to keep the user engaged whilst we initialise, but we don't.
bitcoin.setDownloadListener(controller.progressBarUpdater())
.setBlockingStartup(false)
.setUserAgent(APP_NAME, "1.0")
.startAndWait();
.setUserAgent(APP_NAME, "1.0");
bitcoin.startAsync();
bitcoin.awaitRunning();
// Don't make the user wait for confirmations for now, as the intention is they're sending it their own money!
bitcoin.wallet().allowSpendingUnconfirmedTransactions();
bitcoin.peerGroup().setMaxConnections(11);
@@ -162,7 +163,8 @@ public class Main extends Application {
@Override
public void stop() throws Exception {
bitcoin.stopAndWait();
bitcoin.stopAsync();
bitcoin.awaitTerminated();
super.stop();
}