Browse files

saving timetoken on new susbcribe, and added logic to calculate timet…

…oken when RESUME on reconnect is enabled
  • Loading branch information...
1 parent 82633ea commit 19f51966d2fb0e87ed964ac8382697af52391283 @devendram devendram committed Feb 4, 2013
View
BIN java/3.4/Pubnub-Standardedition-3.4.jar
Binary file not shown.
View
74 java/3.4/examples/src/com/pubnub/examples/PubnubTestClient.java
@@ -0,0 +1,74 @@
+package com.pubnub.examples;
+
+import java.util.Hashtable;
+
+import com.pubnub.api.Callback;
+import com.pubnub.api.Pubnub;
+
+public class PubnubTestClient {
+ Pubnub pubnub;
+ int recvSuccess;
+ int recvErrors;
+ int sendSuccess;
+ int sendErrors;
+
+ PubnubTestClient() {
+ pubnub = new Pubnub("demo", "demo", "demo", false);
+ }
+
+ public void runTest() {
+ Hashtable args = new Hashtable();
+ args.put("channel", "TestClientChannel");
+ try {
+ pubnub.subscribe(args, new Callback() {
+
+ public void successCallback(String channel, Object message) {
+ recvSuccess++;
+ }
+ public void errorCallback(String channel, Object message) {
+ recvErrors++;
+ }
+ });
+
+ } catch (Exception e) {
+
+ }
+ Callback publishCb = new Callback() {
+ public void successCallback(String channel, Object message) {
+ sendSuccess++;
+ }
+
+ public void errorCallback(String channel, Object message) {
+ System.out.println(message.toString());
+ sendErrors++;
+ }
+ };
+ args.put("message", "Test Client Message");
+ for (int i = 0; i < 10; i++) {
+ pubnub.publish(args, publishCb);
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Send Success : " + sendSuccess );
+ System.out.println("Send Errors : " + sendErrors );
+ System.out.println("Receive Success : " + recvSuccess );
+ System.out.println("Receive Errors : " + recvErrors );
+ }
+ System.out.println("Send Success : " + sendSuccess );
+ System.out.println("Send Errors : " + sendErrors );
+ System.out.println("Receive Success : " + recvSuccess );
+ System.out.println("Receive Errors : " + recvErrors );
+
+ }
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) {
+ new PubnubTestClient().runTest();
+
+ }
+
+}
View
BIN java/3.4/jars/PubnubDemoConsole.jar
Binary file not shown.
View
BIN java/3.4/jars/PubnubExample.jar
Binary file not shown.
View
6 java/3.4/srcPubnubApi/com/pubnub/api/Pubnub.java
@@ -907,6 +907,7 @@ private void _subscribe(Hashtable args) {
Callback callback = (Callback) args.get("callback");
String timetoken = (String) args.get("timetoken");
+ _saved_timetoken = _timetoken;
_timetoken = (timetoken == null)?"0":timetoken;
/*
@@ -1061,7 +1062,10 @@ public void handleTimeout() {
log.trace("Timeout Occurred, Calling error callbacks on the channels");
try {
jsobj.put("error", "Network Timeout");
- jsobj.put("timetoken", _timetoken);
+ log.trace("timetoken : " + _timetoken);
+ log.trace("Saved Timetoken : " + _saved_timetoken);
+ String timeoutTimetoken = (isResumeOnReconnect())?(_timetoken.equals("0"))?_saved_timetoken: _timetoken:"0";
+ jsobj.put("timetoken", timeoutTimetoken);
subscriptions.invokeErrorCallbackOnChannels(jsobj);
} catch (JSONException e) {
subscriptions.invokeErrorCallbackOnChannels("Network Timeout");

0 comments on commit 19f5196

Please sign in to comment.