Adds an event listener that will be run when this confidence object is updated. The listener will be locked and * is likely to be invoked on a peer thread.
* - *Note that this is NOT called when every block is arrived. Instead it is called when the transaction + *
Note that this is NOT called when every block arrives. Instead it is called when the transaction * transitions between confidence states, ie, from not being seen in the chain to being seen (not necessarily in * the best chain). If you want to know when the transaction gets buried under another block, listen for new block * events using {@link PeerEventListener#onBlocksDownloaded(Peer, Block, int)} and then use the getters on the @@ -304,7 +304,7 @@ public class TransactionConfidence implements Serializable { * @throws IllegalStateException if confidence type is not BUILDING * @return estimated number of hashes needed to reverse the transaction. */ - public BigInteger getWorkDone(BlockChain chain) throws BlockStoreException { + public synchronized BigInteger getWorkDone(BlockChain chain) throws BlockStoreException { int depth; synchronized (this) { if (getConfidenceType() != ConfidenceType.BUILDING) diff --git a/core/src/main/java/com/google/bitcoin/utils/BriefLogFormatter.java b/core/src/main/java/com/google/bitcoin/utils/BriefLogFormatter.java index c51e1ac0..167a5f00 100644 --- a/core/src/main/java/com/google/bitcoin/utils/BriefLogFormatter.java +++ b/core/src/main/java/com/google/bitcoin/utils/BriefLogFormatter.java @@ -21,7 +21,10 @@ import java.io.StringWriter; import java.io.Writer; import java.text.MessageFormat; import java.util.Date; -import java.util.logging.*; +import java.util.logging.Formatter; +import java.util.logging.Level; +import java.util.logging.LogRecord; +import java.util.logging.Logger; /** * A Java logging formatter that writes more compact output than the default. @@ -29,15 +32,20 @@ import java.util.logging.*; public class BriefLogFormatter extends Formatter { private static final MessageFormat messageFormat = new MessageFormat("{3,date,hh:mm:ss} {0} {1}.{2}: {4}\n{5}"); + // OpenJDK made a questionable, backwards incompatible change to the Logger implementation. It internally uses + // weak references now which means simply fetching the logger and changing its configuration won't work. We must + // keep a reference to our custom logger around. + private static Logger logger; + /** Configures JDK logging to use this class for everything. */ public static void init() { - LogManager.getLogManager().getLogger("").getHandlers()[0].setFormatter(new BriefLogFormatter()); + logger = Logger.getLogger(""); + logger.getHandlers()[0].setFormatter(new BriefLogFormatter()); } public static void initVerbose() { - Logger logger = LogManager.getLogManager().getLogger(""); - logger.getHandlers()[0].setFormatter(new BriefLogFormatter()); - logger.setLevel(Level.FINEST); + init(); + logger.setLevel(Level.ALL); logger.log(Level.FINE, "test"); } diff --git a/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java b/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java index 20a1da0d..3f03a174 100644 --- a/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java +++ b/tools/src/main/java/com/google/bitcoin/tools/WalletTool.java @@ -77,6 +77,7 @@ public class WalletTool { private static NetworkParameters params; private static File walletFile; private static OptionSet options; + private static java.util.logging.Logger logger; public enum ActionEnum { DUMP, @@ -130,7 +131,8 @@ public class WalletTool { log.info("Starting up ..."); } else { // Disable logspam unless there is a flag. - LogManager.getLogManager().getLogger("").setLevel(Level.SEVERE); + logger = LogManager.getLogManager().getLogger(""); + logger.setLevel(Level.SEVERE); } File chainFileName; @@ -262,7 +264,9 @@ public class WalletTool { tmp = File.createTempFile("wallet", null, walletFile.getParentFile()); tmp.deleteOnExit(); wallet.saveToFile(tmp); - tmp.renameTo(walletFile); + if (!tmp.renameTo(walletFile)) { + throw new IOException("Failed to rename wallet"); + } } catch (IOException e) { System.err.println("Failed to save wallet! Old wallet should be left untouched."); e.printStackTrace();