Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding API's for setting maxRetries and retryInterval

  • Loading branch information...
commit 6f10ace259a764f54c356ecee66db66a73b6ec6e 1 parent 82633ea
@devendram devendram authored
View
BIN  java/3.4/Pubnub-Standardedition-3.4.jar
Binary file not shown
View
35 java/3.4/examples/src/com/pubnub/examples/PubnubDemoConsole.java
@@ -132,6 +132,14 @@ private void disconnectAndResubscribe() {
}
+ private void setMaxRetries(int maxRetries) {
+ pubnub.setMaxRetries(maxRetries);
+ }
+
+ private void setRetryInterval(int retryInterval) {
+ pubnub.setRetryInterval(retryInterval);
+ }
+
public void startDemo() {
reader = new Scanner(System.in);
System.out.println("HINT:\tTo test Re-connect and catch-up");
@@ -159,7 +167,6 @@ public void startDemo() {
pubnub = new Pubnub("demo", "demo", "demo", this.cipher_key, this.SSL);
}
-
displayMenuOptions();
String channelName = null;
@@ -176,61 +183,63 @@ public void startDemo() {
subscribe(channelName);
System.out.println("Subscribed to following channels: ");
System.out.println(PubnubUtil.joinString(pubnub.getSubscribedChannelsArray(), " : "));
- displayMenuOptions();
break;
case 2:
System.out.println("Publish: Enter Channel name");
channelName = reader.nextLine();
publish(channelName);
- displayMenuOptions();
break;
case 3:
System.out.println("Presence: Enter Channel name");
channelName = reader.nextLine();
presence(channelName);
- displayMenuOptions();
break;
case 4:
System.out.println("Detailed History: Enter Channel name");
channelName = reader.nextLine();
detailedHistory(channelName);
- displayMenuOptions();
break;
case 5:
System.out.println("Here Now : Enter Channel name");
channelName = reader.nextLine();
hereNow(channelName);
- displayMenuOptions();
break;
case 6:
System.out.println("Unsubscribe: Enter Channel name");
channelName = reader.nextLine();
unsubscribe(channelName);
- displayMenuOptions();
break;
case 7:
System.out.println("UnsubscribePresence : Enter Channel name");
channelName = reader.nextLine();
unsubscribePresence(channelName);
- displayMenuOptions();
break;
case 8:
time();
- displayMenuOptions();
break;
case 10:
disconnectAndResubscribe();
- displayMenuOptions();
break;
case 11:
pubnub.setResumeOnReconnect(pubnub.isResumeOnReconnect()?false:true);
System.out.println("RESUME ON RECONNECT : " + pubnub.isResumeOnReconnect() );
- displayMenuOptions();
+ break;
+ case 12:
+ System.out.println("Set Max Retries: Enter max retries");
+ int maxRetries = reader.nextInt();
+ reader.nextLine();
+ setMaxRetries(maxRetries);
+ break;
+ case 13:
+ System.out.println("Set Retry Interval: Enter retry interval");
+ int retryInterval = reader.nextInt();
+ reader.nextLine();
+ setRetryInterval(retryInterval);
break;
default:
System.out.println("Invalid Input");
- displayMenuOptions();
}
+ displayMenuOptions();
}
System.out.println("Exiting");
pubnub.shutdown();
@@ -249,6 +258,8 @@ private void displayMenuOptions() {
System.out.println("ENTER 9 FOR EXIT OR QUIT");
System.out.println("ENTER 10 FOR Disconnect-And-Resubscribe");
System.out.println("ENTER 11 FOR Toggle Resume On Reconnect");
+ System.out.println("ENTER 12 FOR Setting MAX Retries");
+ System.out.println("ENTER 13 FOR Setting Retry Interval");
System.out.println("\nENTER 0 to display this menu");
}
View
3  java/3.4/examples/src/com/pubnub/examples/PubnubExample.java
@@ -16,11 +16,12 @@
String channel = "hello_world1";
String[] channels = { "hello_world1", "hello_world2", "hello_world3",
"hello_world4" };
+ Pubnub _pubnub;
public PubnubExample() {
+ _pubnub = new Pubnub("demo", "demo",false);
}
- Pubnub _pubnub = new Pubnub("demo", "demo",false);
/**
* @param params
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
11 java/3.4/srcPubnubApi/com/pubnub/api/Pubnub.java
@@ -40,8 +40,8 @@
private String UUID = null;
private Subscriptions subscriptions;
- private RequestManager subscribeManager;
- private RequestManager nonSubscribeManager;
+ private SubscribeManager subscribeManager;
+ private NonSubscribeManager nonSubscribeManager;
private String _timetoken = "0";
private String _saved_timetoken = "0";
@@ -286,6 +286,13 @@ public void setNonSubscribeTimeout(int timeout) {
nonSubscribeManager.setRequestTimeout(timeout);
}
+ public void setRetryInterval(int retryInterval) {
+ subscribeManager.setRetryInterval(retryInterval);
+ }
+
+ public void setMaxRetries(int maxRetries) {
+ subscribeManager.setMaxRetries(maxRetries);
+ }
/**
View
36 java/3.4/srcPubnubApi/com/pubnub/api/RequestManager.java
@@ -126,18 +126,28 @@ void process(HttpRequest hreq) {
}
class SubscribeWorker extends Worker {
- private int MAX_RETRIES = 5;
+ private volatile int maxRetries = 5;
+ private volatile int retryInterval = 5000;
- private int retryInterval = 5000;
- SubscribeWorker(Vector _requestQueue) {
+ public SubscribeWorker(Vector _requestQueue) {
super(_requestQueue);
}
+
+ public void setMaxRetries(int maxRetries) {
+ this.maxRetries = maxRetries;
+ }
+
+ public void setRetryInterval(int retryInterval) {
+ this.retryInterval = retryInterval;
+ }
@Override
void process(HttpRequest hreq) {
HttpResponse hresp = null;
int currentRetryAttempt = 1;
- while (currentRetryAttempt <= MAX_RETRIES) {
+ log.trace("Max Retries : " + maxRetries);
+ log.trace("Retry interval : " + retryInterval);
+ while (currentRetryAttempt <= maxRetries) {
try {
log.debug(hreq.getUrl());
hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders());
@@ -160,7 +170,7 @@ void process(HttpRequest hreq) {
}
catch (SocketTimeoutException e){
log.trace("Exception in Fetch : " + e.toString());
- currentRetryAttempt = MAX_RETRIES + 1;
+ currentRetryAttempt = maxRetries + 1;
break;
}
catch (NoHttpResponseException e){
@@ -179,7 +189,7 @@ void process(HttpRequest hreq) {
}
if (hresp == null) {
log.debug("Error in fetching url : " + hreq.getUrl());
- if (currentRetryAttempt > MAX_RETRIES) {
+ if (currentRetryAttempt > maxRetries) {
log.trace("Exhausted number of retries");
hreq.getResponseHandler().handleTimeout();
} else
@@ -198,7 +208,7 @@ void process(HttpRequest hreq) {
private static int _maxWorkers = 1;
protected Vector _waiting = new Vector();
- private Worker _workers[];
+ protected Worker _workers[];
public static int getWorkerCount() {
return _maxWorkers;
@@ -294,6 +304,18 @@ public void stop() {
}
class SubscribeManager extends RequestManager {
+
+ public void setMaxRetries(int maxRetries) {
+ for (int i = 0; i < _workers.length; i++){
+ ((SubscribeWorker)_workers[i]).setMaxRetries(maxRetries);
+ }
+ }
+
+ public void setRetryInterval(int retryInterval) {
+ for (int i = 0; i < _workers.length; i++){
+ ((SubscribeWorker)_workers[i]).setRetryInterval(retryInterval);
+ }
+ }
public SubscribeManager(String name) {
super(name);
Please sign in to comment.
Something went wrong with that request. Please try again.