Skip to content

Commit

Permalink
more logging and more accurate timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebSLane committed Oct 15, 2024
1 parent bd27d52 commit da2c22e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
2 changes: 1 addition & 1 deletion astm-http-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.itech</groupId>
<artifactId>astm-http-lib</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>

<properties>
<java.version>21</java.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package org.itech.ahb.lib.astm.servlet;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.HandleStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

import java.io.IOException;
import java.net.Socket;
import java.util.List;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.itech.ahb.lib.astm.ASTMHandlerResponse;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.HandleStatus;
Expand All @@ -18,6 +15,7 @@ public class ASTMReceiveThread extends Thread {
private final Socket socket;
private final Communicator communicator;
private ASTMHandlerMarshaller astmHandlerMarshaller;
private boolean lineWasContentious;

public ASTMReceiveThread(Communicator communicator, Socket socket, ASTMHandlerMarshaller astmHandlerMarshaller) {
this.communicator = communicator;
Expand All @@ -31,18 +29,29 @@ public ASTMReceiveThread(Communicator communicator, ASTMHandlerMarshaller astmHa
this.astmHandlerMarshaller = astmHandlerMarshaller;
}

public ASTMReceiveThread(
Communicator communicator,
Socket socket,
ASTMHandlerMarshaller astmHandlerMarshaller,
boolean lineWasContentious
) {
this.communicator = communicator;
this.socket = socket;
this.astmHandlerMarshaller = astmHandlerMarshaller;
this.lineWasContentious = lineWasContentious;
}

@Override
public void run() {
log.trace("thread started to receive ASTM message");
try {
ASTMMessage message;
try {
message = communicator.receiveProtocol();
message = communicator.receiveProtocol(lineWasContentious);
} catch (IllegalStateException | FrameParsingException | ASTMCommunicationException e) {
log.error("an error occurred understanding what was received from the astm sender", e);
return;
}
//TODO replace Pairs with more informative types
ASTMMarshallerResponse response = astmHandlerMarshaller.handle(message);
if (response.getResponses() == null || response.getResponses().size() == 0) {
log.error("message was unhandled");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
public interface Communicator {
String getID();
boolean sendProtocol(ASTMMessage message) throws ASTMCommunicationException, IOException;
ASTMMessage receiveProtocol() throws FrameParsingException, ASTMCommunicationException, IOException;
ASTMMessage receiveProtocol(boolean lineWasContentious)
throws FrameParsingException, ASTMCommunicationException, IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,26 @@ public String getID() {
}

@Override
public ASTMMessage receiveProtocol() throws FrameParsingException, ASTMCommunicationException, IOException {
public ASTMMessage receiveProtocol(boolean lineWasContentious)
throws FrameParsingException, ASTMCommunicationException, IOException {
log.trace("starting receive protocol for ASTM message");
if (astmVersion == ASTMVersion.LIS01_A) {
final Future<Boolean> establishedFuture = executor.submit(establishmentTaskReceive());
Boolean established = false;
try {
established = establishedFuture.get(ESTABLISHMENT_RECEIVE_TIMEOUT, TimeUnit.SECONDS);
established = establishedFuture.get(
lineWasContentious ? ESTABLISHMENT_RECEIVE_TIMEOUT : ESTABLISHMENT_SEND_TIMEOUT,
TimeUnit.SECONDS
);
} catch (TimeoutException e) {
log.warn(
"waited " +
ESTABLISHMENT_SEND_TIMEOUT +
" " +
TimeUnit.SECONDS +
" for the sender to send anything but nothing was received"
);
// attempt sending information?
establishedFuture.cancel(true);
executor.shutdown();
throw new ASTMCommunicationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public HandleStatus handle(ASTMMessage message, Set<HTTPHandlerInfo> handlerInfo
// the communicator must remain open to receive the line contention. The thread
// will close the socket
closeSocket = false;
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller);
ASTMReceiveThread receiveThread = new ASTMReceiveThread(communicator, socket, astmHandlerMarshaller, true);
receiveThread.start();

if (message.getMessageLength() == 0) {
Expand Down
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>
<groupId>org.itech</groupId>
<artifactId>astm-http-bridge</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
<name>astm-http-bridge</name>
<description>Translates astm to http and vice versa</description>
<properties>
Expand All @@ -30,7 +30,7 @@
<dependency>
<groupId>org.itech</groupId>
<artifactId>astm-http-lib</artifactId>
<version>2.2.0</version>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -57,4 +57,4 @@
</plugins>
</build>

</project>
</project>

0 comments on commit da2c22e

Please sign in to comment.