Java Code Examples for org.bitcoinj.core.Context#propagate()

The following examples show how to use org.bitcoinj.core.Context#propagate() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WalletConfig.java    From bisq-core with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void shutDown() throws Exception {
    // Runs in a separate thread.
    try {
        Context.propagate(context);
        vPeerGroup.stop();
        vBtcWallet.saveToFile(vBtcWalletFile);
        if (vBsqWallet != null && vBsqWalletFile != null)
            //noinspection ConstantConditions,ConstantConditions
            vBsqWallet.saveToFile(vBsqWalletFile);
        vStore.close();

        vPeerGroup = null;
        vBtcWallet = null;
        vBsqWallet = null;
        vStore = null;
        vChain = null;
    } catch (BlockStoreException e) {
        throw new IOException(e);
    } catch (Throwable ignore) {
    }
}
 
Example 2
Source File: WalletConfig.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void shutDown() throws Exception {
    // Runs in a separate thread.
    try {
        Context.propagate(context);
        vPeerGroup.stop();
        vBtcWallet.saveToFile(vBtcWalletFile);
        if (vBsqWallet != null && vBsqWalletFile != null)
            //noinspection ConstantConditions,ConstantConditions
            vBsqWallet.saveToFile(vBsqWalletFile);
        vStore.close();

        vPeerGroup = null;
        vBtcWallet = null;
        vBsqWallet = null;
        vStore = null;
        vChain = null;
    } catch (BlockStoreException e) {
        throw new IOException(e);
    } catch (Throwable ignore) {
    }
}
 
Example 3
Source File: NetworkThreadFactory.java    From cate with MIT License 6 votes vote down vote up
@Override
public Thread newThread(Runnable r) {
    final String name = context.getParams().getId() + " worker #"
            + (++threadCount);
    final Thread thread = new Thread(group, () -> {
        Context.propagate(context);
        r.run();
    }, name);

    if (uncaughtExceptionHandler != null) {
        thread.setUncaughtExceptionHandler(uncaughtExceptionHandler);
    }
    thread.setDaemon(true);

    return thread;
}
 
Example 4
Source File: NetworkThreadFactoryTest.java    From cate with MIT License 6 votes vote down vote up
/**
 * Generate a thread and confirm the context is set on it.
 */
@Test
public void shouldSetContextOnThread() throws InterruptedException {
    final Context expected = new Context(TestNet3Params.get());
    final Context broken = new Context(DogecoinTestNet3Params.get());
    final NetworkThreadFactory factory = new NetworkThreadFactory(expected);

    // Progagate the wrong context onto this thread
    Context.propagate(broken);
    assertEquals(broken, Context.get());

    final ThreadMonitor monitor = new ThreadMonitor();
    final Thread thread = factory.newThread(monitor);
    thread.run();
    thread.join();
    
    assertEquals(expected, monitor.actual);
}
 
Example 5
Source File: TestWithWallet.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
public void setUp() throws Exception {
    BriefLogFormatter.init();
    Context.propagate(new Context(UNITTEST, 100, Coin.ZERO, false));
    wallet = new Wallet(UNITTEST);
    myKey = wallet.currentReceiveKey();
    myAddress = LegacyAddress.fromKey(UNITTEST, myKey);
    blockStore = new MemoryBlockStore(UNITTEST);
    chain = new BlockChain(UNITTEST, wallet, blockStore);
}