diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java index a8a76f4..c02d9ba 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/api/android/NodeConnection.java @@ -13,7 +13,13 @@ import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; */ public class NodeConnection { + /** + * List of URLs of the nodes + */ private List mUrlList; + /** + * Index of the current node from the list + */ private int mUrlIndex; private WebsocketWorkerThread mThread; private SubscriptionMessagesHub mMessagesHub; @@ -21,6 +27,9 @@ public class NodeConnection { private static NodeConnection instance; + /* + * Ger the instance of the NodeConnection which is inteded to be used as a Singleton. + */ public static NodeConnection getInstance(){ if(instance == null){ instance = new NodeConnection(); @@ -32,14 +41,38 @@ public class NodeConnection { this.mUrlList = new ArrayList<>(); } + /** + * Add a websocket URL node that will be added to the list used at node hop scheme. + * + * @param url: URL of the node + */ public void addNodeUrl(String url){ this.mUrlList.add(url); } + /** + * Add a list of websocket URL nodes that will be added to the current list and + * be used at node hop scheme. + * + * @param urlList: List of URLs of the nodes + */ + public void addNodeUrls(List urlList){ + List newList = new ArrayList(mUrlList); + newList.addAll(urlList); + } + + /** + * Get the list of websocket URL nodes. + * + * @return List of URLs of the nodes + */ public List getNodeUrls(){ return this.mUrlList; } + /** + * Clear list of websocket URL nodes. + */ public void clearNodeList(){ this.mUrlList.clear(); } @@ -60,6 +93,9 @@ public class NodeConnection { } } + /** + * Add the API Handler to the node. + */ public void addRequestHandler(BaseGrapheneHandler handler) throws RepeatedRequestIdException { handler.setRequestId(requestCounter); requestCounter++; diff --git a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java index 0a6534f..1d1d596 100644 --- a/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java +++ b/graphenej/src/test/java/de/bitsharesmunich/graphenej/api/android/NodeConnectionTest.java @@ -14,6 +14,7 @@ import de.bitsharesmunich.graphenej.api.GetAccountByName; import de.bitsharesmunich.graphenej.api.GetAllAssetHolders; import de.bitsharesmunich.graphenej.api.GetBlockHeader; import de.bitsharesmunich.graphenej.api.GetKeyReferences; +import de.bitsharesmunich.graphenej.api.GetLimitOrders; import de.bitsharesmunich.graphenej.errors.RepeatedRequestIdException; import de.bitsharesmunich.graphenej.errors.MalformedAddressException; import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; @@ -27,6 +28,9 @@ import de.bitsharesmunich.graphenej.Address; */ public class NodeConnectionTest { private String BLOCK_PAY_DE = System.getenv("OPENLEDGER_EU"); + private String NODE_URL_1 = System.getenv("NODE_URL_1"); + private String NODE_URL_2 = System.getenv("NODE_URL_2"); + private String NODE_URL_3 = System.getenv("NODE_URL_3"); private String ACCOUNT_ID = System.getenv("ACCOUNT_ID"); private String ACCOUNT_NAME = System.getenv("ACCOUNT_NAME"); private long BlOCK_TEST_NUMBER = Long.parseLong(System.getenv("BlOCK_TEST_NUMBER")); @@ -88,6 +92,33 @@ public class NodeConnectionTest { } } + @Test + public void testNodeHopFeature(){ + nodeConnection = NodeConnection.getInstance(); + nodeConnection.addNodeUrl(NODE_URL_1); + //Test adding a "sublist" + ArrayList urlList = new ArrayList(){{ + add(NODE_URL_1); + add(NODE_URL_2); + }}; + nodeConnection.addNodeUrl(BLOCK_PAY_DE); + + nodeConnection.connect("", "", true, mErrorListener); + + Timer timer = new Timer(); + timer.schedule(subscribeTask, 5000); + timer.schedule(releaseTask, 30000); + + try{ + // Holding this thread while we get update notifications + synchronized (this){ + wait(); + } + }catch(InterruptedException e){ + System.out.println("InterruptedException. Msg: "+e.getMessage()); + } + } + @Test public void testGetAccountBalancesRequest(){ nodeConnection = NodeConnection.getInstance();