Skip to content
Snippets Groups Projects
Commit 2ec0a252 authored by Terry D. Norbraten's avatar Terry D. Norbraten
Browse files

Merge origin/master

parents 09d6ca7e 3e04f6df
No related branches found
No related tags found
No related merge requests found
...@@ -71,6 +71,16 @@ ...@@ -71,6 +71,16 @@
--> -->
<!-- TODO fix -->
<target name="run.default">
<echo message="run.classpath=${run.classpath}"/>
<java classname="edu.nps.moves.cot.dis.CotMsgReceiver"
classpath=".;${run.classpath}">
<arg line="--performanceTestSendCoT udp localhost 9999 1 1"/>
<jvmarg value="-Djava.net.preferIPv4Stack=true"/>
</java>
</target>
<target name="validate-cot-msg" description="Validate the CoT msg template"> <target name="validate-cot-msg" description="Validate the CoT msg template">
<schemavalidate file="CoT Test TX/src/main/resources/cotMsgTemplate.xml" nonamespaceFile="lib/xsd/CoT Base-Event Schema (PUBLIC RELEASE).xsd"> <schemavalidate file="CoT Test TX/src/main/resources/cotMsgTemplate.xml" nonamespaceFile="lib/xsd/CoT Base-Event Schema (PUBLIC RELEASE).xsd">
<xmlcatalog> <xmlcatalog>
......
/* /*
Copyright (c) 1995-2024 held by the author(s). All rights reserved. Copyright (c) 1995-2024 held by the author(s). All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions modification, are permitted provided that the following conditions
are met: are met:
* Redistributions of source code must retain the above copyright * Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer. notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright * Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the in the documentation and/or other materials provided with the
distribution. distribution.
* Neither the names of the Naval Postgraduate School (NPS) * Neither the names of the Naval Postgraduate School (NPS)
Modeling, Virtual Environments and Simulation (MOVES) Institute Modeling, Virtual Environments and Simulation (MOVES) Institute
(http://www.nps.edu and https://my.nps.edu/web/moves) (http://www.nps.edu and https://my.nps.edu/web/moves)
nor the names of its contributors may be used to endorse or nor the names of its contributors may be used to endorse or
promote products derived from this software without specific promote products derived from this software without specific
prior written permission. prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE. POSSIBILITY OF SUCH DAMAGE.
*/ */
package edu.nps.moves.cot.main; package edu.nps.moves.cot.main;
import edu.nps.moves.cot.dis.CoTMsgParserDisRunner; import edu.nps.moves.cot.dis.CoTMsgParserDisRunner;
import java.io.IOException; import java.io.IOException;
import java.io.PipedInputStream; import java.io.PipedInputStream;
import java.io.PipedOutputStream; import java.io.PipedOutputStream;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import mil.army.usareur.g3.mcsd.CoTUtils.*; import mil.army.usareur.g3.mcsd.CoTUtils.*;
import mil.army.usareur.g3.mcsd.CoTExample.CustomCoTparser; import mil.army.usareur.g3.mcsd.CoTExample.CustomCoTparser;
/** CoT message receiver (UPD, TCP) main entry class. /** CoT message receiver (UPD, TCP) main entry class.
* Based off of mil.army.usareur.g3.mcsd.CoTExample.CoTreceiver * Based off of mil.army.usareur.g3.mcsd.CoTExample.CoTreceiver
* *
* System.in simulation based on: https://stackoverflow.com/questions/1647907/junit-how-to-simulate-system-in-testing * System.in simulation based on: https://stackoverflow.com/questions/1647907/junit-how-to-simulate-system-in-testing
* *
* @author <a href="mailto:tdnorbra@nps.edu?subject=edu.nps.moves.main.CoTMsgReceiver">Terry Norbraten, NPS MOVES</a> * @author <a href="mailto:tdnorbra@nps.edu?subject=edu.nps.moves.main.CoTMsgReceiver">Terry Norbraten, NPS MOVES</a>
*/ */
public class CoTMsgReceiver { public class CoTMsgReceiver {
/** /**
* Utility method that sleeps for a period of time * Utility method that sleeps for a period of time
* *
* @param seconds integer that defines how many seconds to sleep * @param seconds integer that defines how many seconds to sleep
*/ */
private static void sleep(long seconds) { private static void sleep(long seconds) {
try { try {
TimeUnit.SECONDS.sleep(seconds); TimeUnit.SECONDS.sleep(seconds);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
Logger.getLogger(CoTMsgReceiver.class.getName()).log(Level.SEVERE, null, ex); Logger.getLogger(CoTMsgReceiver.class.getName()).log(Level.SEVERE, null, ex);
} }
}//sleep }//sleep
/** /**
* @param args the command line arguments * @param args the command line arguments
*/ */
public static void main(String[] args) { public static void main(String[] args) {
boolean isTcp = args[1].equalsIgnoreCase("tcp"); System.out.print ("CoTMsgReceiver");
for (String arg:args)
// - Create a custom CoTparser class. See CustomCoTparser.java. {
// - Override the coTeventHandler() to add your custom CoT data handling. System.out.print (" " + arg);
// - Invoke the customized parser: }
CustomCoTparser cp = new CustomCoTparser(); System.out.println();
CoTMsgParserDisRunner disr = new CoTMsgParserDisRunner("CoT PLI data DIS transmitter");
boolean isTcp = args[1].equalsIgnoreCase("tcp");
// Manage several UDP and TCP listeners
// - Create a CoT connector // - Create a custom CoTparser class. See CustomCoTparser.java.
CoTconnectors connectors = new CoTconnectors(); // - Override the coTeventHandler() to add your custom CoT data handling.
// - Invoke the customized parser:
// - Assign custom parsers to be used by the listeners. Note that the CustomCoTparser cp = new CustomCoTparser();
// CoT custom parser must be assigned before the listeners are started CoTMsgParserDisRunner disr = new CoTMsgParserDisRunner("CoT PLI data DIS transmitter");
connectors.addCoTparser(cp);
connectors.addCoTparser(disr); // Manage several UDP and TCP listeners
// - Create a CoT connector
// - Common usage example: CoTconnectors connectors = new CoTconnectors();
System.out.println("\n\nStarting listener pool\n");
// - Assign custom parsers to be used by the listeners. Note that the
if (isTcp) { // CoT custom parser must be assigned before the listeners are started
connectors.addTcpListener(9998); connectors.addCoTparser(cp);
connectors.startListener(9998); connectors.addCoTparser(disr);
} else {
connectors.addUdpListener(9999); // default packet size 1024 // - Common usage example:
connectors.startListener(9999); System.out.println("\n\nStarting listener pool\n");
}
if (isTcp) {
PipedOutputStream out = null; connectors.addTcpListener(9998);
connectors.startListener(9998);
// Redirect an output stream to be read by an input stream in order to } else {
// stop the TCP listener connectors.addUdpListener(9999); // default packet size 1024
try { connectors.startListener(9999);
out = new PipedOutputStream(); }
System.setIn(new PipedInputStream(out));
} catch (IOException ex) {} PipedOutputStream out = null;
// Start the CoT message generator/server // Redirect an output stream to be read by an input stream in order to
Runnable r = () -> { // stop the TCP listener
com.aciedge.cotplitool.Main.main(args); try {
}; out = new PipedOutputStream();
Thread t = new Thread(r); System.setIn(new PipedInputStream(out));
t.setDaemon(true); } catch (IOException ex) {}
t.start();
// Start the CoT message generator/server
sleep(5L); Runnable r = () -> {
com.aciedge.cotplitool.Main.main(args);
System.out.println("\n\nStopping listener pool\n"); };
Thread t = new Thread(r);
if (isTcp) t.setDaemon(true);
connectors.stopListener(9998); t.start();
else
connectors.stopListener(9999); sleep(5L);
// Issue the CoT message generator/server quit/exit command System.out.println("\n\nStopping listener pool\n");
try {
if (out != null) if (isTcp)
out.write("quit\n".getBytes("utf-8")); connectors.stopListener(9998);
} catch (IOException ex) {} else
connectors.stopListener(9999);
// Shutdown the DIS listerner
disr.getDisChannel().tearDownNetworkInterface(); // Issue the CoT message generator/server quit/exit command
try {
}// main if (out != null)
out.write("quit\n".getBytes("utf-8"));
} // end class CoTMsgReceiver } catch (IOException ex) {}
// Shutdown the DIS listerner
disr.getDisChannel().tearDownNetworkInterface();
}// main
} // end class CoTMsgReceiver
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment