Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve EthereumListener #1138

Open
mkalinin opened this issue Aug 1, 2018 · 0 comments
Open

Improve EthereumListener #1138

mkalinin opened this issue Aug 1, 2018 · 0 comments
Assignees
Milestone

Comments

@mkalinin
Copy link
Contributor

mkalinin commented Aug 1, 2018

Currently CompositeEthereumListener invokes all defined listeners on any occurred event which is pretty inefficient. It also impacts on memory consumption.
Possible fix: drive listeners in a pub/sub fashion. It would also nice to have a possibility to define one-off listeners that are detached when a certain event has been caught.

Recap:

  • use pub/sub pattern to invoke listener only if it has a subscription to a certain event
  • provide a kind of evict() method that removes listener when current invocation is finished
  • make listener for one-off events like onSyncDone remove itself in automatic fashion
  • get rid of trace() and its usage all over the codebase

Example of listener with evict:

ethereum.addListener(new EthereumListenerAdapter() {
    @Override
    public void onPendingTransactionUpdate(TransactionReceipt txReceipt, PendingTransactionState state, Block block) {
        if (FastByteComparisons.equal(depositTxHash, txReceipt.getTransaction().getHash()) &&
                state == PendingTransactionState.INCLUDED) {
            depositFuture.complete(txReceipt);

            evict();
        }
    }
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants