Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/time source #57

Merged
merged 67 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
22f8275
Created CARMA Cloud time source and simulation federate
kruegersp Feb 15, 2024
160e8d5
Added SimFederal servlet configuration
kruegersp Feb 15, 2024
aa24677
Updated SimFederate to test ambassador address.
kruegersp Feb 15, 2024
870f189
Update SimFederate import InetAdress.
kruegersp Feb 15, 2024
711109a
Fixed SimFederate registration JSON message.
kruegersp Feb 15, 2024
4a01acf
Update Dockerfile with simulation configuration.
kruegersp Feb 16, 2024
b1eccdd
Update rsu.js
kruegersp Feb 29, 2024
ce6e7ee
Update map.js
kruegersp Feb 29, 2024
02370bc
Update Dockerfile
kruegersp Feb 29, 2024
fb35e0d
Update ihp.js
kruegersp Feb 29, 2024
d90013a
SimFederate separated registration retry from socket close
kruegersp Mar 1, 2024
3d1b9dc
Update web.xml
kruegersp Mar 1, 2024
6eb30bb
Update Dockerfile
kruegersp Mar 11, 2024
7417127
Update Dockerfile
kruegersp Mar 11, 2024
d0d763d
Update SimFederate.java
kruegersp Mar 26, 2024
9d5cbff
Update RoadMark.java
kruegersp Mar 27, 2024
9fb6b5a
Update satellite-streets-v11.json
kruegersp Mar 28, 2024
6f4a1f7
Update sourcelayers.json
kruegersp Mar 28, 2024
f62d820
Update validatexodr_sourcelayers.json
kruegersp Mar 28, 2024
d500a6d
Removed commented-out RSM Servlet.
kruegersp Apr 2, 2024
c4b8f06
Default traffic control update and start time to 0L.
kruegersp Apr 2, 2024
e92f7f5
Added port and list attribute parsing to old TCR format.
kruegersp Apr 2, 2024
f9f5697
Updated TcmReqServlet to preserve request host address.
kruegersp Apr 3, 2024
d2579c8
Added error log to TCM response connection.
kruegersp Apr 8, 2024
7b1f836
Add docker and dockerhub workflows
paulbourelly999 May 7, 2024
ced9ff0
Build and push image for testing
paulbourelly999 May 7, 2024
2937c05
Update web.xml init TimeSource singleton first and added CARMA Cloud …
kruegersp May 15, 2024
0170b5d
Delete lib/libcs2cswrapper.so
kruegersp May 15, 2024
60633c8
Added CARMA Cloud simulation id configuration item and handle excepti…
kruegersp May 15, 2024
de2170a
Use TimeSource to handle simulation and real world time, remove extra…
kruegersp May 15, 2024
79c3315
Update TcmReqServlet to use TimeSource
kruegersp May 15, 2024
de7fd12
Update web.xml to add explicit simulation mode logical flag
kruegersp May 15, 2024
6616549
Update SimFederate to check for explicit simulation mode configuration
kruegersp May 15, 2024
8d2d5e3
Update SimFederate to use JSON libary for building ambassador registr…
kruegersp May 15, 2024
a2c1965
Update SimFederate fixed sid typo
kruegersp May 15, 2024
3e09834
Update dockerfile and move instructions to scripts
paulbourelly999 May 16, 2024
4778fe4
Install GIT for checkout
paulbourelly999 May 16, 2024
8a65604
Fix build/install scripts issues
paulbourelly999 May 16, 2024
5103d16
Figure out CI VM path
paulbourelly999 May 16, 2024
c788b25
Fix path error
paulbourelly999 May 16, 2024
74148ef
Remove rm calls in build script
paulbourelly999 May 16, 2024
4f464dc
Update to build scripts
paulbourelly999 May 16, 2024
1f8235d
Print commands in scripts and their arguments as exexuted
paulbourelly999 May 16, 2024
1acae3c
Update
paulbourelly999 May 16, 2024
713fe56
Updates to fix carma-cloud path to absolute /home/carma-cloud inside …
paulbourelly999 May 16, 2024
340fee9
Update path for workflow
paulbourelly999 May 16, 2024
8e28d16
Fix issues
paulbourelly999 May 16, 2024
32b442a
Updates
paulbourelly999 May 16, 2024
d9a47fa
Updates
paulbourelly999 May 16, 2024
b91b142
Updates
paulbourelly999 May 16, 2024
b48a1c4
Update
paulbourelly999 May 16, 2024
2759f50
Updates
paulbourelly999 May 17, 2024
6de48c0
Removing circle ci workflow that was replaced with github action
paulbourelly999 May 17, 2024
792f9f5
Update with docker-compose file, testing script and volume directory
paulbourelly999 May 17, 2024
311cf83
add carma-cloud-config work folder
EricChen-Lei May 20, 2024
81cf059
Update install_dependencies.sh
kruegersp May 21, 2024
c350996
Update build.sh
kruegersp May 21, 2024
9c09200
Update deployment_test.yml
kruegersp May 21, 2024
6a4dd17
Update map.js
kruegersp May 21, 2024
f5024cc
Update ihp.js
kruegersp May 21, 2024
953d2f5
Update rsu.js
kruegersp May 21, 2024
fb53afe
Revert "add carma-cloud-config work folder"
EricChen-Lei May 22, 2024
599eb98
Update build.sh to modify default host path
kruegersp May 22, 2024
c56b8e1
Delete carma-cloud-config/server.xml
kruegersp May 22, 2024
e03b854
Create web.xml for simulation
kruegersp May 22, 2024
2750614
Update web.xml to adjust SimFederate load on startup order
kruegersp May 22, 2024
0b1edd1
Remove trigger for building feature/time-source docker image
paulbourelly999 May 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: Docker build
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
docker:
uses: usdot-fhwa-stol/actions/.github/workflows/docker.yml@main
with:
runner: ubuntu-latest
17 changes: 17 additions & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Docker Hub build
on:
push:
branches:
- develop
- master
- "release/*"
tags:
- "carma-system-*"
jobs:
dockerhub:
uses: usdot-fhwa-stol/actions/.github/workflows/dockerhub.yml@main
secrets:
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
with:
runner: ubuntu-latest
74 changes: 42 additions & 32 deletions Dockerfile
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,51 +1,61 @@
FROM ubuntu:22.04
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
# update package manager and install prerequisites
RUN apt-get update -y && \
apt-get install -y build-essential cmake git wget pkg-config sqlite3 libcurl4-openssl-dev libsqlite3-dev libtiff5-dev
apt-get install -y build-essential cmake git wget pkg-config sqlite3 libcurl4-openssl-dev libsqlite3-dev libtiff5-dev
# download geodesy projection library source
WORKDIR /tmp
RUN wget -q https://download.osgeo.org/proj/proj-9.3.0.tar.gz && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not installing proj from apt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CARMA Cloud is 6 years old and may not have had the option of a DockerHub image or apt at that time. We'll need to verify that the required headers are included to compile the JNI wrapper for proj.

tar -xzf proj-9.3.0.tar.gz && \
rm proj-9.3.0.tar.gz && \
mv proj-9.3.0 proj && \
mkdir -p proj/build
tar -xzf proj-9.3.0.tar.gz && \
rm proj-9.3.0.tar.gz && \
mv proj-9.3.0 proj && \
mkdir -p proj/build
# download openjdk
RUN wget -q https://download.java.net/java/GA/jdk21.0.1/415e3f918a1f4062a0074a2794853d0d/12/GPL/openjdk-21.0.1_linux-x64_bin.tar.gz && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we not installing JDK from apt?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It appears that the apt version does not include the JNI header files needed to compile cs2cs library. Continuing to investigate.

tar -xzf openjdk-21.0.1_linux-x64_bin.tar.gz && \
rm openjdk-21.0.1_linux-x64_bin.tar.gz && \
mv jdk-21.0.1 /opt/jdk
tar -xzf openjdk-21.0.1_linux-x64_bin.tar.gz && \
rm openjdk-21.0.1_linux-x64_bin.tar.gz && \
mv jdk-21.0.1 /opt/jdk
# download apache tomcat
RUN wget -q https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.83/bin/apache-tomcat-9.0.83.tar.gz && \
tar -xzf apache-tomcat-9.0.83.tar.gz && \
rm apache-tomcat-9.0.83.tar.gz && \
mv apache-tomcat-9.0.83 tomcat && \
sed -i 's/appBase="webapps"/appBase="webapps\/carmacloud"/g' tomcat/conf/server.xml && \
rm -r tomcat/webapps/*
RUN wget -q https://archive.apache.org/dist/tomcat/tomcat-9/v9.0.83/bin/apache-tomcat-9.0.83.tar.gz && \
tar -xzf apache-tomcat-9.0.83.tar.gz && \
rm apache-tomcat-9.0.83.tar.gz && \
mv apache-tomcat-9.0.83 tomcat && \
sed -i 's/appBase="webapps"/appBase="webapps\/carmacloud"/g' tomcat/conf/server.xml && \
rm -r tomcat/webapps/*
# download carma-cloud source
RUN git clone https://github.com/usdot-fhwa-stol/carma-cloud.git cc && \
rm cc/lib/libcs2cswrapper.so && \
mkdir -p tomcat/webapps/carmacloud/ROOT && \
mv cc/web/* tomcat/webapps/carmacloud/ROOT
rm cc/lib/libcs2cswrapper.so
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
# compile geodesy projection library
WORKDIR /tmp/proj/build
RUN cmake .. && \
cmake --build . && \
cmake --build . --target install
cmake --build . && \
cmake --build . --target install && \
ldconfig
# compile jni projection library
WORKDIR /tmp/cc/src/cc/geosrv
RUN gcc -c -std=c11 -fPIC -Wall -I /opt/jdk/include/ -I /opt/jdk/include/linux/ -I /tmp/proj/src/ cs2cswrapper.c && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using gcc directly instead of a build system like CMake?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the original author thought CMake was overkill for 3 includes and 1 source file.

gcc -shared -lproj cs2cswrapper.o -o libcs2cswrapper.so && \
mv *.so /usr/lib
gcc -shared cs2cswrapper.o -lproj -o /usr/local/lib/libcs2cswrapper.so
# compile carma-cloud java source and cleanup
WORKDIR /tmp
RUN find ./cc/src -name "*.java" > sources.txt && \
mkdir -p tomcat/webapps/carmacloud/ROOT/WEB-INF/classes && \
/opt/jdk/bin/javac -cp tomcat/lib/servlet-api.jar:cc/lib/commons-compress-1.18.jar:cc/lib/javax.json.jar:cc/lib/json-20210307.jar:cc/lib/keccakj.jar:cc/lib/log4j-api-2.16.0.jar:cc/lib/vector_tile.jar -d tomcat/webapps/carmacloud$
rm sources.txt && \
/opt/jdk/bin/java -cp tomcat/webapps/carmacloud/ROOT/WEB-INF/classes/:tomcat/lib/servlet-api.jar cc.ws.UserMgr ccadmin admin_testpw > tomcat/webapps/carmacloud/user.csv && \
echo "JAVA_HOME=/opt/jdk" > tomcat/bin/setenv.sh && \
mv tomcat /opt && \
rm -r proj && \
rm -r cc
# start carma-cloud
CMD /opt/tomcat/bin/catalina.sh start
RUN mkdir -p tomcat/webapps/carmacloud/ROOT && \
mv cc/web/* tomcat/webapps/carmacloud/ROOT && \
mkdir -p tomcat/webapps/carmacloud/ROOT/WEB-INF/classes && \
find ./cc/src -name "*.java" > sources.txt && \
/opt/jdk/bin/javac -cp tomcat/lib/servlet-api.jar:cc/lib/commons-compress-1.18.jar:cc/lib/javax.json.jar:cc/lib/json-20210307.jar:cc/lib/keccakj.jar:cc/lib/log4j-api-2.16.0.jar:cc/lib/vector_tile.jar -d tomcat/webapps/carmacloud/ROOT/WEB-INF/classes @sources.txt && \
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we using javac directly instead of a build system like maven?

rm sources.txt && \
gunzip cc/osmbin/*.gz && \
mv cc/lib tomcat/webapps/carmacloud/ROOT/WEB-INF && \
mv cc/osmbin/rop.csv tomcat/webapps/carmacloud && \
mv cc/osmbin/storm.csv tomcat/webapps/carmacloud && \
mv cc/osmbin/units.csv tomcat/webapps/carmacloud && \
mv cc/osmbin tomcat/webapps/carmacloud && \
mv tomcat/webapps/carmacloud/ROOT/WEB-INF/log4j2.properties tomcat/webapps/carmacloud/ROOT/WEB-INF/classes && \
touch tomcat/webapps/carmacloud/event.csv && \
mkdir -p tomcat/work/carmacloud/xodr && \
mkdir -p tomcat/work/carmacloud/validate/xodr && \
/opt/jdk/bin/java -cp tomcat/webapps/carmacloud/ROOT/WEB-INF/classes/:tomcat/lib/servlet-api.jar cc.ws.UserMgr ccadmin admin_testpw > tomcat/webapps/carmacloud/user.csv && \
echo 'JAVA_HOME=/opt/jdk' > tomcat/bin/setenv.sh && \
sed -i 's/<param-value>ambassador-address<\/param-value>/<param-value>172.2.0.2<\/param-value>/g' tomcat/webapps/carmacloud/ROOT/WEB-INF/web.xml && \
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not be doing substitutions on configuration files during our build. Instead you can use environment variables and or build arguments or simply setup a volume for the configuration files.

sed -i 's/<param-value>simulation-url<\/param-value>/<param-value>http:\/\/172.2.0.47:8080\/carmacloud\/simulation<\/param-value>/g' tomcat/webapps/carmacloud/ROOT/WEB-INF/web.xml && \
mv tomcat /opt && \
rm -r proj && \
rm -r cc
13 changes: 9 additions & 4 deletions src/cc/ctrl/TcmReqParser2.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ public void startElement(String sUri, String sLocalName,
{
switch (sQname)
{
case "TrafficControlRequest":
{
String sVal;
m_nPort = (sVal = iAtt.getValue("port")) != null ? Integer.parseInt(sVal) : m_nPort;
m_bList = (sVal = iAtt.getValue("list")) != null ? Boolean.parseBoolean(sVal) : m_bList;
break;
}

case "bounds":
{
m_oBounds = new TcBounds();
Expand All @@ -40,11 +48,8 @@ public void startElement(String sUri, String sLocalName,
m_oReq.m_oBounds = new ArrayList();
break;
}


default:


}
}

Expand Down Expand Up @@ -113,8 +118,8 @@ public void endElement(String sUri, String sLocalName, String sQname)
default:
break;
}

}


public TcmReq parseRequest(InputStream oIn)
throws Exception
Expand Down
3 changes: 3 additions & 0 deletions src/cc/geosrv/xodr/rdmk/RoadMark.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public static RoadMark getRoadMark(double dDist, ArrayList<RoadMark> oRoadMarks)

public static int getColor(String sColor)
{
if (sColor == null)
return 0;

int nIndex = COLORS.length;
while (nIndex-- > 0)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cc/ws/CtrlTiles.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private void addControl(HttpServletRequest oReq, HttpServletResponse oRes)
dCenter = Arrays.add(dCenter, dW);
}
CtrlLineArcs oCla = new CtrlLineArcs(-1, -1, -1, -1, XodrUtil.getLaneType("driving"), dCenter, 0.1);
TrafCtrl oCtrl = new TrafCtrl(TrafCtrlEnums.CTRLS[nType][0], nControlValue, nVtypes, lNow, lNow, oCla.m_dLineArcs, sLabel, bReg, ProcCtrl.CC);
TrafCtrl oCtrl = new TrafCtrl(TrafCtrlEnums.CTRLS[nType][0], nControlValue, nVtypes, 0L, 0L, oCla.m_dLineArcs, sLabel, bReg, ProcCtrl.CC);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a hard coded traffic control at 0 seconds? Does this not break real world functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be replaced with : clock:now()->either simulation time or real time based on configuration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace all calls to System.time() with TimeSource so that lNow can still be used.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uses singleton TimeSource now.

oCtrl.write(ProcCtrl.g_sTrafCtrlDir, ProcCtrl.g_dExplodeStep, ProcCtrl.g_nDefaultZoom, ProcCtrl.CC);
ArrayList<TrafCtrl> oCtrls = new ArrayList();
oCtrls.add(oCtrl);
Expand Down Expand Up @@ -624,7 +624,7 @@ private void saveEdit(HttpServletRequest oReq, HttpServletResponse oRes)
}
else
{
TrafCtrl oNewCtrl = new TrafCtrl(sType, nControlValue, nVtypes, lNow, lNow, oOriginalCtrl, sLabel, bReg, ProcCtrl.CC);
TrafCtrl oNewCtrl = new TrafCtrl(sType, nControlValue, nVtypes, 0L, 0L, oOriginalCtrl, sLabel, bReg, ProcCtrl.CC);
oCtrlToWrite = oNewCtrl;
oNewCtrl.write(ProcCtrl.g_sTrafCtrlDir, ProcCtrl.g_dExplodeStep, ProcCtrl.g_nDefaultZoom, ProcCtrl.CC);
ArrayList<TrafCtrl> oCtrls = new ArrayList(1);
Expand Down
121 changes: 121 additions & 0 deletions src/cc/ws/SimFederate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
package cc.ws;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject;
import org.json.JSONTokener;


public class SimFederate extends HttpServlet implements Runnable
{
protected static final Logger LOGGER = LogManager.getRootLogger();

private long m_lRetryInterval = 60000L; // registration retry 60 seconds
private String m_sAmbassadorAddress;
private String m_sCarmaCloudUrl = "";
private TimeSource m_oTs;


public SimFederate()
{
}


@Override
public void init()
{
ServletConfig oConf = getServletConfig();

String sRetry = oConf.getInitParameter("retry");
if (sRetry != null)
m_lRetryInterval = Integer.parseInt(sRetry) * 1000L;

String sAddress = oConf.getInitParameter("ambassador");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not use ambassor config to indicate simulation mode. Please have a separate configuration parameter to be more explicit. Service should fail of sim mode is true and ambassador is null.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added simulation configuration parameter and updated SimFederate to use it.

if (sAddress != null)
{
try
{
InetAddress.getByName(sAddress); // validate network address
m_sAmbassadorAddress = sAddress;
m_oTs = new TimeSource(true);

String sUrl = oConf.getInitParameter("url");
if (sUrl != null)
m_sCarmaCloudUrl = sUrl;

new Thread(this).start(); // begin registration cycle
}
catch (Exception oEx)
{
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
}
}

if (m_oTs == null) // simulation time source not created
m_oTs = new TimeSource(false);
}


@Override
public void doPost(HttpServletRequest oReq, HttpServletResponse oRes)
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
throws ServletException, IOException
{
JSONObject oJson;
try (BufferedInputStream oIn = new BufferedInputStream(oReq.getInputStream()))
{
oJson = new JSONObject(new JSONTokener(oIn));
}

long lSeq = -1L;
long lStep = -1L;
if (oJson.has("seq") && oJson.has("timestep"))
{
lSeq = oJson.getLong("seq");
lStep = oJson.getLong("timestep");
m_oTs.m_lSimTime = lStep;
}
LOGGER.debug(String.format("seq: %d timestep: %d timesource: %d", lSeq, lStep, m_oTs.currentTimeMillis()));
}


@Override
public void run()
{
boolean bRegistered = false;
while (!bRegistered)
{
try (Socket oSock = new Socket())
{
oSock.connect(new InetSocketAddress(m_sAmbassadorAddress, 1617), 10000);
DataOutputStream oOut = new DataOutputStream(oSock.getOutputStream());
oOut.writeUTF(String.format("{\"id\":\"carma-cloud\", \"url\":\"%s\"}", m_sCarmaCloudUrl));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this id configurable and can we use a JSON library to serialize JSON strings.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CARMA Cloud id added to configuration and registration message uses JSON library.

bRegistered = true;
}
catch (Exception oEx)
{
LOGGER.error(oEx);
}

if (!bRegistered)
{
try
{
Thread.sleep(m_lRetryInterval);
}
catch (Exception oEx)
{
}
paulbourelly999 marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
14 changes: 10 additions & 4 deletions src/cc/ws/TcmReqServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public void doPost(HttpServletRequest oReq, HttpServletResponse oRes)
throws ServletException, IOException
{
StringBuilder sReq = new StringBuilder(1024);
sReq.append(oReq.getRemoteAddr());
try (BufferedInputStream oIn = new BufferedInputStream(oReq.getInputStream()))
{
int nByte;
Expand All @@ -109,8 +110,12 @@ public void run()
{
long lNow = System.currentTimeMillis();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be replaces with a call to time wrapper that either returns sim time or real time base on configuration

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use TimeSource.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe there is a commit I am missing. Please make sure you pull and push you local changes.

String sReq = Thread.currentThread().getName();
int nPos = sReq.indexOf('<');
String sHost = sReq.substring(0, nPos);
sReq = sReq.substring(nPos);

TcmReqParser oReqParser;
if (sReq.indexOf("<tcrV01>") >= 0)
if (sReq.contains("<tcrV01>"))
oReqParser = new TcmReqParser();
else
oReqParser = new TcmReqParser2();
Expand Down Expand Up @@ -233,7 +238,7 @@ public void run()

if (!oReqParser.m_bList)
{
HttpURLConnection oHttpClient = (HttpURLConnection)new URL(String.format("http://tcmreplyhost:%d/tcmreply", oReqParser.m_nPort)).openConnection();
HttpURLConnection oHttpClient = (HttpURLConnection)new URL(String.format("http://%s:%d/tcmreply", sHost, oReqParser.m_nPort)).openConnection();
oHttpClient.setFixedLengthStreamingMode(sBuf.length());
oHttpClient.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
oHttpClient.setDoOutput(true);
Expand Down Expand Up @@ -262,7 +267,8 @@ public void run()

if (oReqParser.m_bList)
{
HttpURLConnection oHttpClient = (HttpURLConnection)new URL(String.format("http://tcmreplyhost:%d/tcmreply", oReqParser.m_nPort)).openConnection();
String sUrl = String.format("http://%s:%d/tcmreply", sHost, oReqParser.m_nPort);
HttpURLConnection oHttpClient = (HttpURLConnection)new URL(sUrl).openConnection();
oHttpClient.setRequestProperty("Content-Encoding", "gzip");
oHttpClient.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
oHttpClient.setDoOutput(true);
Expand All @@ -287,7 +293,7 @@ public void run()
}
catch (Exception oEx)
{
oEx.printStackTrace();
LOGGER.error(sUrl, oEx);
}
}
sBuf.insert(0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><TrafficControlMessageList>");
Expand Down
37 changes: 37 additions & 0 deletions src/cc/ws/TimeSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cc.ws;


public class TimeSource
{
private static TimeSource g_oInstance;

private boolean m_bSim; // determines if instance is in simulation mode
long m_lSimTime; // package private time set by simulation federate


protected TimeSource()
{
}


TimeSource(boolean bSim)
{
m_bSim = bSim;
g_oInstance = this;
}


public static TimeSource getInstance()
{
return g_oInstance;
}


public long currentTimeMillis()
{
if (m_bSim)
return m_lSimTime;

return System.currentTimeMillis();
}
}
Loading