Skip to content

Commit

Permalink
reorg code to accommodate more growth
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebSLane committed Oct 17, 2024
1 parent 441bae9 commit 6d385df
Show file tree
Hide file tree
Showing 40 changed files with 146 additions and 157 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.communication;

import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Data;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.exception.ASTMCommunicationException;
import org.itech.ahb.lib.common.exception.FrameParsingException;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.exception.ASTMCommunicationException;
import org.itech.ahb.lib.astm.exception.FrameParsingException;

public interface Communicator {
String getID();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.communication;

import java.io.BufferedReader;
import java.io.IOException;
Expand All @@ -22,16 +22,17 @@
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.astm.concept.ASTMFrame;
import org.itech.ahb.lib.astm.concept.ASTMFrame.FrameType;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMRecord;
import org.itech.ahb.lib.astm.concept.DefaultASTMFrame;
import org.itech.ahb.lib.astm.exception.ASTMCommunicationException;
import org.itech.ahb.lib.astm.exception.FrameParsingException;
import org.itech.ahb.lib.astm.interpretation.ASTMInterpreterFactory;
import org.itech.ahb.lib.astm.servlet.ASTMServlet.ASTMVersion;
import org.itech.ahb.lib.common.ASTMFrame;
import org.itech.ahb.lib.common.ASTMFrame.FrameType;
import org.itech.ahb.lib.common.ASTMInterpreterFactory;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.ASTMRecord;
import org.itech.ahb.lib.common.exception.ASTMCommunicationException;
import org.itech.ahb.lib.common.exception.FrameParsingException;
import org.itech.ahb.lib.common.thread.ThreadUtil;
import org.itech.ahb.lib.util.LogUtil;
import org.itech.ahb.lib.util.ThreadUtil;

//If this class gets too complicated, separate out the LISA-01 and E1382-95 protocols
@Slf4j
Expand Down Expand Up @@ -423,7 +424,7 @@ private Set<FrameError> readNextCompliantFrame(List<ASTMFrame> frames, int expec
);

if (frameErrors.isEmpty()) {
ASTMFrame frame = new ASTMFrame();
ASTMFrame frame = new DefaultASTMFrame();
frame.setFrameNumber(Character.getNumericValue(frameNumberChar));
frame.setType(finalFrame ? FrameType.END : FrameType.INTERMEDIATE);
frame.setText(text);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.itech.ahb.lib.astm.concept;

public interface ASTMFrame {
public enum FrameType {
INTERMEDIATE,
END
}

FrameType getType();
void setType(FrameType object);
String getText();
void setText(String text);
void setFrameNumber(int numericValue);
int getFrameNumber();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.concept;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.concept;

public interface ASTMRecord {
int getRecordLength();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.itech.ahb.lib.astm.concept;

import lombok.Data;

@Data
public class DefaultASTMFrame implements ASTMFrame {

private FrameType type;
private int frameNumber = 0;
private String text;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.concept;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.concept;

import lombok.Data;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common.exception;
package org.itech.ahb.lib.astm.exception;

public class ASTMCommunicationException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common.exception;
package org.itech.ahb.lib.astm.exception;

public class FrameParsingException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

//TODO add the capability to add info about forwarding (for example listen on sevaral sockets, and each socket could have a defined forwarding info)
public class ASTMForwardingHandlerInfo {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMMessage;

public interface ASTMHandler {
String getName();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -7,8 +7,8 @@
import java.util.Map.Entry;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.HandleStatus;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.common.handling.HandleStatus;

@Slf4j
public class ASTMHandlerMarshaller {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.itech.ahb.lib.common.HandleStatus;
import org.itech.ahb.lib.common.HandlerResponse;
import org.itech.ahb.lib.common.handling.HandleStatus;
import org.itech.ahb.lib.common.handling.HandlerResponse;

@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import org.itech.ahb.lib.common.MarshallerResponse;
import org.itech.ahb.lib.common.handling.MarshallerResponse;

@Data
@AllArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import java.io.IOException;
import java.net.Socket;
import java.net.SocketTimeoutException;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.HandleStatus;
import org.itech.ahb.lib.common.exception.ASTMCommunicationException;
import org.itech.ahb.lib.common.exception.FrameParsingException;
import org.itech.ahb.lib.astm.communication.Communicator;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.exception.ASTMCommunicationException;
import org.itech.ahb.lib.astm.exception.FrameParsingException;
import org.itech.ahb.lib.common.handling.HandleStatus;

@Slf4j
public class ASTMReceiveThread extends Thread {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.astm.servlet;
package org.itech.ahb.lib.astm.handling;

import java.io.IOException;
import java.net.URI;
Expand All @@ -8,9 +8,9 @@
import java.net.http.HttpResponse;
import java.util.Base64;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.common.ASTMMessage;
import org.itech.ahb.lib.common.DefaultASTMMessage;
import org.itech.ahb.lib.common.HandleStatus;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.DefaultASTMMessage;
import org.itech.ahb.lib.common.handling.HandleStatus;
import org.itech.ahb.lib.util.LogUtil;

@Slf4j
Expand Down Expand Up @@ -59,7 +59,7 @@ public ASTMHandlerResponse handle(ASTMMessage message) {
return new ASTMHandlerResponse(response.body(), HandleStatus.FORWARD_FAIL_BAD_RESPONSE, false, this);
} catch (IOException | InterruptedException e) {
log.error("error occurred communicating with http server at " + forwardingUri.toString(), e);
return new ASTMHandlerResponse("", HandleStatus.GENERIC_FAIL, false, this);
return new ASTMHandlerResponse("", HandleStatus.FORWARD_FAIL_ERROR, false, this);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.interpretation;

import java.util.List;
import org.itech.ahb.lib.common.exception.FrameParsingException;
import org.itech.ahb.lib.astm.concept.ASTMFrame;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMRecord;
import org.itech.ahb.lib.astm.exception.FrameParsingException;

public interface ASTMInterpreter {
ASTMMessage interpretFramesToASTMMessage(List<ASTMFrame> frames) throws FrameParsingException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.interpretation;

import java.util.List;
import org.itech.ahb.lib.astm.concept.ASTMFrame;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMRecord;

public interface ASTMInterpreterFactory {
ASTMInterpreter createInterpreterForFrames(List<ASTMFrame> frames);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.interpretation;

import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.astm.servlet.GeneralASTMCommunicator;
import org.itech.ahb.lib.common.ASTMFrame.FrameType;
import org.itech.ahb.lib.common.exception.FrameParsingException;
import org.itech.ahb.lib.astm.communication.GeneralASTMCommunicator;
import org.itech.ahb.lib.astm.concept.ASTMFrame;
import org.itech.ahb.lib.astm.concept.ASTMFrame.FrameType;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMRecord;
import org.itech.ahb.lib.astm.concept.DefaultASTMFrame;
import org.itech.ahb.lib.astm.concept.DefaultASTMMessage;
import org.itech.ahb.lib.astm.concept.DefaultASTMRecord;
import org.itech.ahb.lib.astm.exception.FrameParsingException;

@Slf4j
public class DefaultASTMInterpreter implements ASTMInterpreter {
Expand Down Expand Up @@ -54,7 +60,7 @@ public List<ASTMFrame> interpretASTMRecordsToFrames(ASTMRecord record) {
String[] frameTexts = record.getRecord().split("(?<=\\G.{" + GeneralASTMCommunicator.MAX_TEXT_SIZE + "})");
log.trace("astm record: " + record);
for (int i = 0; i < frameTexts.length; i++) {
ASTMFrame curFrame = new ASTMFrame();
ASTMFrame curFrame = new DefaultASTMFrame();
curFrame.setText(frameTexts[i]);
curFrame.setFrameNumber((i + 1) % 8);
curFrame.setType(i != (frameTexts.length - 1) ? FrameType.INTERMEDIATE : FrameType.END);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.astm.interpretation;

import java.util.List;
import org.itech.ahb.lib.astm.concept.ASTMFrame;
import org.itech.ahb.lib.astm.concept.ASTMMessage;
import org.itech.ahb.lib.astm.concept.ASTMRecord;

public class DefaultASTMInterpreterFactory implements ASTMInterpreterFactory {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import java.net.ServerSocket;
import java.net.Socket;
import lombok.extern.slf4j.Slf4j;
import org.itech.ahb.lib.common.ASTMInterpreterFactory;
import org.itech.ahb.lib.astm.communication.GeneralASTMCommunicator;
import org.itech.ahb.lib.astm.handling.ASTMHandlerMarshaller;
import org.itech.ahb.lib.astm.handling.ASTMReceiveThread;
import org.itech.ahb.lib.astm.interpretation.ASTMInterpreterFactory;

@Slf4j
public class ASTMServlet {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.common.handling;

public enum HandleStatus {
SUCCESS,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.itech.ahb.lib.common;
package org.itech.ahb.lib.common.handling;

public interface HandlerResponse {
HandleStatus getStatus();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.itech.ahb.lib.common.handling;

public interface MarshallerResponse {}
Loading

0 comments on commit 6d385df

Please sign in to comment.