Example usage for com.google.common.util.concurrent MoreExecutors sameThreadExecutor

List of usage examples for com.google.common.util.concurrent MoreExecutors sameThreadExecutor

Introduction

In this page you can find the example usage for com.google.common.util.concurrent MoreExecutors sameThreadExecutor.

Prototype

@Deprecated
@GwtIncompatible("TODO")
public static ListeningExecutorService sameThreadExecutor() 

Source Link

Document

Creates an executor service that runs each task in the thread that invokes execute/submit , as in CallerRunsPolicy .

Usage

From source file:com.google.sha1coin.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {//w w w . jav a 2 s  . co m
        Coin value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + value.toFriendlyString());
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final Coin amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    } catch (InsufficientMoneyException e) {
        // This should never happen - we're only trying to forward what we received!
        throw new RuntimeException(e);
    }
}

From source file:com.google.worldcoin.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {//from  w  ww  . j a va2 s  .c  om
        BigInteger value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + Utils.worldcoinValueToFriendlyString(value) + " BTC");
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final BigInteger amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    } catch (InsufficientMoneyException e) {
        // This should never happen - we're only trying to forward what we received!
        throw new RuntimeException(e);
    }
}

From source file:com.tribesman.kobocoinj.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {/*from   w  w  w .  jav a 2  s .c  om*/
        BigInteger value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + Utils.kobocoinValueToFriendlyString(value) + " BTC");
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final BigInteger amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    } catch (InsufficientMoneyException e) {
        // This should never happen - we're only trying to forward what we received!
        throw new RuntimeException(e);
    }
}

From source file:com.dogecoin.dogecoinj.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {//from   w  ww  . j a  v  a 2 s .  c o m
        Coin value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + value.toFriendlyString());
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final Coin amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException | InsufficientMoneyException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    }
}

From source file:com.google.spartancoin.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {//from   ww  w . j  a v a 2  s.  c o m
        BigInteger value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + Utils.bitcoinValueToFriendlyString(value) + " BTC");
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final BigInteger amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    } catch (InsufficientMoneyException e) {
        // This should never happen - we're only trying to forward what we received!
        throw new RuntimeException(e);
    }
}

From source file:com.woollysammoth.nubitj.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {/*  w  w  w  . j a v a2 s .co  m*/
        BigInteger value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + Utils.nubitValueToFriendlyString(value) + " BTC");
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final BigInteger amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    } catch (InsufficientMoneyException e) {
        // This should never happen - we're only trying to forward what we received!
        throw new RuntimeException(e);
    }
}

From source file:org.apache.cassandra.streaming.StreamManager.java

public void registerReceiving(final StreamResultFuture result) {
    result.addEventListener(notifier);/*from w  ww .j a v a2s .c  o  m*/
    // Make sure we remove the stream on completion (whether successful or not)
    result.addListener(new Runnable() {
        public void run() {
            receivingStreams.remove(result.planId);
        }
    }, MoreExecutors.sameThreadExecutor());

    receivingStreams.put(result.planId, result);
}

From source file:org.lealone.cluster.streaming.StreamManager.java

public void registerReceiving(final StreamResultFuture result) {
    result.addEventListener(notifier);// ww  w.j a va  2  s .  c o  m
    // Make sure we remove the stream on completion (whether successful or not)
    result.addListener(new Runnable() {
        @Override
        public void run() {
            receivingStreams.remove(result.planId);
        }
    }, MoreExecutors.sameThreadExecutor());

    receivingStreams.put(result.planId, result);
}

From source file:org.apache.cassandra.service.ActiveRepairService.java

/**
 * Requests repairs for the given keyspace and column families.
 *
 * @return Future for asynchronous call or null if there is no need to repair
 *//*from ww  w .  jav a  2 s  . c o  m*/
public RepairSession submitRepairSession(UUID parentRepairSession, Range<Token> range, String keyspace,
        RepairParallelism parallelismDegree, Set<InetAddress> endpoints, long repairedAt,
        ListeningExecutorService executor, String... cfnames) {
    if (endpoints.isEmpty())
        return null;

    if (cfnames.length == 0)
        return null;

    final RepairSession session = new RepairSession(parentRepairSession, UUIDGen.getTimeUUID(), range, keyspace,
            parallelismDegree, endpoints, repairedAt, cfnames);

    sessions.put(session.getId(), session);
    // register listeners
    gossiper.register(session);
    failureDetector.registerFailureDetectionEventListener(session);

    // unregister listeners at completion
    session.addListener(new Runnable() {
        /**
         * When repair finished, do clean up
         */
        public void run() {
            failureDetector.unregisterFailureDetectionEventListener(session);
            gossiper.unregister(session);
            sessions.remove(session.getId());
        }
    }, MoreExecutors.sameThreadExecutor());
    session.start(executor);
    return session;
}

From source file:com.google.devcoin.examples.ForwardingService.java

private static void forwardCoins(Transaction tx) {
    try {//from  w  w w.  ja  va 2 s  .  com
        BigInteger value = tx.getValueSentToMe(kit.wallet());
        System.out.println("Forwarding " + Utils.bitcoinValueToFriendlyString(value) + " BTC");
        // Now send the coins back! Send with a small fee attached to ensure rapid confirmation.
        final BigInteger amountToSend = value.subtract(Transaction.REFERENCE_DEFAULT_MIN_TX_FEE);
        final Wallet.SendResult sendResult = kit.wallet().sendCoins(kit.peerGroup(), forwardingAddress,
                amountToSend);
        checkNotNull(sendResult); // We should never try to send more coins than we have!
        System.out.println("Sending ...");
        // Register a callback that is invoked when the transaction has propagated across the network.
        // This shows a second style of registering ListenableFuture callbacks, it works when you don't
        // need access to the object the future returns.
        sendResult.broadcastComplete.addListener(new Runnable() {
            @Override
            public void run() {
                // The wallet has changed now, it'll get auto saved shortly or when the app shuts down.
                System.out
                        .println("Sent coins onwards! Transaction hash is " + sendResult.tx.getHashAsString());
            }
        }, MoreExecutors.sameThreadExecutor());
    } catch (KeyCrypterException e) {
        // We don't use encrypted wallets in this example - can never happen.
        throw new RuntimeException(e);
    }
}