当前位置: 首页>>代码示例>>Java>>正文


Java Threading.SAME_THREAD属性代码示例

本文整理汇总了Java中org.bitcoinj.utils.Threading.SAME_THREAD属性的典型用法代码示例。如果您正苦于以下问题:Java Threading.SAME_THREAD属性的具体用法?Java Threading.SAME_THREAD怎么用?Java Threading.SAME_THREAD使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在org.bitcoinj.utils.Threading的用法示例。


在下文中一共展示了Threading.SAME_THREAD属性的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processGetData

protected void processGetData(GetDataMessage getdata) {
    log.info("{}: Received getdata message: {}", getAddress(), getdata.toString());
    ArrayList<Message> items = new ArrayList<>();
    for (ListenerRegistration<GetDataEventListener> registration : getDataEventListeners) {
        if (registration.executor != Threading.SAME_THREAD) continue;
        List<Message> listenerItems = registration.listener.getData(this, getdata);
        if (listenerItems == null) continue;
        items.addAll(listenerItems);
    }
    if (items.isEmpty()) {
        return;
    }
    log.info("{}: Sending {} items gathered from listeners to peer", getAddress(), items.size());
    for (Message item : items) {
        sendMessage(item);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:17,代码来源:Peer.java

示例2: processGetData

protected void processGetData(GetDataMessage getdata) {
    log.info("{}: Received getdata message: {}", getAddress(), getdata.toString());
    ArrayList<Message> items = new ArrayList<Message>();
    for (ListenerRegistration<GetDataEventListener> registration : getDataEventListeners) {
        if (registration.executor != Threading.SAME_THREAD) continue;
        List<Message> listenerItems = registration.listener.getData(this, getdata);
        if (listenerItems == null) continue;
        items.addAll(listenerItems);
    }
    if (items.isEmpty()) {
        return;
    }
    log.info("{}: Sending {} items gathered from listeners to peer", getAddress(), items.size());
    for (Message item : items) {
        sendMessage(item);
    }
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:17,代码来源:Peer.java

示例3: notifyHeight

private void notifyHeight(final long height) {
    final boolean isSynced = isChainSynced && isHistorySynced;
    log.info("notify height {} {} {}", isChainSynced, isHistorySynced, height);
    for (final ListenerRegistration<MultiWalletEventListener> registration : eventListeners) {
        if (registration.executor == Threading.SAME_THREAD) {
            registration.listener.onSyncState(this, isSynced, height);
        } else {
            registration.executor.execute(new Runnable() {
                @Override
                public void run() {
                    registration.listener.onSyncState(ElectrumMultiWallet.this, isSynced, height);
                }
            });
        }
    }
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:16,代码来源:ElectrumMultiWallet.java

示例4: processGetData

private void processGetData(GetDataMessage getdata) {
    log.info("{}: Received getdata message: {}", getAddress(), getdata.toString());
    ArrayList<Message> items = new ArrayList<Message>();
    for (ListenerRegistration<PeerEventListener> registration : eventListeners) {
        if (registration.executor != Threading.SAME_THREAD) continue;
        List<Message> listenerItems = registration.listener.getData(this, getdata);
        if (listenerItems == null) continue;
        items.addAll(listenerItems);
    }
    if (items.size() == 0) {
        return;
    }
    log.info("{}: Sending {} items gathered from listeners to peer", getAddress(), items.size());
    for (Message item : items) {
        sendMessage(item);
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:17,代码来源:Peer.java

示例5: containsRelevantTransactions

/**
 * Returns true if any connected wallet considers any transaction in the block to be relevant.
 */
private boolean containsRelevantTransactions(Block block) {
    // Does not need to be locked.
    for (Transaction tx : block.transactions) {
        try {
            for (final ListenerRegistration<BlockChainListener> registration : listeners) {
                if (registration.executor != Threading.SAME_THREAD) continue;
                if (registration.listener.isTransactionRelevant(tx)) return true;
            }
        } catch (ScriptException e) {
            // We don't want scripts we don't understand to break the block chain so just note that this tx was
            // not scanned here and continue.
            log.warn("Failed to parse a script: " + e.toString());
        }
    }
    return false;
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:19,代码来源:AbstractBlockChain.java

示例6: notifyTransaction

private void notifyTransaction(final Transaction tx, final boolean isNewCoin) {
    for (final ListenerRegistration<MultiWalletEventListener> registration : eventListeners) {
        if (registration.executor == Threading.SAME_THREAD) {
            registration.listener.onTransaction(this, tx, isNewCoin);
        } else {
            registration.executor.execute(new Runnable() {
                @Override
                public void run() {
                    registration.listener.onTransaction(ElectrumMultiWallet.this, tx, isNewCoin);
                }
            });
        }
    }
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:14,代码来源:ElectrumMultiWallet.java

示例7: queueOnTransactionConfidenceChanged

private void queueOnTransactionConfidenceChanged(final Transaction tx) {
    checkState(lock.isHeldByCurrentThread());
    for (final ListenerRegistration<WalletEventListener> registration : eventListeners) {
        if (registration.executor == Threading.SAME_THREAD) {
            registration.listener.onTransactionConfidenceChanged(this, tx);
        } else {
            registration.executor.execute(new Runnable() {
                @Override
                public void run() {
                    registration.listener.onTransactionConfidenceChanged(Wallet.this, tx);
                }
            });
        }
    }
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:15,代码来源:Wallet.java

示例8: processMessage

@Override
protected void processMessage(Message m) throws Exception {
    // Allow event listeners to filter the message stream. Listeners are allowed to drop messages by
    // returning null.
    for (ListenerRegistration<PreMessageReceivedEventListener> registration : preMessageReceivedEventListeners) {
        // Skip any listeners that are supposed to run in another thread as we don't want to block waiting
        // for it, which might cause circular deadlock.
        if (registration.executor == Threading.SAME_THREAD) {
            m = registration.listener.onPreMessageReceived(this, m);
            if (m == null) break;
        }
    }
    if (m == null) return;

    // If we are in the middle of receiving transactions as part of a filtered block push from the remote node,
    // and we receive something that's not a transaction, then we're done.
    if (currentFilteredBlock != null && !(m instanceof Transaction)) {
        endFilteredBlock(currentFilteredBlock);
        currentFilteredBlock = null;
    }

    // No further communication is possible until version handshake is complete.
    if (!(m instanceof VersionMessage || m instanceof VersionAck
            || (versionHandshakeFuture.isDone() && !versionHandshakeFuture.isCancelled())))
        throw new ProtocolException(
                "Received " + m.getClass().getSimpleName() + " before version handshake is complete.");

    if (m instanceof Ping) {
        processPing((Ping) m);
    } else if (m instanceof Pong) {
        processPong((Pong) m);
    } else if (m instanceof NotFoundMessage) {
        // This is sent to us when we did a getdata on some transactions that aren't in the peers memory pool.
        // Because NotFoundMessage is a subclass of InventoryMessage, the test for it must come before the next.
        processNotFoundMessage((NotFoundMessage) m);
    } else if (m instanceof InventoryMessage) {
        processInv((InventoryMessage) m);
    } else if (m instanceof Block) {
        processBlock((Block) m);
    } else if (m instanceof FilteredBlock) {
        startFilteredBlock((FilteredBlock) m);
    } else if (m instanceof Transaction) {
        processTransaction((Transaction) m);
    } else if (m instanceof GetDataMessage) {
        processGetData((GetDataMessage) m);
    } else if (m instanceof AddressMessage) {
        // We don't care about addresses of the network right now. But in future,
        // we should save them in the wallet so we don't put too much load on the seed nodes and can
        // properly explore the network.
        processAddressMessage((AddressMessage) m);
    } else if (m instanceof HeadersMessage) {
        processHeaders((HeadersMessage) m);
    } else if (m instanceof AlertMessage) {
        processAlert((AlertMessage) m);
    } else if (m instanceof VersionMessage) {
        processVersionMessage((VersionMessage) m);
    } else if (m instanceof VersionAck) {
        processVersionAck((VersionAck) m);
    } else if (m instanceof UTXOsMessage) {
        processUTXOMessage((UTXOsMessage) m);
    } else if (m instanceof RejectMessage) {
        log.error("{} {}: Received {}", this, getPeerVersionMessage().subVer, m);
    } else {
        log.warn("{}: Received unhandled message: {}", this, m);
    }
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:66,代码来源:Peer.java

示例9: informListenersForNewBlock

private void informListenersForNewBlock(final Block block, final NewBlockType newBlockType,
                                        @Nullable final List<Sha256Hash> filteredTxHashList,
                                        @Nullable final Map<Sha256Hash, Transaction> filteredTxn,
                                        final StoredBlock newStoredBlock) throws VerificationException {
    // Notify the listeners of the new block, so the depth and workDone of stored transactions can be updated
    // (in the case of the listener being a wallet). Wallets need to know how deep each transaction is so
    // coinbases aren't used before maturity.
    boolean first = true;
    Set<Sha256Hash> falsePositives = Sets.newHashSet();
    if (filteredTxHashList != null) falsePositives.addAll(filteredTxHashList);
    for (final ListenerRegistration<BlockChainListener> registration : listeners) {
        if (registration.executor == Threading.SAME_THREAD) {
            informListenerForNewTransactions(block, newBlockType, filteredTxHashList, filteredTxn,
                    newStoredBlock, first, registration.listener, falsePositives);
            if (newBlockType == NewBlockType.BEST_CHAIN)
                registration.listener.notifyNewBestBlock(newStoredBlock);
        } else {
            // Listener wants to be run on some other thread, so marshal it across here.
            final boolean notFirst = !first;
            registration.executor.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        // We can't do false-positive handling when executing on another thread
                        Set<Sha256Hash> ignoredFalsePositives = Sets.newHashSet();
                        informListenerForNewTransactions(block, newBlockType, filteredTxHashList, filteredTxn,
                                newStoredBlock, notFirst, registration.listener, ignoredFalsePositives);
                        if (newBlockType == NewBlockType.BEST_CHAIN)
                            registration.listener.notifyNewBestBlock(newStoredBlock);
                    } catch (VerificationException e) {
                        log.error("Block chain listener threw exception: ", e);
                        // Don't attempt to relay this back to the original peer thread if this was an async
                        // listener invocation.
                        // TODO: Make exception reporting a global feature and use it here.
                    }
                }
            });
        }
        first = false;
    }

    trackFalsePositives(falsePositives.size());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:43,代码来源:AbstractBlockChain.java


注:本文中的org.bitcoinj.utils.Threading.SAME_THREAD属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。