From c8fe1ec9c4c7f639b2bd2e4e26eb2777174f6556 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Thu, 9 Nov 2017 15:08:35 -0500 Subject: [PATCH] Increasing the message ids of the SubscriptionMessagesHub increase monotonically --- gradle.properties | 2 +- graphenej/build.gradle | 2 +- .../graphenej/api/SubscriptionMessagesHub.java | 11 ++++++----- .../graphenej/api/SubscriptionMessagesHubTest.java | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index a7a8496..c915c80 100644 --- a/gradle.properties +++ b/gradle.properties @@ -17,7 +17,7 @@ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.6-alpha0 +VERSION_NAME=0.4.6-alpha1 VERSION_CODE=8 GROUP=com.github.bilthon diff --git a/graphenej/build.gradle b/graphenej/build.gradle index 1eaa54e..9e79ae6 100644 --- a/graphenej/build.gradle +++ b/graphenej/build.gradle @@ -22,7 +22,7 @@ android { minSdkVersion 9 targetSdkVersion 24 versionCode 8 - versionName "0.4.6-alpha0" + versionName "0.4.6-alpha1" vectorDrawables.useSupportLibrary = true } diff --git a/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java b/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java index 594f3af..6cab2c8 100644 --- a/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java +++ b/graphenej/src/main/java/cy/agorise/graphenej/api/SubscriptionMessagesHub.java @@ -140,17 +140,17 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs String message = frame.getPayloadText(); System.out.println("<< "+message); if(currentId == LOGIN_ID){ + currentId = GET_DATABASE_ID; ArrayList emptyParams = new ArrayList<>(); ApiCall getDatabaseId = new ApiCall(1, RPC.CALL_DATABASE, emptyParams, RPC.VERSION, currentId); websocket.sendText(getDatabaseId.toJsonString()); - currentId++; }else if(currentId == GET_DATABASE_ID){ Type ApiIdResponse = new TypeToken>() {}.getType(); WitnessResponse witnessResponse = gson.fromJson(message, ApiIdResponse); databaseApiId = witnessResponse.result; subscribe(); - } else if(currentId == SUBSCRIPTION_REQUEST){ + } else if(currentId >= SUBSCRIPTION_REQUEST){ List subscriptionListeners = mSubscriptionDeserializer.getSubscriptionListeners(); if(!isUnsubscribing){ @@ -204,12 +204,12 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs private void subscribe(){ isUnsubscribing = false; + currentId++; ArrayList subscriptionParams = new ArrayList<>(); subscriptionParams.add(String.format("%d", SUBSCRIPTION_NOTIFICATION)); subscriptionParams.add(clearFilter); - ApiCall getDatabaseId = new ApiCall(databaseApiId, RPC.CALL_SET_SUBSCRIBE_CALLBACK, subscriptionParams, RPC.VERSION, SUBSCRIPTION_REQUEST); + ApiCall getDatabaseId = new ApiCall(databaseApiId, RPC.CALL_SET_SUBSCRIBE_CALLBACK, subscriptionParams, RPC.VERSION, currentId); mWebsocket.sendText(getDatabaseId.toJsonString()); - currentId = SUBSCRIPTION_REQUEST; } /** @@ -235,7 +235,8 @@ public class SubscriptionMessagesHub extends BaseGrapheneHandler implements Subs isSubscribed = false; isUnsubscribing = true; - ApiCall unsubscribe = new ApiCall(databaseApiId, RPC.CALL_CANCEL_ALL_SUBSCRIPTIONS, new ArrayList(), RPC.VERSION, SUBSCRIPTION_REQUEST); + currentId++; + ApiCall unsubscribe = new ApiCall(databaseApiId, RPC.CALL_CANCEL_ALL_SUBSCRIPTIONS, new ArrayList(), RPC.VERSION, currentId); mWebsocket.sendText(unsubscribe.toJsonString()); // Clearing all subscription listeners diff --git a/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java b/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java index f0f3e29..b6f8fda 100644 --- a/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java +++ b/graphenej/src/test/java/cy/agorise/graphenej/api/SubscriptionMessagesHubTest.java @@ -20,6 +20,7 @@ import cy.agorise.graphenej.models.SubscriptionResponse; /** * Class used to encapsulate all tests that relate to the {@see SubscriptionMessagesHub} class. + * This test requires setting up the NODE_URL environment variable */ public class SubscriptionMessagesHubTest extends BaseApiTest {