From 7c3a53f3223c86541cdeb9d1c5109a9e502cdf40 Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 9 Jul 2013 22:38:18 +0530 Subject: [PATCH] remove sleep from first attempt in subscribe thread --- .../examples/blackberry/AuthKeyConfig.java | 40 +++++++++++++++++++ .../examples/blackberry/DetailedHistory.java | 2 +- .../pubnub/examples/blackberry/HereNow.java | 2 +- .../pubnub/examples/blackberry/Publish.java | 2 +- j2me/src1/com/pubnub/api/SubscribeWorker.java | 13 ++++-- 5 files changed, 52 insertions(+), 7 deletions(-) create mode 100644 blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/AuthKeyConfig.java diff --git a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/AuthKeyConfig.java b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/AuthKeyConfig.java new file mode 100644 index 000000000..ac35b9b26 --- /dev/null +++ b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/AuthKeyConfig.java @@ -0,0 +1,40 @@ +package com.pubnub.examples.blackberry; + +import net.rim.device.api.ui.Field; +import net.rim.device.api.ui.FieldChangeListener; +import net.rim.device.api.ui.component.BasicEditField; +import net.rim.device.api.ui.component.ButtonField; +import net.rim.device.api.ui.container.MainScreen; + +import com.pubnub.api.Pubnub; + +public class AuthKeyConfig extends PubnubCommand { + + public AuthKeyConfig(Pubnub pubnub) { + super(pubnub, "Auth Key Config"); + } + + protected void initScreen() { + final BasicEditField txtAuthKey = new BasicEditField("Auth Key : ", "", 256, BasicEditField.FILTER_DEFAULT); + screen = new MainScreen(); + screen.add(txtAuthKey); + + ButtonField btn = new ButtonField(); + btn.setLabel("Set Auth Key"); + screen.add(btn); + + btn.setChangeListener(new FieldChangeListener() { + + public void fieldChanged(Field field, int context) { + + try { + _pubnub.setAuthKey(txtAuthKey.getText()); + close(); + } catch (Exception e) { + + } + }}); + } +} + + diff --git a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/DetailedHistory.java b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/DetailedHistory.java index a71956f6f..b4fb7bd57 100644 --- a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/DetailedHistory.java +++ b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/DetailedHistory.java @@ -35,7 +35,7 @@ public void successCallback(String channel, Object message) { notifyUser(message.toString()); } - public void errorCallback(String channel, PubnubError message) { + public void errorCallback(String channel, PubnubError error) { notifyUser(channel + " : " + error.toString()); } }); diff --git a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/HereNow.java b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/HereNow.java index e43458404..204362a48 100644 --- a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/HereNow.java +++ b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/HereNow.java @@ -33,7 +33,7 @@ public void successCallback(String channel, Object message) { notifyUser(message.toString()); } - public void errorCallback(String channel, PubnubError message) { + public void errorCallback(String channel, PubnubError error) { notifyUser(channel + " : " + error.toString()); } }); diff --git a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/Publish.java b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/Publish.java index 617cc4e2a..b0781b662 100644 --- a/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/Publish.java +++ b/blackberry/examples/PubnubExample/src/com/pubnub/examples/blackberry/Publish.java @@ -36,7 +36,7 @@ public void successCallback(String channel, Object message) { notifyUser(message.toString()); } - public void errorCallback(String channel, PubnubError message) { + public void errorCallback(String channel, PubnubError error) { notifyUser(channel + " : " + error.toString()); } }); diff --git a/j2me/src1/com/pubnub/api/SubscribeWorker.java b/j2me/src1/com/pubnub/api/SubscribeWorker.java index ee2ab4509..e8f360689 100644 --- a/j2me/src1/com/pubnub/api/SubscribeWorker.java +++ b/j2me/src1/com/pubnub/api/SubscribeWorker.java @@ -17,7 +17,15 @@ void process(HttpRequest hreq) { HttpResponse hresp = null; int currentRetryAttempt = (hreq.isDar())?1:maxRetries; log.verbose("disconnectAndResubscribe is " + hreq.isDar()); + boolean sleep = false; while (!_die && currentRetryAttempt <= maxRetries) { + if (sleep) { + try { + Thread.sleep(retryInterval); + } catch (InterruptedException e) { + } + sleep = true; + } try { log.debug(hreq.getUrl()); hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders()); @@ -56,10 +64,7 @@ void process(HttpRequest hreq) { currentRetryAttempt++; } - try { - Thread.sleep(retryInterval); - } catch (InterruptedException e) { - } + } if (!_die) { if (hresp == null) {