implement EthereumListenerAdapter for Block / Transaction filter.

This commit is contained in:
Yaroslav Dmytrotsa 2015-06-23 20:02:09 +03:00
parent ee842e3a81
commit 50ee6adb5b
2 changed files with 21 additions and 7 deletions

View File

@ -113,7 +113,7 @@ public final class JsonRpcServer {
this.dispatcher.register(new shh_getFilterChanges(this.ethereum));
this.dispatcher.register(new shh_getMessages(this.ethereum));
FilterManager.getInstance();
ethereum.addListener(FilterManager.getInstance());
org.ethereum.android.jsonrpc.whisper.FilterManager.getInstance();
}

View File

@ -2,19 +2,21 @@ package org.ethereum.android.jsonrpc.filter;
import net.minidev.json.JSONArray;
import org.ethereum.core.Block;
import org.ethereum.core.Transaction;
import org.ethereum.core.TransactionReceipt;
import org.ethereum.facade.Ethereum;
import org.ethereum.listener.EthereumListenerAdapter;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;
/*
This class must receive notification from -core about new log, Block, Transaction. Right now I not see the way todo that.
TODO: ask advice from Roman about how to send notification to this class.
*/
public class FilterManager {
public class FilterManager extends EthereumListenerAdapter {
protected static FilterManager instance = null;
@ -49,7 +51,19 @@ public class FilterManager {
}, TimeUnit.MINUTES.toMillis(1));
}
public void processEvent(Object data) {
@Override
public void onBlock(Block block, List<TransactionReceipt> receipts) {
processEvent(block);
}
@Override
public void onPendingTransactionsReceived(Set<Transaction> transactions) {
for(Transaction tx : transactions) {
processEvent(tx);
}
}
private void processEvent(Object data) {
synchronized (filters) {
for (Map.Entry<Integer, FilterBase> item : filters.entrySet()) {
item.getValue().processEvent(data);