Permalink
Browse files

disconnectAndResub

  • Loading branch information...
1 parent be70371 commit e0cd1be88d44d9e2fb31448a173f7f8fbaf8d2fe @devendram devendram committed Jan 30, 2013
Binary file not shown.
View
@@ -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" />
@@ -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);
Binary file not shown.
Binary file not shown.
@@ -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();
+ }
}
Oops, something went wrong.

0 comments on commit e0cd1be

Please sign in to comment.