Skip to content

Commit 0f3a34f

Browse files
committed
Upgrade threadly dependency
This includes the API changes for ListenableFuture
1 parent db5300a commit 0f3a34f

File tree

8 files changed

+26
-92
lines changed

8 files changed

+26
-92
lines changed

client/src/main/java/org/threadly/litesockets/client/http/HTTPStreamClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public Executor getClientsThreadExecutor() {
208208

209209
public ListenableFuture<Boolean> connect() {
210210
ListenableFuture<Boolean> lf = client.connect();
211-
lf.addCallback(new FutureCallback<Boolean>(){
211+
lf.callback(new FutureCallback<Boolean>(){
212212
@Override
213213
public void handleResult(Boolean result) {
214214
isConnected = true;

client/src/main/java/org/threadly/litesockets/client/websocket/WSClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ public ListenableFuture<?> getLastWriteFuture() {
327327
public ListenableFuture<Boolean> connect() {
328328
if(sentRequest.compareAndSet(false, true)) {
329329
hsc.connect();
330-
hsc.writeRequest(hrb.buildHTTPRequest()).addCallback(new FutureCallback<HTTPResponse>() {
330+
hsc.writeRequest(hrb.buildHTTPRequest()).callback(new FutureCallback<HTTPResponse>() {
331331
@Override
332332
public void handleResult(HTTPResponse result) {
333333
if(result.getResponseHeader().getResponseCode() == HTTPResponseCode.SwitchingProtocols) {

client/src/test/java/org/threadly/litesockets/client/http/HTTPClientTests.java

Lines changed: 13 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public void manyRequestsConcurrent() throws IOException {
9595
public void run() {
9696
ClientHTTPRequest chr = hrb.buildClientHTTPRequest();
9797
//final long start = Clock.accurateForwardProgressingMillis();
98-
final ListenableFuture<HTTPResponseData> lf = httpClient.requestAsync(chr);
99-
lf.addCallback(new FutureCallback<HTTPResponseData>() {
98+
final ListenableFuture<HTTPResponseData> lf = httpClient.requestAsync(chr);
99+
lf.callback(new FutureCallback<HTTPResponseData>() {
100100
@Override
101101
public void handleResult(HTTPResponseData result) {
102102
//System.out.println("DELAY:"+(Clock.accurateForwardProgressingMillis()-start));
@@ -106,19 +106,11 @@ public void handleResult(HTTPResponseData result) {
106106

107107
@Override
108108
public void handleFailure(Throwable t) {
109-
System.out.println("***********************ERR*******************");
110-
try {
111-
System.out.println(lf.get().getBodyAsString());
112-
} catch (InterruptedException e) {
113-
e.printStackTrace();
114-
} catch (ExecutionException e) {
115-
e.printStackTrace();
116-
}
117-
System.out.println("***********************ERR*******************");
109+
System.err.println("***********************ERR*******************");
110+
t.printStackTrace();
111+
System.err.println("***********************ERR*******************");
118112
fail();
119113
}});
120-
121-
122114
}};
123115

124116
for(int i=0; i<number; i++) {
@@ -153,7 +145,7 @@ public void run() {
153145
ClientHTTPRequest chr = hrb.buildClientHTTPRequest();
154146
//final long start = Clock.accurateForwardProgressingMillis();
155147
final ListenableFuture<HTTPResponseData> lf = httpClient.requestAsync(chr);
156-
lf.addCallback(new FutureCallback<HTTPResponseData>() {
148+
lf.callback(new FutureCallback<HTTPResponseData>() {
157149
@Override
158150
public void handleResult(HTTPResponseData result) {
159151
//System.out.println("DELAY:"+(Clock.accurateForwardProgressingMillis()-start));
@@ -163,19 +155,11 @@ public void handleResult(HTTPResponseData result) {
163155

164156
@Override
165157
public void handleFailure(Throwable t) {
166-
System.out.println("***********************ERR*******************");
167-
try {
168-
System.out.println(lf.get().getBodyAsString());
169-
} catch (InterruptedException e) {
170-
e.printStackTrace();
171-
} catch (ExecutionException e) {
172-
e.printStackTrace();
173-
}
174-
System.out.println("***********************ERR*******************");
158+
System.err.println("***********************ERR*******************");
159+
t.printStackTrace();
160+
System.err.println("***********************ERR*******************");
175161
fail();
176162
}});
177-
178-
179163
}};
180164

181165
for(int i=0; i<number; i++) {
@@ -215,7 +199,7 @@ public void run() {
215199
//final long start = Clock.accurateForwardProgressingMillis();
216200

217201
final ListenableFuture<HTTPResponseData> lf = httpClient.requestAsync(chr);
218-
lf.addCallback(new FutureCallback<HTTPResponseData>() {
202+
lf.callback(new FutureCallback<HTTPResponseData>() {
219203
@Override
220204
public void handleResult(HTTPResponseData result) {
221205
//System.out.println("DELAY:"+(Clock.accurateForwardProgressingMillis()-start));
@@ -225,19 +209,11 @@ public void handleResult(HTTPResponseData result) {
225209

226210
@Override
227211
public void handleFailure(Throwable t) {
228-
System.out.println("***********************ERR*******************");
229-
try {
230-
System.out.println(lf.get().getBodyAsString());
231-
} catch (InterruptedException e) {
232-
e.printStackTrace();
233-
} catch (ExecutionException e) {
234-
e.printStackTrace();
235-
}
236-
System.out.println("***********************ERR*******************");
212+
System.err.println("***********************ERR*******************");
213+
t.printStackTrace();
214+
System.err.println("***********************ERR*******************");
237215
fail();
238216
}});
239-
240-
241217
}};
242218

243219
for(int i=0; i<number; i++) {

client/src/test/java/org/threadly/litesockets/client/http/HTTPStreamClientTest.java

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import org.junit.Before;
1414
import org.junit.Test;
1515
import org.threadly.concurrent.PriorityScheduler;
16-
import org.threadly.concurrent.future.FutureCallback;
1716
import org.threadly.concurrent.future.ListenableFuture;
1817
import org.threadly.litesockets.SocketExecuter;
1918
import org.threadly.litesockets.ThreadedSocketExecuter;
@@ -66,18 +65,7 @@ public void handle(ByteBuffer bb) {
6665
hsc.connect();
6766

6867
final ListenableFuture<HTTPResponse> lf = hsc.writeRequest(hrb.buildHTTPRequest());
69-
lf.addCallback(new FutureCallback<HTTPResponse>() {
70-
71-
@Override
72-
public void handleResult(HTTPResponse result) {
73-
set.set(true);
74-
}
75-
76-
@Override
77-
public void handleFailure(Throwable t) {
78-
// TODO Auto-generated method stub
79-
80-
}});
68+
lf.resultCallback((result) -> set.set(true));
8169

8270
new TestCondition(){
8371
@Override
@@ -108,19 +96,10 @@ public void handle(ByteBuffer bb) {
10896

10997
final ListenableFuture<HTTPResponse> lf = hsc.writeRequest(hrb.buildHTTPRequest());
11098

111-
lf.addCallback(new FutureCallback<HTTPResponse>() {
112-
113-
@Override
114-
public void handleResult(HTTPResponse result) {
99+
lf.resultCallback((result) -> {
115100
set.set(true);
116-
count.addAndGet(Integer.parseInt(result.getHeaders().getHeader(HTTPConstants.HTTP_KEY_CONTENT_LENGTH)));
117-
}
118-
119-
@Override
120-
public void handleFailure(Throwable t) {
121-
// TODO Auto-generated method stub
122-
123-
}});
101+
count.addAndGet(Integer.parseInt(result.getHeaders().getHeader(HTTPConstants.HTTP_KEY_CONTENT_LENGTH)));
102+
});
124103

125104
new TestCondition(){
126105
@Override

client/src/test/java/org/threadly/litesockets/client/http/TestHTTPServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void headersFinished(HTTPRequest hreq) {
9292
}
9393
sendBack.rollback();
9494
if(closeOnSend) {
95-
lf.addListener(()->c.close());
95+
lf.listener(c::close);
9696
}
9797
hrp.reset();
9898
}

client/src/test/java/org/threadly/litesockets/client/websocket/WebSocketClientTest.java

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void onData(WSFrame wsf, ByteBuffer bb) {
7979
mbb.add(bb);
8080
response.compareAndSet(null, mbb.getAsString(mbb.remaining()));
8181
}});
82-
wsc.connect().addCallback(new FutureCallback<Boolean>(){
82+
wsc.connect().callback(new FutureCallback<Boolean>(){
8383
@Override
8484
public void handleResult(Boolean result) {
8585
wsc.write(ByteBuffer.wrap("ECHO".getBytes()), WSOPCode.Text, false);
@@ -176,20 +176,11 @@ public void onData(WSFrame wsf, ByteBuffer bb) {
176176

177177
}});
178178
wsc.addCloseListener(new Runnable() {
179-
180179
@Override
181180
public void run() {
182181
gotClose.set(true);
183182
}});
184-
wsc.connect().addCallback(new FutureCallback<Boolean>(){
185-
@Override
186-
public void handleResult(Boolean result) {
187-
}
188-
189-
@Override
190-
public void handleFailure(Throwable t) {
191-
gotFailure.set(true);
192-
}});
183+
wsc.connect().failureCallback((t) -> gotFailure.set(true));
193184

194185
new TestCondition(){
195186
@Override
@@ -225,15 +216,7 @@ public void onData(WSFrame wsf, ByteBuffer bb) {
225216
public void run() {
226217
gotClose.set(true);
227218
}});
228-
wsc.connect().addCallback(new FutureCallback<Boolean>(){
229-
@Override
230-
public void handleResult(Boolean result) {
231-
}
232-
233-
@Override
234-
public void handleFailure(Throwable t) {
235-
gotFailure.set(true);
236-
}});
219+
wsc.connect().failureCallback((t) -> gotFailure.set(true));
237220

238221
new TestCondition(){
239222
@Override

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
group = org.threadly
2-
version = 0.22
3-
threadlyVersion = 5.31
2+
version = 0.23-SNAPSHOT
3+
threadlyVersion = 5.34
44
litesocketsVersion = 4.9
55
org.gradle.parallel=false
66
junitVersion = 4.12

server/src/main/java/org/threadly/litesockets/server/http/HTTPServer.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,7 @@ public ListenableFuture<?> writeWebsocketFrame(WSOPCode wsoc, MergedByteBuffers
354354
public void done() {
355355
done = true;
356356
if(closeOnDone && !client.isClosed()) {
357-
client.lastWriteFuture().addListener(new Runnable(){
358-
@Override
359-
public void run() {
360-
client.close();
361-
}});
357+
client.lastWriteFuture().listener(client::close);
362358
}
363359
}
364360

0 commit comments

Comments
 (0)