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