Skip to content

Commit

Permalink
saving timetoken on new susbcribe, and added logic to calculate timet…
Browse files Browse the repository at this point in the history
…oken when RESUME on reconnect is enabled
  • Loading branch information
Devendra committed Feb 4, 2013
1 parent 82633ea commit 19f5196
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 1 deletion.
Binary file modified java/3.4/Pubnub-Standardedition-3.4.jar
Binary file not shown.
74 changes: 74 additions & 0 deletions java/3.4/examples/src/com/pubnub/examples/PubnubTestClient.java
Original file line number Original file line Diff line number Diff line change
@@ -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();

}

}
Binary file modified java/3.4/jars/PubnubDemoConsole.jar
Binary file not shown.
Binary file modified java/3.4/jars/PubnubExample.jar
Binary file not shown.
6 changes: 5 additions & 1 deletion java/3.4/srcPubnubApi/com/pubnub/api/Pubnub.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -907,6 +907,7 @@ private void _subscribe(Hashtable args) {
Callback callback = (Callback) args.get("callback"); Callback callback = (Callback) args.get("callback");
String timetoken = (String) args.get("timetoken"); String timetoken = (String) args.get("timetoken");


_saved_timetoken = _timetoken;
_timetoken = (timetoken == null)?"0":timetoken; _timetoken = (timetoken == null)?"0":timetoken;


/* /*
Expand Down Expand Up @@ -1061,7 +1062,10 @@ public void handleTimeout() {
log.trace("Timeout Occurred, Calling error callbacks on the channels"); log.trace("Timeout Occurred, Calling error callbacks on the channels");
try { try {
jsobj.put("error", "Network Timeout"); 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); subscriptions.invokeErrorCallbackOnChannels(jsobj);
} catch (JSONException e) { } catch (JSONException e) {
subscriptions.invokeErrorCallbackOnChannels("Network Timeout"); subscriptions.invokeErrorCallbackOnChannels("Network Timeout");
Expand Down

0 comments on commit 19f5196

Please sign in to comment.