mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-01-31 15:22:16 +00:00
Rename the Locks class to Threading in preparation for more stuff.
This commit is contained in:
parent
1296074e8f
commit
b87879fd42
@ -18,7 +18,7 @@ package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.store.BlockStore;
|
||||
import com.google.bitcoin.store.BlockStoreException;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
@ -77,7 +77,7 @@ import static com.google.common.base.Preconditions.*;
|
||||
*/
|
||||
public abstract class AbstractBlockChain {
|
||||
private static final Logger log = LoggerFactory.getLogger(AbstractBlockChain.class);
|
||||
protected ReentrantLock lock = Locks.lock("blockchain");
|
||||
protected ReentrantLock lock = Threading.lock("blockchain");
|
||||
|
||||
/** Keeps a map of block hashes to StoredBlocks. */
|
||||
private final BlockStore blockStore;
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -45,7 +45,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||
*/
|
||||
public class MemoryPool {
|
||||
private static final Logger log = LoggerFactory.getLogger(MemoryPool.class);
|
||||
protected ReentrantLock lock = Locks.lock("mempool");
|
||||
protected ReentrantLock lock = Threading.lock("mempool");
|
||||
|
||||
// For each transaction we may have seen:
|
||||
// - only its hash in an inv packet
|
||||
|
@ -18,7 +18,7 @@ package com.google.bitcoin.core;
|
||||
|
||||
import com.google.bitcoin.store.BlockStore;
|
||||
import com.google.bitcoin.store.BlockStoreException;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -55,7 +55,7 @@ public class Peer {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(Peer.class);
|
||||
|
||||
protected final ReentrantLock lock = Locks.lock("peer");
|
||||
protected final ReentrantLock lock = Threading.lock("peer");
|
||||
|
||||
private final NetworkParameters params;
|
||||
private final AbstractBlockChain blockChain;
|
||||
|
@ -20,7 +20,7 @@ package com.google.bitcoin.core;
|
||||
import com.google.bitcoin.core.Peer.PeerHandler;
|
||||
import com.google.bitcoin.discovery.PeerDiscovery;
|
||||
import com.google.bitcoin.discovery.PeerDiscoveryException;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.google.common.util.concurrent.*;
|
||||
@ -71,7 +71,7 @@ public class PeerGroup extends AbstractIdleService implements TransactionBroadca
|
||||
private static final int DEFAULT_CONNECTIONS = 4;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PeerGroup.class);
|
||||
protected final ReentrantLock lock = Locks.lock("peergroup");
|
||||
protected final ReentrantLock lock = Threading.lock("peergroup");
|
||||
|
||||
// These lists are all thread-safe so do not have to be accessed under the PeerGroup lock.
|
||||
// Addresses to try to connect to, excluding active peers.
|
||||
|
@ -22,7 +22,7 @@ import com.google.bitcoin.crypto.KeyCrypter;
|
||||
import com.google.bitcoin.crypto.KeyCrypterException;
|
||||
import com.google.bitcoin.crypto.KeyCrypterScrypt;
|
||||
import com.google.bitcoin.store.WalletProtobufSerializer;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.collect.*;
|
||||
@ -83,7 +83,7 @@ public class Wallet implements Serializable, BlockChainListener {
|
||||
private static final Logger log = LoggerFactory.getLogger(Wallet.class);
|
||||
private static final long serialVersionUID = 2L;
|
||||
|
||||
protected final ReentrantLock lock = Locks.lock("wallet");
|
||||
protected final ReentrantLock lock = Threading.lock("wallet");
|
||||
|
||||
// The various pools below give quick access to wallet-relevant transactions by the state they're in:
|
||||
//
|
||||
|
@ -4,7 +4,7 @@ import java.math.BigInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.protobuf.ByteString;
|
||||
import net.jcip.annotations.GuardedBy;
|
||||
@ -28,7 +28,7 @@ public class PaymentChannelClient {
|
||||
//TODO: Update JavaDocs with notes for communication over stateless protocols
|
||||
private static final org.slf4j.Logger log = LoggerFactory.getLogger(PaymentChannelClient.class);
|
||||
|
||||
protected final ReentrantLock lock = Locks.lock("channelclient");
|
||||
protected final ReentrantLock lock = Threading.lock("channelclient");
|
||||
|
||||
/**
|
||||
* Implements the connection between this client and the server, providing an interface which allows messages to be
|
||||
|
@ -4,7 +4,7 @@ import java.math.BigInteger;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.util.concurrent.MoreExecutors;
|
||||
import com.google.protobuf.ByteString;
|
||||
import net.jcip.annotations.GuardedBy;
|
||||
@ -28,7 +28,7 @@ public class PaymentChannelServer {
|
||||
//TODO: Update JavaDocs with notes for communication over stateless protocols
|
||||
private static final org.slf4j.Logger log = LoggerFactory.getLogger(PaymentChannelServer.class);
|
||||
|
||||
protected final ReentrantLock lock = Locks.lock("channelserver");
|
||||
protected final ReentrantLock lock = Threading.lock("channelserver");
|
||||
|
||||
// The step in the initialization process we are in, some of this is duplicated in the PaymentChannelServerState
|
||||
private enum InitStep {
|
||||
|
@ -25,7 +25,7 @@ import java.util.TimerTask;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import net.jcip.annotations.GuardedBy;
|
||||
@ -46,7 +46,7 @@ public class StoredPaymentChannelClientStates implements WalletExtension {
|
||||
private Wallet containingWallet;
|
||||
private final TransactionBroadcaster announcePeerGroup;
|
||||
|
||||
protected final ReentrantLock lock = Locks.lock("StoredPaymentChannelClientStates");
|
||||
protected final ReentrantLock lock = Threading.lock("StoredPaymentChannelClientStates");
|
||||
|
||||
/**
|
||||
* Creates a new StoredPaymentChannelClientStates and associates it with the given {@link Wallet} and
|
||||
|
@ -21,7 +21,7 @@ import java.util.*;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import net.jcip.annotations.GuardedBy;
|
||||
|
||||
@ -41,7 +41,7 @@ public class StoredPaymentChannelServerStates implements WalletExtension {
|
||||
|
||||
private final Timer channelTimeoutHandler = new Timer();
|
||||
|
||||
private final ReentrantLock lock = Locks.lock("StoredPaymentChannelServerStates");
|
||||
private final ReentrantLock lock = Threading.lock("StoredPaymentChannelServerStates");
|
||||
|
||||
/**
|
||||
* The offset between the refund transaction's lock time and the time channels will be automatically closed.
|
||||
|
@ -27,7 +27,7 @@ import java.nio.channels.spi.SelectorProvider;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -50,7 +50,7 @@ public class ProtobufServer {
|
||||
private static final int BUFFER_SIZE_UPPER_BOUND = 65536;
|
||||
|
||||
private class ConnectionHandler extends MessageWriteTarget {
|
||||
private final ReentrantLock lock = Locks.lock("protobufServerConnectionHandler");
|
||||
private final ReentrantLock lock = Threading.lock("protobufServerConnectionHandler");
|
||||
private final ByteBuffer dbuf;
|
||||
private final SocketChannel channel;
|
||||
private final ProtobufParser parser;
|
||||
|
@ -17,7 +17,7 @@
|
||||
package com.google.bitcoin.store;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -53,7 +53,7 @@ public class SPVBlockStore implements BlockStore {
|
||||
protected int numHeaders;
|
||||
protected NetworkParameters params;
|
||||
|
||||
protected ReentrantLock lock = Locks.lock("SPVBlockStore");
|
||||
protected ReentrantLock lock = Threading.lock("SPVBlockStore");
|
||||
|
||||
// The entire ring-buffer is mmapped and accessing it should be as fast as accessing regular memory once it's
|
||||
// faulted in. Unfortunately, in theory practice and theory are the same. In practice they aren't.
|
||||
|
@ -25,7 +25,7 @@ import static com.google.common.base.Preconditions.checkState;
|
||||
/**
|
||||
* A wrapper around explicit lock creation that lets you control whether bitcoinj performs cycle detection or not.
|
||||
*/
|
||||
public class Locks {
|
||||
public class Threading {
|
||||
|
||||
static {
|
||||
// Default policy goes here. If you want to change this, use one of the static methods before
|
||||
@ -54,7 +54,7 @@ public class Locks {
|
||||
}
|
||||
|
||||
public static void setPolicy(CycleDetectingLockFactory.Policy policy) {
|
||||
Locks.policy = policy;
|
||||
Threading.policy = policy;
|
||||
factory = CycleDetectingLockFactory.newInstance(policy);
|
||||
}
|
||||
|
@ -17,7 +17,12 @@
|
||||
package com.google.bitcoin.protocols.channels;
|
||||
|
||||
import com.google.bitcoin.core.*;
|
||||
import com.google.bitcoin.utils.Locks;
|
||||
import com.google.bitcoin.protocols.niowrapper.ProtobufParser;
|
||||
import com.google.bitcoin.protocols.niowrapper.ProtobufParserFactory;
|
||||
import com.google.bitcoin.protocols.niowrapper.ProtobufServer;
|
||||
import com.google.bitcoin.utils.Threading;
|
||||
import org.bitcoin.paymentchannel.Protos;
|
||||
import org.junit.Before;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
import com.google.common.util.concurrent.SettableFuture;
|
||||
import com.google.protobuf.ByteString;
|
||||
@ -83,13 +88,13 @@ public class ChannelConnectionTest extends TestWithWallet {
|
||||
// Because there are no separate threads in the tests here (we call back into client/server in server/client
|
||||
// handlers), we have lots of lock cycles. A normal user shouldn't have this issue as they are probably not both
|
||||
// client+server running in the same thread.
|
||||
Locks.warnOnLockCycles();
|
||||
Threading.warnOnLockCycles();
|
||||
}
|
||||
|
||||
@After
|
||||
public void checkFail() {
|
||||
assertFalse(fail.get());
|
||||
Locks.throwOnLockCycles();
|
||||
Threading.throwOnLockCycles();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user