From c3261a469efa6ea79e069cac5570f08d3e9fca75 Mon Sep 17 00:00:00 2001 From: Yaroslav Dmytrotsa Date: Thu, 3 Sep 2015 11:03:52 +0300 Subject: [PATCH] remove SHH from light version of JSON_RPC. Now it peroxided. --- .../android/jsonrpc/light/JsonRpcServer.java | 14 --- .../android/jsonrpc/light/method/proxy.java | 11 +++ .../jsonrpc/light/method/shh_addToGroup.java | 32 ------- .../light/method/shh_getFilterChanges.java | 29 ------- .../jsonrpc/light/method/shh_getMessages.java | 29 ------- .../jsonrpc/light/method/shh_hasIdentity.java | 32 ------- .../jsonrpc/light/method/shh_newFilter.java | 35 -------- .../jsonrpc/light/method/shh_newGroup.java | 23 ----- .../jsonrpc/light/method/shh_newIdentity.java | 23 ----- .../jsonrpc/light/method/shh_post.java | 60 ------------- .../light/method/shh_uninstallFilter.java | 29 ------- .../jsonrpc/light/method/shh_version.java | 22 ----- .../android/jsonrpc/light/whisper/Filter.java | 86 ------------------- .../jsonrpc/light/whisper/FilterManager.java | 80 ----------------- 14 files changed, 11 insertions(+), 494 deletions(-) delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_addToGroup.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getFilterChanges.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getMessages.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_hasIdentity.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newFilter.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newGroup.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newIdentity.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_post.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_uninstallFilter.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_version.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/Filter.java delete mode 100644 ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/FilterManager.java diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java index 447f4123..0eae5d58 100644 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/JsonRpcServer.java @@ -10,7 +10,6 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; import io.netty.handler.codec.http.HttpServerCodec; -import org.ethereum.android.jsonrpc.light.whisper.FilterManager; import org.ethereum.facade.Ethereum; import com.thetransactioncompany.jsonrpc2.server.*; import org.ethereum.android.jsonrpc.light.method.*; @@ -45,21 +44,8 @@ public final class JsonRpcServer extends org.ethereum.android.jsonrpc.JsonRpcSer this.dispatcher.register(new eth_sign(this.ethereum)); this.dispatcher.register(new eth_sendTransaction(this.ethereum)); - this.dispatcher.register(new shh_version(this.ethereum)); - this.dispatcher.register(new shh_post(this.ethereum)); - this.dispatcher.register(new shh_newIdentity(this.ethereum)); - this.dispatcher.register(new shh_hasIdentity(this.ethereum)); - this.dispatcher.register(new shh_newGroup(this.ethereum)); - this.dispatcher.register(new shh_addToGroup(this.ethereum)); - this.dispatcher.register(new shh_newFilter(this.ethereum)); - this.dispatcher.register(new shh_uninstallFilter(this.ethereum)); - this.dispatcher.register(new shh_getFilterChanges(this.ethereum)); - this.dispatcher.register(new shh_getMessages(this.ethereum)); - this.dispatcher.register(new proxy(this.ethereum)); - FilterManager.getInstance(); - addRemoteServer("http://139.162.13.89:8545/"); } diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/proxy.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/proxy.java index 66b63ff9..b7bfd626 100644 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/proxy.java +++ b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/proxy.java @@ -52,6 +52,17 @@ public class proxy extends JsonRpcServerMethod { proxyMethods.add("eth_getFilterLogs"); proxyMethods.add("eth_getLogs"); + proxyMethods.add("shh_version"); + proxyMethods.add("shh_post"); + proxyMethods.add("shh_newIdentity"); + proxyMethods.add("shh_hasIdentity"); + proxyMethods.add("shh_newGroup"); + proxyMethods.add("shh_addToGroup"); + proxyMethods.add("shh_newFilter"); + proxyMethods.add("shh_uninstallFilter"); + proxyMethods.add("shh_getFilterChanges"); + proxyMethods.add("shh_getMessages"); + //TODO: issue methods - they generate transaction but must call them in blockchain. proxyMethods.add("eth_call"); proxyMethods.add("eth_estimateGas"); diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_addToGroup.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_addToGroup.java deleted file mode 100644 index 09386f5d..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_addToGroup.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -/* -TODO: not present clear specification for this method, also cpp and go version not provide it. -*/ -public class shh_addToGroup extends JsonRpcServerMethod { - - public shh_addToGroup(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - byte[] identity = jsToAddress((String)params.get(0)); - - JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getFilterChanges.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getFilterChanges.java deleted file mode 100644 index cd7ac1f2..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getFilterChanges.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.android.jsonrpc.light.whisper.FilterManager; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -public class shh_getFilterChanges extends JsonRpcServerMethod { - - public shh_getFilterChanges(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - int id = jsToInt((String)params.get(0)); - JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().toJS(id), req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getMessages.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getMessages.java deleted file mode 100644 index a1e97a36..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_getMessages.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.android.jsonrpc.light.whisper.FilterManager; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -public class shh_getMessages extends JsonRpcServerMethod { - - public shh_getMessages(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - int id = jsToInt((String)params.get(0)); - JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().toJSAll(id), req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_hasIdentity.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_hasIdentity.java deleted file mode 100644 index 1252051f..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_hasIdentity.java +++ /dev/null @@ -1,32 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -/* -TODO: done it when shh will be ready in -core -*/ -public class shh_hasIdentity extends JsonRpcServerMethod { - - public shh_hasIdentity(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - byte[] identity = jsToAddress((String)params.get(0)); - - JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newFilter.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newFilter.java deleted file mode 100644 index 43c6acfe..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newFilter.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; - -import net.minidev.json.JSONObject; - -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.android.jsonrpc.light.whisper.Filter; -import org.ethereum.android.jsonrpc.light.whisper.FilterManager; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -public class shh_newFilter extends JsonRpcServerMethod { - - public shh_newFilter(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - JSONObject obj = (JSONObject)params.get(0); - int id = FilterManager.getInstance().addFilter(new Filter(obj)); - String tmp = "0x" + Integer.toHexString(id); - JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newGroup.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newGroup.java deleted file mode 100644 index e2c39b6e..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newGroup.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; - -/* -TODO: not present clear specification for this method, also cpp and go version not provide it. -*/ -public class shh_newGroup extends JsonRpcServerMethod { - - public shh_newGroup(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID()); - return res; - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newIdentity.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newIdentity.java deleted file mode 100644 index d9f776c2..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_newIdentity.java +++ /dev/null @@ -1,23 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; - -/* -TODO: done it when shh will be ready in -core -*/ -public class shh_newIdentity extends JsonRpcServerMethod { - - public shh_newIdentity(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID()); - return res; - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_post.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_post.java deleted file mode 100644 index ae7d2925..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_post.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; - -import net.minidev.json.JSONArray; -import net.minidev.json.JSONObject; - -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; -import org.spongycastle.util.encoders.Hex; - -import java.util.ArrayList; -import java.util.List; - -/* -TODO: done it when shh will be ready in -core -*/ -public class shh_post extends JsonRpcServerMethod { - - public shh_post (Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - JSONObject obj = (JSONObject)params.get(0); - - byte[] from = null; - if (obj.containsKey("from")) - from = jsToAddress((String)obj.get("from")); - - byte[] to = null; - if (obj.containsKey("to")) - to = jsToAddress((String)obj.get("to")); - - ArrayList topics = new ArrayList<>(); - for (Object item : (JSONArray)obj.get("topics")) { - if (item instanceof String) { - topics.add(jsToAddress((String)item)); - } - } - - byte[] payload = jsToAddress((String)obj.get("payload")); - - int priority = jsToInt((String) obj.get("priority")); - - int ttl = jsToInt((String)obj.get("ttl")); - -//TODO: implement after Adrian merge with dev - - JSONRPC2Response res = new JSONRPC2Response(JSONRPC2Error.METHOD_NOT_FOUND, req.getID()); - return res; - } - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_uninstallFilter.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_uninstallFilter.java deleted file mode 100644 index d3094d01..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_uninstallFilter.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.android.jsonrpc.light.whisper.FilterManager; -import org.ethereum.facade.Ethereum; - -import java.util.List; - -public class shh_uninstallFilter extends JsonRpcServerMethod { - - public shh_uninstallFilter(Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - List params = req.getPositionalParams(); - if (params.size() != 1) { - return new JSONRPC2Response(JSONRPC2Error.INVALID_PARAMS, req.getID()); - } else { - int id = jsToInt((String)params.get(0)); - JSONRPC2Response res = new JSONRPC2Response(FilterManager.getInstance().uninstallFilter(id), req.getID()); - return res; - } - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_version.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_version.java deleted file mode 100644 index c3ea6e0f..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/method/shh_version.java +++ /dev/null @@ -1,22 +0,0 @@ -package org.ethereum.android.jsonrpc.light.method; - -import com.thetransactioncompany.jsonrpc2.*; -import com.thetransactioncompany.jsonrpc2.server.*; -import org.ethereum.android.jsonrpc.light.JsonRpcServerMethod; -import org.ethereum.facade.Ethereum; -import org.ethereum.net.shh.ShhHandler; - -public class shh_version extends JsonRpcServerMethod { - - public shh_version (Ethereum ethereum) { - super(ethereum); - } - - protected JSONRPC2Response worker(JSONRPC2Request req, MessageContext ctx) { - - String tmp = "" + ShhHandler.VERSION; - JSONRPC2Response res = new JSONRPC2Response(tmp, req.getID()); - return res; - - } -} \ No newline at end of file diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/Filter.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/Filter.java deleted file mode 100644 index 7d318f43..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/Filter.java +++ /dev/null @@ -1,86 +0,0 @@ -package org.ethereum.android.jsonrpc.light.whisper; - -import net.minidev.json.JSONArray; -import net.minidev.json.JSONObject; - -import org.ethereum.facade.Ethereum; -import org.ethereum.net.shh.ShhMessage; -import org.spongycastle.util.encoders.Hex; - -import java.util.ArrayList; - -/* -TODO: replace ShhMessage with real class when Roman finish Shh. -*/ -public class Filter { - protected int id; - protected ArrayList messages; - byte[] to = null; - boolean isWildcard = false; - ArrayList> or; - ArrayList and; - int sendID = 0; - - public Filter (JSONObject data) { - messages = new ArrayList(); - if (data.containsKey("to")) { - to = Hex.decode(((String)data.get("to")).substring(2)); - } - JSONArray topics = (JSONArray)data.get("topics"); - for (Object item : topics) { - if (item == null) { - isWildcard = true; - } - else if (item instanceof JSONArray) { - ArrayList tmp = new ArrayList(); - for (Object ori : (JSONArray)item) { - if (ori instanceof String) { - tmp.add(Hex.decode(((String)ori).substring(2))); - } - } - or.add(tmp); - } else if (item instanceof String) { - and.add(Hex.decode(((String)item).substring(2))); - } - } - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public void processEvent(Object data) { -//TODO: parse incomming data when we will know what comes. - } - - public JSONArray toJS() { - JSONArray res = new JSONArray(); - synchronized (messages) { - for (int i = sendID; i < messages.size(); i++) { - res.add(toJS(messages.get(i))); - } - sendID = messages.size(); - } - return res; - } - - public JSONArray toJSAll() { - JSONArray res = new JSONArray(); - synchronized (messages) { - for (int i = 0; i < messages.size(); i++) { - res.add(toJS(messages.get(i))); - } - sendID = messages.size(); - } - return res; - } - - private JSONObject toJS (ShhMessage data) { - JSONObject res = new JSONObject(); - return res; - } -} diff --git a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/FilterManager.java b/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/FilterManager.java deleted file mode 100644 index ab6c2227..00000000 --- a/ethereumj-core-android/src/main/java/org/ethereum/android/jsonrpc/light/whisper/FilterManager.java +++ /dev/null @@ -1,80 +0,0 @@ -package org.ethereum.android.jsonrpc.light.whisper; - -import net.minidev.json.JSONArray; - -import org.ethereum.facade.Ethereum; - -import java.util.Hashtable; -import java.util.Map; -import java.util.Timer; -import java.util.TimerTask; -import java.util.concurrent.TimeUnit; - -/* -This class must receive notification from -core about new whisper message. Right now I not see the way to do that. -TODO: ask advice from Roman about how to send notification to this class. -*/ -public class FilterManager { - - protected static FilterManager instance = null; - - public static FilterManager getInstance() { - if (instance == null) - instance = new FilterManager(); - return instance; - } - - protected Hashtable filters; - protected int last_id = 0; - - private FilterManager() { - filters = new Hashtable(); - } - - public void processEvent(Object data) { - synchronized (filters) { - for (Map.Entry item : filters.entrySet()) { - item.getValue().processEvent(data); - } - } - } - - public int addFilter(Filter filter) { - filter.setId(++last_id); - filters.put(filter.getId(), filter); - return filter.getId(); - } - - public Filter getFilter(int id) { - if (filters.containsKey(id)) { - return filters.get(id); - } - return null; - } - - public boolean uninstallFilter(int id) { - synchronized (filters) { - if (!filters.containsKey(id)) - return false; - filters.remove(id); - } - return true; - } - - public JSONArray toJS(int id) { - synchronized (filters) { - if (!filters.containsKey(id)) - return null; - return filters.get(id).toJS(); - } - } - - public JSONArray toJSAll(int id) { - synchronized (filters) { - if (!filters.containsKey(id)) - return null; - return filters.get(id).toJSAll(); - } - } - -} \ No newline at end of file