Skip to content

Commit fec67b2

Browse files
committed
rename EventStream.close() to more appropriate cancel()
1 parent 1e71c33 commit fec67b2

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

src/AndroidClient/android/src/main/java/net/servicestack/android/AndroidServerEventsClient.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.ArrayList;
2727
import java.util.HashMap;
2828
import java.util.List;
29+
import java.util.concurrent.TimeUnit;
2930

3031
import okhttp3.Call;
3132
import okhttp3.Callback;
@@ -47,7 +48,8 @@ public AndroidServerEventsClient(String baseUri, String... channels) {
4748
this.serviceClient = new AndroidServiceClient(this.baseUri);
4849

4950
client = new OkHttpClient.Builder()
50-
.cookieJar(new JavaNetCookieJar(CookieHandler.getDefault()))
51+
.cookieJar(new JavaNetCookieJar(CookieHandler.getDefault())) //sync cookies with Android HTTP
52+
.readTimeout(0, TimeUnit.MILLISECONDS) //disable Read Timeout on long poll /event-stream
5153
.build();
5254
}
5355

@@ -99,9 +101,10 @@ protected InputStream getInputStream(URL streamUri) throws IOException {
99101
}
100102

101103
@Override
102-
public void close() {
103-
if (call == null) return;
104-
call.cancel();
104+
public void cancel() {
105+
if (call != null){
106+
call.cancel();
107+
}
105108
}
106109

107110
@Override
@@ -129,7 +132,7 @@ protected int readFromStream(InputStream inputStream, byte[] buffer) throws IOEx
129132
@Override
130133
protected synchronized void stopBackgroundThread() {
131134
if (bgThread != null){
132-
bgEventStream.close();
135+
bgEventStream.cancel();
133136
try {
134137
bgThread.join(100);
135138
} catch (InterruptedException ignore) {}

src/AndroidClient/android/src/main/java/net/servicestack/client/sse/EventStream.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ protected InputStream getInputStream(URL streamUri) throws IOException {
2828
return new BufferedInputStream(req.getInputStream());
2929
}
3030

31-
public void close(){
31+
public void cancel(){
3232
}
3333

3434
@Override
3535
public void run() {
36+
InputStream is = null;
3637
try {
3738
if (client.running.get())
3839
return;
3940
client.running.set(true);
4041

4142
URL streamUri = new URL(client.getEventStreamUri());
42-
InputStream is = getInputStream(streamUri);
43+
is = getInputStream(streamUri);
4344
client.errorsCount.set(0);
4445
readStream(is);
4546
} catch (InterruptedException ie){
@@ -50,6 +51,7 @@ public void run() {
5051
Log.e("Error reading from event-stream, continuous errors: " + client.errorsCount.incrementAndGet(), e);
5152
Log.e(Utils.getStackTrace(e));
5253
} finally {
54+
Utils.closeQuietly(is);
5355
client.running.set(false);
5456
}
5557

src/AndroidClient/android/src/main/java/net/servicestack/client/sse/ServerEventsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public String getConnectionDisplayName() {
274274

275275
protected synchronized void stopBackgroundThread() {
276276
if (bgThread != null){
277-
bgEventStream.close();
277+
bgEventStream.cancel();
278278
bgThread.interrupt(); //notify the bgThread to exit
279279
try {
280280
bgThread.join();

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/EventStream.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ protected InputStream getInputStream(URL streamUri) throws IOException {
2828
return new BufferedInputStream(req.getInputStream());
2929
}
3030

31-
public void close(){
31+
public void cancel(){
3232
}
3333

3434
@Override
3535
public void run() {
36+
InputStream is = null;
3637
try {
3738
if (client.running.get())
3839
return;
3940
client.running.set(true);
4041

4142
URL streamUri = new URL(client.getEventStreamUri());
42-
InputStream is = getInputStream(streamUri);
43+
is = getInputStream(streamUri);
4344
client.errorsCount.set(0);
4445
readStream(is);
4546
} catch (InterruptedException ie){
@@ -50,6 +51,7 @@ public void run() {
5051
Log.e("Error reading from event-stream, continuous errors: " + client.errorsCount.incrementAndGet(), e);
5152
Log.e(Utils.getStackTrace(e));
5253
} finally {
54+
Utils.closeQuietly(is);
5355
client.running.set(false);
5456
}
5557

src/AndroidClient/client/src/main/java/net/servicestack/client/sse/ServerEventsClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public String getConnectionDisplayName() {
274274

275275
protected synchronized void stopBackgroundThread() {
276276
if (bgThread != null){
277-
bgEventStream.close();
277+
bgEventStream.cancel();
278278
bgThread.interrupt(); //notify the bgThread to exit
279279
try {
280280
bgThread.join();

0 commit comments

Comments
 (0)