Skip to content

Commit 7b31e6e

Browse files
committed
heavily rework threads for more accurate timeouts and interupt checks
1 parent 4fb5f6c commit 7b31e6e

File tree

13 files changed

+281
-209
lines changed

13 files changed

+281
-209
lines changed

astm-http-lib/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>org.itech</groupId>
66
<artifactId>astm-http-lib</artifactId>
7-
<version>2.3.1</version>
7+
<version>2.3.2</version>
88

99
<properties>
1010
<java.version>21</java.version>
@@ -38,4 +38,4 @@
3838

3939
</dependencies>
4040

41-
</project>
41+
</project>

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.itech.ahb.lib.astm.servlet;
22

3-
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
43
import org.itech.ahb.lib.common.ASTMMessage;
54

65
public interface ASTMHandler {

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMHandlerMarshaller.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.Map.Entry;
88
import java.util.Set;
99
import lombok.extern.slf4j.Slf4j;
10-
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
1110
import org.itech.ahb.lib.common.ASTMMessage;
1211
import org.itech.ahb.lib.common.HandleStatus;
1312

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/ASTMHandlerResponse.java renamed to astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMHandlerResponse.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
package org.itech.ahb.lib.astm;
1+
package org.itech.ahb.lib.astm.servlet;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Data;
55
import lombok.NonNull;
66
import lombok.RequiredArgsConstructor;
7-
import org.itech.ahb.lib.astm.servlet.ASTMHandler;
87
import org.itech.ahb.lib.common.HandleStatus;
98
import org.itech.ahb.lib.common.HandlerResponse;
109

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMMarshallerResponse.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import lombok.AllArgsConstructor;
55
import lombok.Data;
66
import lombok.RequiredArgsConstructor;
7-
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
87
import org.itech.ahb.lib.common.MarshallerResponse;
98

109
@Data

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMReceiveThread.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import java.io.IOException;
44
import java.net.Socket;
5+
import java.net.SocketTimeoutException;
56
import lombok.extern.slf4j.Slf4j;
6-
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
77
import org.itech.ahb.lib.common.ASTMMessage;
88
import org.itech.ahb.lib.common.HandleStatus;
99
import org.itech.ahb.lib.common.exception.ASTMCommunicationException;
@@ -51,6 +51,12 @@ public void run() {
5151
} catch (IllegalStateException | FrameParsingException | ASTMCommunicationException e) {
5252
log.error("an error occurred understanding what was received from the astm sender", e);
5353
return;
54+
} catch (InterruptedException e) {
55+
log.error("the thread was interrupted during receive protocol", e);
56+
return;
57+
} catch (SocketTimeoutException e) {
58+
log.error("there was a timeout in the receive protocol at the socket level, abandoning message", e);
59+
return;
5460
}
5561
ASTMMarshallerResponse response = astmHandlerMarshaller.handle(message);
5662
if (response.getResponses() == null || response.getResponses().size() == 0) {
@@ -77,4 +83,8 @@ public void run() {
7783
}
7884
}
7985
}
86+
87+
public boolean didReceiveEstablishmentSucceed() {
88+
return communicator.didReceiveEstablishmentSucceed();
89+
}
8090
}

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/ASTMServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void listen() {
3939
// Waiting for socket connection
4040
Socket s = serverSocket.accept();
4141
new ASTMReceiveThread(
42-
new GeneralASTMCommunicator(astmInterpreterFactory, s.getInputStream(), s.getOutputStream(), astmVersion),
42+
new GeneralASTMCommunicator(astmInterpreterFactory, s, astmVersion),
4343
s,
4444
astmMessageMarshaller
4545
).start();
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
11
package org.itech.ahb.lib.astm.servlet;
22

33
import java.io.IOException;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
46
import org.itech.ahb.lib.common.ASTMMessage;
57
import org.itech.ahb.lib.common.exception.ASTMCommunicationException;
68
import org.itech.ahb.lib.common.exception.FrameParsingException;
79

810
public interface Communicator {
911
String getID();
10-
boolean sendProtocol(ASTMMessage message) throws ASTMCommunicationException, IOException;
12+
SendResult sendProtocol(ASTMMessage message) throws ASTMCommunicationException, IOException, InterruptedException;
1113
ASTMMessage receiveProtocol(boolean lineWasContentious)
12-
throws FrameParsingException, ASTMCommunicationException, IOException;
14+
throws FrameParsingException, ASTMCommunicationException, IOException, InterruptedException;
15+
boolean didReceiveEstablishmentSucceed();
16+
17+
@Data
18+
@AllArgsConstructor
19+
public class SendResult {
20+
21+
private boolean lineContention;
22+
23+
private boolean rejected;
24+
}
1325
}

astm-http-lib/src/main/java/org/itech/ahb/lib/astm/servlet/DefaultForwardingASTMToHTTPHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.net.http.HttpResponse;
99
import java.util.Base64;
1010
import lombok.extern.slf4j.Slf4j;
11-
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
1211
import org.itech.ahb.lib.common.ASTMMessage;
1312
import org.itech.ahb.lib.common.DefaultASTMMessage;
1413
import org.itech.ahb.lib.common.HandleStatus;

0 commit comments

Comments
 (0)