Skip to content

Commit

Permalink
Added CARMA Cloud simulation id configuration item and handle excepti…
Browse files Browse the repository at this point in the history
…ons better
  • Loading branch information
kruegersp authored May 15, 2024
1 parent 0170b5d commit 60633c8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/cc/ws/SimFederate.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class SimFederate extends HttpServlet implements Runnable

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

Expand Down Expand Up @@ -50,6 +51,10 @@ public void init()
m_sAmbassadorAddress = sAddress;
m_oTs = new TimeSource(true);

String sId = oConf.getInitParameter("id");
if (sid != null)
m_sCarmaCloudId = sId;

String sUrl = oConf.getInitParameter("url");
if (sUrl != null)
m_sCarmaCloudUrl = sUrl;
Expand All @@ -58,6 +63,7 @@ public void init()
}
catch (Exception oEx)
{
LOGGER.error("SimFederate init invalid ambassador network address"); // simulation mode possibly not necessary
}
}

Expand Down Expand Up @@ -98,7 +104,7 @@ public void run()
{
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));
oOut.writeUTF(String.format("{\"id\":\"%s\", \"url\":\"%s\"}", m_sCarmaCloudId, m_sCarmaCloudUrl));
bRegistered = true;
}
catch (Exception oEx)
Expand All @@ -112,8 +118,13 @@ public void run()
{
Thread.sleep(m_lRetryInterval);
}
catch (Exception oEx)
catch (InterruptedException oEx)
{
bRegistered = true; // container thread interrupts on shutdown
}
catch (IllegalArgumentException oEx)
{
LOGGER.error(oEx.toString()); // invalid, possibly negative, delay specified
}
}
}
Expand Down

0 comments on commit 60633c8

Please sign in to comment.