Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

disconnectAndResub

  • Loading branch information...
commit e0cd1be88d44d9e2fb31448a173f7f8fbaf8d2fe 1 parent be70371
@devendram devendram authored
View
BIN  java/3.4/Pubnub-Standardedition-3.4.jar
Binary file not shown
View
3  java/3.4/build.xml
@@ -11,6 +11,7 @@
<pathelement location="libs/bouncycastle.jar"/>
<pathelement location="libs/json.jar"/>
<pathelement location="libs/commons-codec-1.5.jar"/>
+ <pathelement location="libs/log4j-1.2.17.jar"/>
</path>
<target name="init">
<mkdir dir="bin"/>
@@ -74,7 +75,7 @@
<attribute name="Company" value="Pubnub" />
<attribute name="Project" value="pubnub-api" />
<attribute name="Java-Version" value="${java.version}" />
- <attribute name="Rsrc-Class-Path" value="./ httpcore-4.2.2.jar httpclient-4.2.2.jar bouncycastle.jar json.jar commons-logging-1.1.1.jar commons-codec-1.5.jar " />
+ <attribute name="Rsrc-Class-Path" value="./ log4j-1.2.17.jar httpcore-4.2.2.jar httpclient-4.2.2.jar bouncycastle.jar json.jar commons-logging-1.1.1.jar commons-codec-1.5.jar " />
<attribute name="Class-Path" value="." />
<attribute name="Rsrc-Main-Class" value="@{jar.classname}" />
<attribute name="Main-Class" value="org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader" />
View
22 java/3.4/examples/src/com/pubnub/examples/PubnubExample.java
@@ -2,6 +2,7 @@
import java.util.Hashtable;
+import org.apache.log4j.Logger;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -26,13 +27,14 @@ public PubnubExample() {
*/
public static void main(String[] params) {
+ int counter = 0;
PubnubExample pex = new PubnubExample();
pex._pubnub.setSubscribeTimeout(310000);
pex._pubnub.setNonSubscribeTimeout(15000);
Pubnub.startHeartbeat(5000);
-
+/*
System.out.println("\nRunning publish()");
pex.publish();
@@ -46,10 +48,22 @@ public static void main(String[] params) {
pex.detailedHistory();
System.out.println("\nRunning presence()");
- pex.presence();
+ pex.presence();*/
System.out.println("\nRunning subscribe()");
- pex.subscribe();
+ pex.subscribe(new String[]{"hello_world" + "-" + String.valueOf(counter)});
+
+ while (true) {
+ counter = (counter + 1) % 9;
+ try {
+ Thread.sleep((long) ((Math.random() % 9 ) * 1000));
+ } catch (InterruptedException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ pex._pubnub.disconnectAndResubscribe();
+ pex.subscribe(new String[]{"hello_world" + "-" + String.valueOf(counter)});
+ }
}
@@ -77,7 +91,7 @@ public void errorCallback(String channel, Object message) {
});
}
- public void subscribe() {
+ public void subscribe(String[] channels) {
Hashtable args = new Hashtable(6);
args.put("channels", channels);
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/src/com/pubnub/httpclient/HttpClientCore.java
@@ -22,6 +22,7 @@
public class HttpClientCore extends HttpClient {
private int requestTimeout = 310000;
private int connectionTimeout = 5000;
+ private DefaultHttpClient defaultHttpClient;
private DecompressingHttpClient httpClient;
private Hashtable _headers;
private HttpGet httpGet;
@@ -33,7 +34,7 @@ public void abortCurrentRequest(){
}
public HttpClientCore() {
DefaultHttpRequestRetryHandler retryHandler = new DefaultHttpRequestRetryHandler(0, false);
- DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
+ defaultHttpClient = new DefaultHttpClient();
defaultHttpClient.setHttpRequestRetryHandler(retryHandler);
httpClient = new DecompressingHttpClient(defaultHttpClient);
_headers = new Hashtable();
@@ -142,4 +143,7 @@ public synchronized HttpResponse fetch(String url, Hashtable headers) throws IOE
public boolean isOk(int rc) {
return (rc == HttpStatus.SC_OK );
}
+ public void shutdown() {
+ defaultHttpClient.getConnectionManager().shutdown();
+ }
}
View
134 java/3.4/srcPubnubApi/com/pubnub/api/Pubnub.java
@@ -4,6 +4,7 @@
import java.util.Hashtable;
import org.apache.commons.codec.binary.Hex;
+import org.apache.log4j.Logger;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.InvalidCipherTextException;
import org.bouncycastle.util.SecureRandom;
@@ -26,11 +27,16 @@
public class Pubnub {
- private String ORIGIN = "pubsub.pubnub.com";
+ private String HOSTNAME = "pubsub";
+ private int HOSTNAME_SUFFIX = 1;
+ private String DOMAIN = "pubnub.com";
+ private String ORIGIN_STR = null;
private String PUBLISH_KEY = "";
private String SUBSCRIBE_KEY = "";
private String SECRET_KEY = "";
private String CIPHER_KEY = "";
+ private boolean resumeOnReconnect;
+
private boolean SSL = true;
private String UUID = null;
private Hashtable _headers;
@@ -40,14 +46,39 @@
private HttpManager simpleConnManager;
private PubnubCrypto pc;
private String _timetoken = "0";
-
+ private String _saved_timetoken = "0";
+
private String PRESENCE_SUFFIX = "-pnpres";
+
+ private static Logger log = Logger.getLogger(
+ Pubnub.class.getName());
public void shutdown() {
longPollConnManager.stop();
simpleConnManager.stop();
}
-
+
+ public boolean isResumeOnReconnect() {
+ return resumeOnReconnect;
+ }
+
+ private String getOrigin() {
+ if (ORIGIN_STR == null) {
+ // SSL On?
+ if (this.SSL) {
+ ORIGIN_STR = "https://" + HOSTNAME + "-" + String.valueOf(HOSTNAME_SUFFIX) + "." + DOMAIN;
+ } else {
+ ORIGIN_STR = "http://" + HOSTNAME + "-" + String.valueOf(HOSTNAME_SUFFIX) + "." + DOMAIN;
+ }
+ }
+ return ORIGIN_STR;
+ }
+
+ public void setResumeOnReconnect(boolean resumeOnReconnect) {
+ this.resumeOnReconnect = resumeOnReconnect;
+ }
+
+
/** Convert input String to JSONObject, JSONArray, or String
* @param String str
* @return Object
@@ -217,13 +248,6 @@ private void init(String publish_key, String subscribe_key,
this.CIPHER_KEY = cipher_key;
this.SSL = ssl_on;
- // SSL On?
- if (this.SSL) {
- this.ORIGIN = "https://" + this.ORIGIN;
- } else {
- this.ORIGIN = "http://" + this.ORIGIN;
- }
-
if (UUID == null)
UUID = uuid();
@@ -243,11 +267,11 @@ private void init(String publish_key, String subscribe_key,
_headers.put("Accept-Encoding", "deflate");
}
-
+
public void setSubscribeTimeout(int timeout) {
longPollConnManager.setRequestTimeout(timeout);
}
-
+
public void setNonSubscribeTimeout(int timeout) {
simpleConnManager.setRequestTimeout(timeout);
}
@@ -362,7 +386,7 @@ public void publish(Hashtable args) {
return;
}
}
-
+
// Generate String to Sign
String signature = "0";
@@ -377,12 +401,12 @@ public void publish(Hashtable args) {
// Sign Message
signature = Hex.encodeHexString(PubnubCrypto.md5(string_to_sign.toString()));
}
- String[] urlComponents = { this.ORIGIN, "publish", PubnubUtil.urlEncode(this.PUBLISH_KEY),
+ String[] urlComponents = { getOrigin(), "publish", PubnubUtil.urlEncode(this.PUBLISH_KEY),
PubnubUtil.urlEncode(this.SUBSCRIBE_KEY), PubnubUtil.urlEncode(signature),
PubnubUtil.urlEncode(channel), PubnubUtil.urlEncode("0"),
PubnubUtil.urlEncode(msgStr)};
- PubnubRequest req = new PubnubRequest(urlComponents, channel,
+ HttpRequest hreq = new HttpRequest(urlComponents,
new ResponseHandler() {
public void handleResponse(String response) {
JSONArray jsarr;
@@ -409,7 +433,7 @@ public void handleError(String response) {
}
});
- _request(req, simpleConnManager);
+ _request(hreq, simpleConnManager);
}
/**
@@ -443,10 +467,10 @@ public void presence(String channel, Callback callback)
*/
public void hereNow(final String channel, final Callback callback) {
- String[] urlargs = { this.ORIGIN, "v2", "presence", "sub_key",
+ String[] urlargs = { getOrigin(), "v2", "presence", "sub_key",
this.SUBSCRIBE_KEY, "channel", channel };
- PubnubRequest req = new PubnubRequest(urlargs, (String) null,
+ HttpRequest hreq = new HttpRequest(urlargs,
new ResponseHandler() {
public void handleResponse(String response) {
JSONObject jsobj;
@@ -473,7 +497,7 @@ public void handleError(String response) {
}
});
- _request(req, simpleConnManager);
+ _request(hreq, simpleConnManager);
}
/**
@@ -513,10 +537,10 @@ private void history(Hashtable args) {
String limit = (String) args.get("limit");
final Callback callback = (Callback) args.get("callback");
- String[] urlargs = { this.ORIGIN, "history", this.SUBSCRIBE_KEY,
+ String[] urlargs = { getOrigin(), "history", this.SUBSCRIBE_KEY,
channel, "0", limit };
- PubnubRequest req = new PubnubRequest(urlargs, channel, new ResponseHandler() {
+ HttpRequest hreq = new HttpRequest(urlargs, new ResponseHandler() {
public void handleResponse(String response) {
JSONArray jsarr;
@@ -543,7 +567,7 @@ public void handleError(String response) {
}
});
- _request(req, simpleConnManager);
+ _request(hreq, simpleConnManager);
}
/**
@@ -577,10 +601,10 @@ public void detailedHistory(final String channel, long start, long end,
if (end != -1)
parameters.put("end", Long.toString(end).toLowerCase());
- String[] urlargs = { this.ORIGIN, "v2", "history", "sub-key",
+ String[] urlargs = { getOrigin(), "v2", "history", "sub-key",
this.SUBSCRIBE_KEY, "channel", channel };
- PubnubRequest req = new PubnubRequest(urlargs, parameters, channel,
+ HttpRequest hreq = new HttpRequest(urlargs, parameters,
new ResponseHandler() {
public void handleResponse(String response) {
@@ -608,7 +632,7 @@ public void handleError(String response) {
}
});
- _request(req, simpleConnManager);
+ _request(hreq, simpleConnManager);
}
/**
@@ -717,8 +741,8 @@ public void detailedHistory(String channel, int count, Callback callback) {
*/
public void time(final Callback cb) {
- String[] url = { this.ORIGIN, "time", "0" };
- PubnubRequest req = new PubnubRequest(url, (String) null, new ResponseHandler() {
+ String[] url = { getOrigin(), "time", "0" };
+ HttpRequest hreq = new HttpRequest(url, new ResponseHandler() {
public void handleResponse(String response) {
cb.successCallback(null, response);
@@ -730,7 +754,7 @@ public void handleError(String response) {
});
- _request(req, simpleConnManager);
+ _request(hreq, simpleConnManager);
}
private boolean inputsValid(Hashtable args) throws PubnubException {
@@ -898,14 +922,14 @@ private void _subscribe(Hashtable args) {
return;
}
}
- _subscribe_base(timetoken);
+ _subscribe_base(true);
}
/**
* @param timetoken
* , Timetoken to be used
*/
- private void _subscribe_base(String timetoken) {
+ private void _subscribe_base(boolean fresh) {
String channelString = subscriptions.getChannelString();
String[] channelsArray = subscriptions.getChannelNames();
@@ -913,13 +937,14 @@ private void _subscribe_base(String timetoken) {
callErrorCallbacks(channelsArray, "Parsing Error");
return;
}
- String[] urlComponents = { Pubnub.this.ORIGIN, "subscribe",
- Pubnub.this.SUBSCRIBE_KEY, channelString, "0", timetoken };
+ String[] urlComponents = { getOrigin(), "subscribe",
+ Pubnub.this.SUBSCRIBE_KEY, channelString, "0", _timetoken };
Hashtable params = new Hashtable();
params.put("uuid", UUID);
+ //System.out.println("Subscribing with timetoken : " + _timetoken);
- PubnubRequest req = new PubnubRequest(urlComponents, params, channelsArray,
+ HttpRequest hreq = new HttpRequest(urlComponents, params,
new ResponseHandler() {
public void handleResponse(String response) {
@@ -938,7 +963,9 @@ public void handleResponse(String response) {
JSONArray jsa;
try {
jsa = new JSONArray(response);
- _timetoken = jsa.get(1).toString();
+ _timetoken = (!_saved_timetoken.equals("0") && isResumeOnReconnect())?
+ _saved_timetoken:jsa.get(1).toString();
+ _saved_timetoken = "0";
JSONArray messages = new JSONArray(jsa.get(0)
.toString());
@@ -1000,20 +1027,23 @@ public void handleResponse(String response) {
}
}
- _subscribe_base(_timetoken);
+ _subscribe_base(false);
} catch (JSONException e) {
- _subscribe_base(_timetoken);
+ _subscribe_base(false);
}
}
public void handleError(String response) {
subscriptions.invokeDisconnectCallbackOnChannels();
- _subscribe_base(_timetoken);
+ _subscribe_base(true);
+ }
+ public String getTimetoken() {
+ return _timetoken;
}
});
- _request(req, longPollConnManager, true);
+ _request(hreq, longPollConnManager, true);
}
/**
@@ -1021,23 +1051,31 @@ public void handleError(String response) {
* @param connManager
* @param abortExisting
*/
- private void _request(final PubnubRequest req, HttpManager connManager, boolean abortExisting) {
- HttpRequest hreq = new HttpRequest(req.getUrl(), _headers, req.responseHandler);
- if (abortExisting)
- connManager.abortAndQueue(hreq);
- else
- connManager.queue(hreq);
+ private void _request(final HttpRequest hreq, HttpManager connManager, boolean abortExisting) {
+ if (abortExisting)
+ connManager.resetHttpManager();
+ connManager.queue(hreq);
}
/**
* @param req
* @param connManager
*/
- private void _request(final PubnubRequest req, HttpManager connManager) {
- _request(req, connManager, false);
+ private void _request(final HttpRequest hreq, HttpManager connManager) {
+ _request(hreq, connManager, false);
}
-
+
+ private void changeOrigin() {
+ this.ORIGIN_STR = null;
+ this.HOSTNAME_SUFFIX = (this.HOSTNAME_SUFFIX + 1) % 9 ;
+ }
+
public void disconnectAndResubscribe() {
+ log.trace("Received disconnectAndResubscribe");
+ log.trace("RESUME_ON_RECONNECT is : " + isResumeOnReconnect());
subscriptions.invokeDisconnectCallbackOnChannels();
- _subscribe_base(this._timetoken);
+ changeOrigin();
+ _saved_timetoken = _timetoken;
+ _timetoken = "0";
+ _subscribe_base(true);
}
}
View
91 java/3.4/srcPubnubApi/com/pubnub/api/PubnubRequest.java
@@ -1,91 +0,0 @@
-package com.pubnub.api;
-
-import java.util.Enumeration;
-import java.util.Hashtable;
-
-import com.pubnub.http.ResponseHandler;
-
-/**
- *
- * @author Pubnub
- */
-class PubnubRequest {
-
- private String[] urlComponents;
- private Hashtable params;
- private String url;
- private String[] channels;
- ResponseHandler responseHandler;
-
- public String[] getChannels() {
-
- return this.channels;
- }
-
- public String getUrl() {
-
- if (url != null) {
- return url;
- }
-
- String url = PubnubUtil.joinString(urlComponents, "/");
-
- if (this.params != null) {
- StringBuffer sb = new StringBuffer();
- sb.append(url).append("?");
-
- Enumeration paramsKeys = this.params.keys();
- boolean first = true;
- while (paramsKeys.hasMoreElements()) {
- if (!first) {
- sb.append("&");
- } else
- first = false;
-
- String key = (String) paramsKeys.nextElement();
- sb.append(PubnubUtil.urlEncode((String) key))
- .append("=")
- .append(PubnubUtil.urlEncode((String) this.params
- .get(key)));
- }
-
- url = sb.toString();
- }
- this.url = url;
-
- return this.url;
- }
-
- public PubnubRequest(String[] urlComponents, String[] channels,
- ResponseHandler responseHandler) {
- this.channels = channels;
- this.responseHandler = responseHandler;
- this.urlComponents = urlComponents;
-
- }
-
- public PubnubRequest(String[] urlComponents, Hashtable params, String[] channels,
- ResponseHandler responseHandler) {
- this.channels = channels;
- this.responseHandler = responseHandler;
- this.params = params;
- this.urlComponents = urlComponents;
- }
-
- public PubnubRequest(String[] urlComponents, String channel,
- ResponseHandler responseHandler) {
-
- this.channels = new String[] { channel };
- this.responseHandler = responseHandler;
- this.urlComponents = urlComponents;
- }
-
- public PubnubRequest(String[] urlComponents, Hashtable params, String channel,
- ResponseHandler responseHandler) {
-
- this.channels = new String[] { channel };
- this.responseHandler = responseHandler;
- this.params = params;
- this.urlComponents = urlComponents;
- }
-}
View
2  java/3.4/srcPubnubApi/com/pubnub/api/PubnubUtil.java
@@ -8,7 +8,7 @@
*
* @author Pubnub
*/
-class PubnubUtil {
+public class PubnubUtil {
/**
* Takes source and delimiter string as inputs and returns splitted string
View
84 java/3.4/srcPubnubApi/com/pubnub/http/HttpManager.java
@@ -3,6 +3,8 @@
import java.io.IOException;
import java.util.Vector;
+import org.apache.log4j.Logger;
+
import com.pubnub.api.PubnubException;
import com.pubnub.httpclient.HttpClient;
import com.pubnub.httpclient.HttpResponse;
@@ -12,10 +14,14 @@
private static int _maxWorkers = 1;
private Vector _waiting = new Vector();
private Worker _workers[];
+ private Thread _threads[];
private static Heartbeat heartbeat;
private static Network network;
private HttpClient httpclient;
+ private static Logger log = Logger.getLogger(
+ HttpManager.class.getName());
+
public static void stopHeartbeat() {
heartbeat.stop();
}
@@ -51,10 +57,12 @@ private void initManager(int maxCalls, String name) {
maxCalls = 1;
}
_workers = new Worker[maxCalls];
+ _threads = new Thread[maxCalls];
for (int i = 0; i < maxCalls; ++i) {
Worker w = new Worker();
_workers[i] = w;
- new Thread(w, name).start();
+ _threads[i] = new Thread(w, name);
+ _threads[i].start();
}
if (network == null) {
network = new Network();
@@ -72,11 +80,31 @@ public HttpManager(String name) {
initManager(_maxWorkers, name);
}
- public void abortAndQueue(HttpRequest hreq) {
- httpclient.abortCurrentRequest();
+ private void interruptWorkers() {
+ for (int i = 0; i < _threads.length; i++){
+ _threads[i].interrupt();
+ }
+ }
+
+ public void abortCurrent(){
+ //httpclient.reset();
+ }
+ public void abortCurrentAndClear() {
+ abortCurrent();
synchronized(_waiting) {
_waiting.clear();
}
+ }
+ private void resetHttpClient() {
+ httpclient = httpclient.reset();
+
+ }
+ public void resetHttpManager() {
+ abortCurrentAndClear();
+ resetHttpClient();
+ }
+ public void abortClearAndQueue(HttpRequest hreq) {
+ resetHttpManager();
queue(hreq);
}
@@ -166,38 +194,48 @@ public void die() {
private void process(HttpRequest hreq) {
HttpResponse hresp = null;
- if (network.isAvailable()) {
- try {
- hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders());
- } catch (IOException e) {
- hreq.getResponseHandler().handleError(e.toString());
- return;
- } catch (PubnubException e) {
- return;
+
+ if (network.isAvailable()) {
+ try {
+ log.debug(hreq.getUrl());
+ try {
+ hresp = httpclient.fetch(hreq.getUrl(), hreq.getHeaders());
+ } catch (NullPointerException e) {
+ hreq.getResponseHandler().handleError("[0,'Network Error']");
+ return;
+ }
+ } catch (IOException e) {
+ hreq.getResponseHandler().handleError(e.toString());
+ return;
+ } catch (PubnubException e) {
+ return;
+ }
+ hreq.getResponseHandler().handleResponse(hresp.getResponse());
+ } else {
+ hreq.getResponseHandler().handleError("[0,'Network Error']");
}
- hreq.getResponseHandler().handleResponse(hresp.getResponse());
- } else {
- hreq.getResponseHandler().handleError("[0,'Network Error']");
- }
+
}
public void run() {
do {
HttpRequest hreq = null;
- synchronized (_waiting) {
- while (!_die) {
- if (!network.isAvailable()) {
- synchronized (network) {
- try {
- network.wait(5000);
- } catch (InterruptedException e1) {
+ while (!_die) {
+
+ if (!network.isAvailable()) {
+ synchronized (network) {
+ try {
+ network.wait(5000);
+ } catch (InterruptedException e1) {
- }
}
}
+ }
+ synchronized (_waiting) {
+
if (_waiting.size() != 0) {
hreq = (HttpRequest) _waiting.firstElement();
_waiting.removeElementAt(0);
View
75 java/3.4/srcPubnubApi/com/pubnub/http/HttpRequest.java
@@ -1,21 +1,51 @@
package com.pubnub.http;
+import java.util.Enumeration;
import java.util.Hashtable;
+import com.pubnub.api.PubnubUtil;
+
public class HttpRequest {
private ResponseHandler responseHandler;
- private String url;
private Hashtable headers;
+ private String[] urlComponents;
+ private Hashtable params;
+ private String url;
- public HttpRequest(String url, Hashtable headers, ResponseHandler rh){
- this.setUrl(url);
+ public HttpRequest(String[] urlComponents, Hashtable params, Hashtable headers, ResponseHandler rh){
+ this.setUrlComponents(urlComponents);
+ this.setParams(params);
this.setHeaders(headers);
this.setResponseHandler(rh);
}
- HttpRequest(String url, ResponseHandler rh){
- this.setUrl(url);
+
+ public HttpRequest(String[] urlComponents, Hashtable params, ResponseHandler rh){
+ this.setUrlComponents(urlComponents);
+ this.setParams(params);
+ this.setResponseHandler(rh);
+ }
+
+ public HttpRequest(String[] urlComponents, ResponseHandler rh){
+ this.setUrlComponents(urlComponents);
this.setResponseHandler(rh);
}
+
+ public String[] getUrlComponents() {
+ return urlComponents;
+ }
+
+ public void setUrlComponents(String[] urlComponents) {
+ this.urlComponents = urlComponents;
+ }
+
+ public Hashtable getParams() {
+ return params;
+ }
+
+ public void setParams(Hashtable params) {
+ this.params = params;
+ }
+
public ResponseHandler getResponseHandler() {
return responseHandler;
}
@@ -29,9 +59,36 @@ public void setHeaders(Hashtable headers) {
this.headers = headers;
}
public String getUrl() {
- return url;
- }
- public void setUrl(String url) {
- this.url = url;
+
+ if (url != null) {
+ return url;
+ }
+
+ String url = PubnubUtil.joinString(urlComponents, "/");
+
+ if (this.params != null) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(url).append("?");
+
+ Enumeration paramsKeys = this.params.keys();
+ boolean first = true;
+ while (paramsKeys.hasMoreElements()) {
+ if (!first) {
+ sb.append("&");
+ } else
+ first = false;
+
+ String key = (String) paramsKeys.nextElement();
+ sb.append(PubnubUtil.urlEncode((String) key))
+ .append("=")
+ .append(PubnubUtil.urlEncode((String) this.params
+ .get(key)));
+ }
+
+ url = sb.toString();
+ }
+ this.url = url;
+
+ return this.url;
}
}
View
11 java/3.4/srcPubnubApi/com/pubnub/httpclient/HttpClient.java
@@ -18,6 +18,13 @@ public HttpClient getClient(int requestTimeout) {
return new HttpClientCore(requestTimeout);
}
+ public synchronized HttpClient reset() {
+ int connTimeout = getConnectionTimeout();
+ int requestTimeout = getRequestTimeout();
+ shutdown();
+ return getClient(requestTimeout, connTimeout);
+
+ }
public abstract int getRequestTimeout();
public abstract void setRequestTimeout(int requestTimeout);
@@ -33,8 +40,10 @@ public HttpClient getClient(int requestTimeout) {
public abstract boolean checkResponse(int rc);
public abstract boolean isOk(int rc);
+
+ public abstract void shutdown();
- public abstract HttpResponse fetch(String url) throws IOException, PubnubException;
+ public abstract HttpResponse fetch(String url) throws IOException, PubnubException;
public abstract HttpResponse fetch(String url, Hashtable headers)
throws IOException, PubnubException;
Please sign in to comment.
Something went wrong with that request. Please try again.