From 9d6a3cc1e9047262d9202a74a707e7df59d44630 Mon Sep 17 00:00:00 2001 From: Mike Hearn Date: Wed, 27 Feb 2013 15:18:38 +0100 Subject: [PATCH] Upgrade Guava and make a simple accessor for building cycle-detecting locks. --- core/pom.xml | 2 +- core/src/main/java/com/google/bitcoin/core/Utils.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/core/pom.xml b/core/pom.xml index c2356192..9596d958 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -184,7 +184,7 @@ com.google.guava guava - 11.0 + 13.0 diff --git a/core/src/main/java/com/google/bitcoin/core/Utils.java b/core/src/main/java/com/google/bitcoin/core/Utils.java index c0b831c9..b52c75a2 100644 --- a/core/src/main/java/com/google/bitcoin/core/Utils.java +++ b/core/src/main/java/com/google/bitcoin/core/Utils.java @@ -16,6 +16,7 @@ package com.google.bitcoin.core; +import com.google.common.util.concurrent.CycleDetectingLockFactory; import org.spongycastle.crypto.digests.RIPEMD160Digest; import org.spongycastle.util.encoders.Hex; @@ -27,6 +28,9 @@ import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Date; +import java.util.concurrent.locks.ReadWriteLock; +import java.util.concurrent.locks.ReentrantLock; +import java.util.concurrent.locks.ReentrantReadWriteLock; import static com.google.common.base.Preconditions.checkArgument; @@ -35,6 +39,12 @@ import static com.google.common.base.Preconditions.checkArgument; * To enable debug logging from the library, run with -Dbitcoinj.logging=true on your command line. */ public class Utils { + private static CycleDetectingLockFactory lockFactory = CycleDetectingLockFactory.newInstance(CycleDetectingLockFactory.Policies.THROW); + /** Returns a cycle detecting re-entrant named lock. */ + public static ReentrantLock lock(String name) { + return lockFactory.newReentrantLock(name); + } + /** The string that prefixes all text messages signed using Bitcoin keys. */ public static final String BITCOIN_SIGNED_MESSAGE_HEADER = "Bitcoin Signed Message:\n";