Skip to content

Commit da2c22e

Browse files
committed
more logging and more accurate timeouts
1 parent bd27d52 commit da2c22e

File tree

7 files changed

+35
-16
lines changed

7 files changed

+35
-16
lines changed

astm-http-lib/pom.xml

Lines changed: 1 addition & 1 deletion
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.2.0</version>
7+
<version>2.2.1</version>
88

99
<properties>
1010
<java.version>21</java.version>

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

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

33
import java.util.ArrayList;
4-
import java.util.Arrays;
54
import java.util.HashMap;
65
import java.util.List;
76
import java.util.Map;
87
import java.util.Map.Entry;
9-
import java.util.Optional;
108
import lombok.extern.slf4j.Slf4j;
11-
import org.apache.commons.lang3.tuple.Pair;
129
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
1310
import org.itech.ahb.lib.common.ASTMMessage;
1411
import org.itech.ahb.lib.common.HandleStatus;

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

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import java.io.IOException;
44
import java.net.Socket;
5-
import java.util.List;
6-
import java.util.Optional;
75
import lombok.extern.slf4j.Slf4j;
8-
import org.apache.commons.lang3.tuple.Pair;
96
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
107
import org.itech.ahb.lib.common.ASTMMessage;
118
import org.itech.ahb.lib.common.HandleStatus;
@@ -18,6 +15,7 @@ public class ASTMReceiveThread extends Thread {
1815
private final Socket socket;
1916
private final Communicator communicator;
2017
private ASTMHandlerMarshaller astmHandlerMarshaller;
18+
private boolean lineWasContentious;
2119

2220
public ASTMReceiveThread(Communicator communicator, Socket socket, ASTMHandlerMarshaller astmHandlerMarshaller) {
2321
this.communicator = communicator;
@@ -31,18 +29,29 @@ public ASTMReceiveThread(Communicator communicator, ASTMHandlerMarshaller astmHa
3129
this.astmHandlerMarshaller = astmHandlerMarshaller;
3230
}
3331

32+
public ASTMReceiveThread(
33+
Communicator communicator,
34+
Socket socket,
35+
ASTMHandlerMarshaller astmHandlerMarshaller,
36+
boolean lineWasContentious
37+
) {
38+
this.communicator = communicator;
39+
this.socket = socket;
40+
this.astmHandlerMarshaller = astmHandlerMarshaller;
41+
this.lineWasContentious = lineWasContentious;
42+
}
43+
3444
@Override
3545
public void run() {
3646
log.trace("thread started to receive ASTM message");
3747
try {
3848
ASTMMessage message;
3949
try {
40-
message = communicator.receiveProtocol();
50+
message = communicator.receiveProtocol(lineWasContentious);
4151
} catch (IllegalStateException | FrameParsingException | ASTMCommunicationException e) {
4252
log.error("an error occurred understanding what was received from the astm sender", e);
4353
return;
4454
}
45-
//TODO replace Pairs with more informative types
4655
ASTMMarshallerResponse response = astmHandlerMarshaller.handle(message);
4756
if (response.getResponses() == null || response.getResponses().size() == 0) {
4857
log.error("message was unhandled");

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
public interface Communicator {
99
String getID();
1010
boolean sendProtocol(ASTMMessage message) throws ASTMCommunicationException, IOException;
11-
ASTMMessage receiveProtocol() throws FrameParsingException, ASTMCommunicationException, IOException;
11+
ASTMMessage receiveProtocol(boolean lineWasContentious)
12+
throws FrameParsingException, ASTMCommunicationException, IOException;
1213
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,26 @@ public String getID() {
142142
}
143143

144144
@Override
145-
public ASTMMessage receiveProtocol() throws FrameParsingException, ASTMCommunicationException, IOException {
145+
public ASTMMessage receiveProtocol(boolean lineWasContentious)
146+
throws FrameParsingException, ASTMCommunicationException, IOException {
146147
log.trace("starting receive protocol for ASTM message");
147148
if (astmVersion == ASTMVersion.LIS01_A) {
148149
final Future<Boolean> establishedFuture = executor.submit(establishmentTaskReceive());
149150
Boolean established = false;
150151
try {
151-
established = establishedFuture.get(ESTABLISHMENT_RECEIVE_TIMEOUT, TimeUnit.SECONDS);
152+
established = establishedFuture.get(
153+
lineWasContentious ? ESTABLISHMENT_RECEIVE_TIMEOUT : ESTABLISHMENT_SEND_TIMEOUT,
154+
TimeUnit.SECONDS
155+
);
152156
} catch (TimeoutException e) {
157+
log.warn(
158+
"waited " +
159+
ESTABLISHMENT_SEND_TIMEOUT +
160+
" " +
161+
TimeUnit.SECONDS +
162+
" for the sender to send anything but nothing was received"
163+
);
164+
// attempt sending information?
153165
establishedFuture.cancel(true);
154166
executor.shutdown();
155167
throw new ASTMCommunicationException(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public HandleStatus handle(ASTMMessage message, Set<HTTPHandlerInfo> handlerInfo
8989
// the communicator must remain open to receive the line contention. The thread
9090
// will close the socket
9191
closeSocket = false;
92-
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller);
92+
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller, true);
9393
receiveThread.start();
9494

9595
if (message.getMessageLength() == 0) {

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
</parent>
1212
<groupId>org.itech</groupId>
1313
<artifactId>astm-http-bridge</artifactId>
14-
<version>2.2.0</version>
14+
<version>2.2.1</version>
1515
<name>astm-http-bridge</name>
1616
<description>Translates astm to http and vice versa</description>
1717
<properties>
@@ -30,7 +30,7 @@
3030
<dependency>
3131
<groupId>org.itech</groupId>
3232
<artifactId>astm-http-lib</artifactId>
33-
<version>2.2.0</version>
33+
<version>2.2.1</version>
3434
</dependency>
3535
<dependency>
3636
<groupId>org.springframework.boot</groupId>
@@ -57,4 +57,4 @@
5757
</plugins>
5858
</build>
5959

60-
</project>
60+
</project>

0 commit comments

Comments
 (0)