Skip to content

Commit 534d299

Browse files
committed
Cleanup and update for litesockets 4.0 release
1 parent 03abd3d commit 534d299

File tree

14 files changed

+37
-453
lines changed

14 files changed

+37
-453
lines changed

client/config/checkstyle/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
<property name="ignoredMethodNames" value="finalize, call, acceptConsumedItem"/>
7575
</module>
7676
<module name="MagicNumber">
77-
<property name="ignoreNumbers" value="-2, -1, 0, 1, 2, 10, 100, 1000"/>
77+
<property name="ignoreNumbers" value="-2, -1, 0, 1, 2, 8, 10, 100, 1000"/>
7878
</module>
7979
<module name="MissingSwitchDefault"/>
8080
<module name="NoFinalizer">

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.threadly.concurrent.future.ListenableFuture;
2121
import org.threadly.concurrent.future.SettableListenableFuture;
2222
import org.threadly.litesockets.Client;
23-
import org.threadly.litesockets.Client.CloseListener;
23+
import org.threadly.litesockets.Client.ClientCloseListener;
2424
import org.threadly.litesockets.Client.Reader;
2525
import org.threadly.litesockets.NoThreadSocketExecuter;
2626
import org.threadly.litesockets.SocketExecuter;
@@ -45,8 +45,7 @@
4545
/**
4646
* <p>This is a HTTPClient for doing many simple HTTPRequests. Every request will be make a new connection and requests
4747
* can be done in parallel. This is mainly used for doing many smaller Request and Response messages as the full Request/Response
48-
* is kept in memory and are not handled as streams. See {@link HTTPStreamClient} for use with large HTTP data sets.</p>
49-
*
48+
* is kept in memory and are not handled as streams. See {@link HTTPStreamClient} for use with large HTTP data sets.</p>
5049
*/
5150
public class HTTPClient extends AbstractService {
5251
public static final int DEFAULT_CONCURRENT = 2;
@@ -466,10 +465,9 @@ public void run() {
466465
}
467466

468467
/**
469-
*
470-
*
468+
* Class for accepting data into the request processor as well handling the close event.
471469
*/
472-
private class MainClientProcessor implements Reader, CloseListener {
470+
private class MainClientProcessor implements Reader, ClientCloseListener {
473471
@Override
474472
public void onClose(Client client) {
475473
HTTPRequestWrapper hrw = inProcess.get(client);
@@ -502,7 +500,6 @@ public void onRead(Client client) {
502500

503501
/**
504502
*
505-
*
506503
*/
507504
private class HTTPRequestWrapper implements HTTPResponseCallback {
508505
private final SettableListenableFuture<HTTPResponseData> slf = new SettableListenableFuture<>(false);
@@ -562,7 +559,7 @@ public void hasError(Throwable t) {
562559
}
563560

564561
/**
565-
* This is a simple, full HttpResponse with data
562+
* This is a simple, full HttpResponse with data.
566563
*/
567564
public static class HTTPResponseData {
568565
private final HTTPResponse hr;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.threadly.concurrent.future.ListenableFuture;
1212
import org.threadly.concurrent.future.SettableListenableFuture;
1313
import org.threadly.litesockets.Client;
14-
import org.threadly.litesockets.Client.CloseListener;
14+
import org.threadly.litesockets.Client.ClientCloseListener;
1515
import org.threadly.litesockets.Client.Reader;
1616
import org.threadly.litesockets.SocketExecuter;
1717
import org.threadly.litesockets.TCPClient;
@@ -44,7 +44,7 @@
4444
public class HTTPStreamClient implements StreamingClient {
4545
private static final int DEFAULT_TIMEOUT = 20000;
4646
private final Reader classReader = new HTTPReader();
47-
private final CloseListener classCloser = new HTTPCloser();
47+
private final ClientCloseListener classCloser = new HTTPCloser();
4848
private final RunnableListenerHelper closeListener = new RunnableListenerHelper(true);
4949
private final RequestCallback requestCB = new RequestCallback();
5050
private final TCPClient client;
@@ -238,7 +238,7 @@ public void onRead(Client client) {
238238
* @author lwahlmeier
239239
*
240240
*/
241-
private class HTTPCloser implements CloseListener {
241+
private class HTTPCloser implements ClientCloseListener {
242242
@Override
243243
public void onClose(Client client) {
244244
isConnected = false;

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import static org.junit.Assert.fail;
66

77
import java.io.IOException;
8-
import java.io.InputStream;
98
import java.net.URL;
109
import java.nio.ByteBuffer;
1110
import java.util.HashMap;
@@ -25,8 +24,6 @@
2524
import org.threadly.litesockets.SocketExecuter;
2625
import org.threadly.litesockets.TCPServer;
2726
import org.threadly.litesockets.ThreadedSocketExecuter;
28-
import org.threadly.litesockets.buffers.MergedByteBuffers;
29-
import org.threadly.litesockets.buffers.ReuseableMergedByteBuffers;
3027
import org.threadly.litesockets.client.http.HTTPClient.HTTPResponseData;
3128
import org.threadly.litesockets.protocols.http.request.HTTPRequest;
3229
import org.threadly.litesockets.protocols.http.request.HTTPRequestBuilder;
@@ -37,10 +34,9 @@
3734
import org.threadly.litesockets.protocols.http.shared.HTTPHeaders;
3835
import org.threadly.litesockets.protocols.http.shared.HTTPParsingException;
3936
import org.threadly.litesockets.utils.IOUtils;
37+
import org.threadly.litesockets.utils.PortUtils;
4038
import org.threadly.test.concurrent.TestCondition;
4139
import org.threadly.util.Clock;
42-
import org.w3c.dom.Element;
43-
import org.xml.sax.SAXException;
4440

4541
public class HTTPClientTests {
4642
static String CONTENT = "TEST123";
@@ -86,7 +82,7 @@ public void stop() {
8682
@Test
8783
public void manyRequestsConcurrent() throws IOException {
8884
final int number = 500;
89-
final int port = TestUtils.findTCPPort();
85+
final int port = PortUtils.findTCPPort();
9086
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, false, false);
9187
final HTTPRequestBuilder hrb = new HTTPRequestBuilder().setPort(port);
9288
final HTTPClient httpClient = new HTTPClient();
@@ -140,7 +136,7 @@ public boolean get() {
140136
@Test
141137
public void manyRequestsConcurrentJavaExecutor() throws IOException, InterruptedException {
142138
final int number = 500;
143-
final int port = TestUtils.findTCPPort();
139+
final int port = PortUtils.findTCPPort();
144140
final ThreadedSocketExecuter TSE = new ThreadedSocketExecuter(PS);
145141
TSE.start();
146142
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, false, false);
@@ -200,7 +196,7 @@ public boolean get() {
200196
@Test
201197
public void manyRequestsConcurrentOnPool() throws IOException {
202198
final int number = 500;
203-
final int port = TestUtils.findTCPPort();
199+
final int port = PortUtils.findTCPPort();
204200
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, false, false);
205201
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
206202
final ThreadedSocketExecuter TSE = new ThreadedSocketExecuter(PS);
@@ -257,7 +253,7 @@ public boolean get() {
257253

258254
@Test
259255
public void blockingRequest() throws IOException, HTTPParsingException {
260-
int port = TestUtils.findTCPPort();
256+
int port = PortUtils.findTCPPort();
261257
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, false, true);
262258
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
263259
final HTTPClient httpClient = new HTTPClient();
@@ -267,7 +263,7 @@ public void blockingRequest() throws IOException, HTTPParsingException {
267263

268264
@Test
269265
public void noContentLengthNoBody() throws IOException, HTTPParsingException {
270-
int port = TestUtils.findTCPPort();
266+
int port = PortUtils.findTCPPort();
271267
fakeServer = new TestHTTPServer(port, RESPONSE_NO_CL, "", false, true);
272268
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
273269
final HTTPClient httpClient = new HTTPClient();
@@ -278,7 +274,7 @@ public void noContentLengthNoBody() throws IOException, HTTPParsingException {
278274

279275
@Test
280276
public void noContentLengthWithBody() throws IOException, HTTPParsingException {
281-
int port = TestUtils.findTCPPort();
277+
int port = PortUtils.findTCPPort();
282278
fakeServer = new TestHTTPServer(port, RESPONSE_NO_CL, CONTENT, false, true);
283279
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
284280
final HTTPClient httpClient = new HTTPClient();
@@ -290,7 +286,7 @@ public void noContentLengthWithBody() throws IOException, HTTPParsingException {
290286

291287
@Test
292288
public void closeBeforeLength() throws IOException, HTTPParsingException {
293-
int port = TestUtils.findTCPPort();
289+
int port = PortUtils.findTCPPort();
294290
fakeServer = new TestHTTPServer(port, RESPONSE_HUGE, CONTENT, false, true);
295291
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
296292
final HTTPClient httpClient = new HTTPClient();
@@ -306,7 +302,7 @@ public void closeBeforeLength() throws IOException, HTTPParsingException {
306302

307303
@Test
308304
public void timeoutRequest() throws IOException, HTTPParsingException {
309-
int port = TestUtils.findTCPPort();
305+
int port = PortUtils.findTCPPort();
310306
TCPServer server = SEI.createTCPServer("localhost", port);
311307
server.start();
312308
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
@@ -322,7 +318,7 @@ public void timeoutRequest() throws IOException, HTTPParsingException {
322318

323319
@Test
324320
public void expireRequest() throws IOException, HTTPParsingException {
325-
int port = TestUtils.findTCPPort();
321+
int port = PortUtils.findTCPPort();
326322
fakeServer = new TestHTTPServer(port, RESPONSE_CL, "", false, false);
327323
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
328324
final HTTPClient httpClient = new HTTPClient();
@@ -339,7 +335,7 @@ public void expireRequest() throws IOException, HTTPParsingException {
339335

340336
@Test
341337
public void sslRequest() throws IOException, HTTPParsingException {
342-
int port = TestUtils.findTCPPort();
338+
int port = PortUtils.findTCPPort();
343339
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, true, false);
344340
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("https://localhost:"+port));
345341
final HTTPClient httpClient = new HTTPClient();
@@ -349,7 +345,7 @@ public void sslRequest() throws IOException, HTTPParsingException {
349345

350346
@Test
351347
public void toLargeRequest() throws IOException, HTTPParsingException {
352-
int port = TestUtils.findTCPPort();
348+
int port = PortUtils.findTCPPort();
353349
fakeServer = new TestHTTPServer(port, RESPONSE_HUGE, LARGE_CONTENT, false, false);
354350
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
355351
final HTTPClient httpClient = new HTTPClient();
@@ -364,7 +360,7 @@ public void toLargeRequest() throws IOException, HTTPParsingException {
364360

365361
@Test
366362
public void toLargeRequestNoContentLength() throws IOException, HTTPParsingException {
367-
int port = TestUtils.findTCPPort();
363+
int port = PortUtils.findTCPPort();
368364
fakeServer = new TestHTTPServer(port, RESPONSE_NO_CL, LARGE_CONTENT, false, true);
369365
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost:"+port));
370366
final HTTPClient httpClient = new HTTPClient();
@@ -409,7 +405,7 @@ public void toLargeRequestNoContentLength() throws IOException, HTTPParsingExcep
409405

410406
@Test
411407
public void timeOut() throws IOException, InterruptedException, ExecutionException, TimeoutException {
412-
int port = TestUtils.findTCPPort();
408+
int port = PortUtils.findTCPPort();
413409
TCPServer server = SEI.createTCPServer("localhost", port);
414410
server.setClientAcceptor(new ClientAcceptor() {
415411
@Override
@@ -437,7 +433,7 @@ public void accept(Client c) {
437433

438434
@Test
439435
public void urlRequest() throws HTTPParsingException, IOException {
440-
int port = TestUtils.findTCPPort();
436+
int port = PortUtils.findTCPPort();
441437
fakeServer = new TestHTTPServer(port, RESPONSE_CL, CONTENT, false, false);
442438
final HTTPClient httpClient = new HTTPClient();
443439
httpClient.start();

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.threadly.litesockets.protocols.http.response.HTTPResponse;
2424
import org.threadly.litesockets.protocols.http.response.HTTPResponseBuilder;
2525
import org.threadly.litesockets.protocols.http.shared.HTTPConstants;
26+
import org.threadly.litesockets.utils.PortUtils;
2627
import org.threadly.test.concurrent.TestCondition;
2728

2829
public class HTTPStreamClientTest {
@@ -50,7 +51,7 @@ public void stop() {
5051

5152
@Test
5253
public void chunkRecvTest() throws IOException, InterruptedException, ExecutionException {
53-
final int port = TestUtils.findTCPPort();
54+
final int port = PortUtils.findTCPPort();
5455
final int number = 300;
5556
fakeServer = new FakeHTTPStreamingServer(port, RESPONSE_CHUNKED, "", number, false, true);
5657
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost/dl.php"));//.setChunked();
@@ -91,8 +92,7 @@ public boolean get() {
9192

9293
@Test
9394
public void CLRecvTest() throws IOException, InterruptedException, ExecutionException {
94-
final int port = TestUtils.findTCPPort();
95-
final int number = 300;
95+
final int port = PortUtils.findTCPPort();
9696
fakeServer = new FakeHTTPStreamingServer(port, HTTPClientTests.RESPONSE_HUGE, HTTPClientTests.LARGE_CONTENT, 0, false, false);
9797
final HTTPRequestBuilder hrb = new HTTPRequestBuilder(new URL("http://localhost/dl.php"));//.setChunked();
9898
final HTTPStreamClient hsc = new HTTPStreamClient(SEI, "localhost", port);

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

Lines changed: 0 additions & 20 deletions
This file was deleted.

0 commit comments

Comments
 (0)