From b4946419cb3bd2530a03aecaab1ac97c1052ce0b Mon Sep 17 00:00:00 2001 From: brutzman <brutzman@nps.edu> Date: Sat, 1 Jan 2022 18:21:34 -0800 Subject: [PATCH] further scaffolding: descriptor, disThreadedNetworkInterface, constructor utility methods --- .../OpenDis7Examples/SimulationManager.java | 152 +++++++++++++++++- 1 file changed, 149 insertions(+), 3 deletions(-) diff --git a/examples/src/OpenDis7Examples/SimulationManager.java b/examples/src/OpenDis7Examples/SimulationManager.java index 512260494c..c9ebff2965 100644 --- a/examples/src/OpenDis7Examples/SimulationManager.java +++ b/examples/src/OpenDis7Examples/SimulationManager.java @@ -1,9 +1,41 @@ /* - * Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. - * This work is provided under a BSD open-source license, see project license.html and license.txt - */ +Copyright (c) 1995-2021 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 + https://www.nps.edu and https://www.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. +*/ +// TODO move into open-dis7 distribution tree + package OpenDis7Examples; +import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface; import java.util.ArrayList; /** @@ -16,9 +48,29 @@ import java.util.ArrayList; */ public class SimulationManager { + private DisThreadedNetworkInterface disThreadedNetworkInterface; private ArrayList<RecordType> entityRecordList = new ArrayList<>(); private ArrayList<RecordType> hostRecordList = new ArrayList<>(); private ArrayList<RecordType> applicationRecordList = new ArrayList<>(); + private String descriptor = new String(); + + private String TRACE_PREFIX = "[" + (SimulationManager.class.getSimpleName()) + "] "; + + /** + * Object constructor with descriptor + * @param newDescriptor simple descriptor name for this class + */ + public SimulationManager (String newDescriptor) + { + this.descriptor = newDescriptor; + } + /** + * Object constructor + */ + public SimulationManager () + { + this(""); + } /** * Start the simulation according to specifications @@ -311,4 +363,98 @@ public class SimulationManager public ArrayList<RecordType> getApplicationRecordList() { return applicationRecordList; } + + /** + * Provide access to current disThreadedNetworkInterface + * @return the disThreadedNetworkInterface + */ + protected DisThreadedNetworkInterface getDisThreadedNetworkInterface() { + return disThreadedNetworkInterface; + } + /** + * Set the disThreadedNetworkInterface singleton to match other classes + * @param disThreadedNetworkInterface the disThreadedNetworkInterface to set + */ + public void setDisThreadedNetworkInterface(DisThreadedNetworkInterface disThreadedNetworkInterface) { + this.disThreadedNetworkInterface = disThreadedNetworkInterface; + } + /** + * Constructor for disThreadedNetworkInterface + */ + protected void createDisThreadedNetworkInterface() + { + this.disThreadedNetworkInterface = new DisThreadedNetworkInterface(descriptor); + } + /** + * Constructor for disThreadedNetworkInterface with descriptor, + * using default multicast address and port + * @param newDescriptor simple descriptor name for this interface + */ + protected void createDisThreadedNetworkInterface(String newDescriptor) + { + this.disThreadedNetworkInterface = new DisThreadedNetworkInterface(newDescriptor); + } + /** + * Constructor for disThreadedNetworkInterface using specified multicast address and port + * @param address the multicast group or unicast address to utilize + * @param port the multicast port to utilize + */ + protected void createDisThreadedNetworkInterface(String address, int port) + { + this.disThreadedNetworkInterface = new DisThreadedNetworkInterface(address, port, descriptor); + } + /** + * Constructor for disThreadedNetworkInterface using specified multicast address and port, plus descriptor. + * @param address the multicast group or unicast address to utilize + * @param port the multicast port to utilize + * @param newDescriptor simple descriptor name for this interface + */ + protected void createDisThreadedNetworkInterface(String address, int port, String newDescriptor) + { + this.disThreadedNetworkInterface = new DisThreadedNetworkInterface(address, port, newDescriptor); + } + /** + * Get simple descriptor (such as parent class name) for this SimulationManager, used in trace statements + * @return simple descriptor name + */ + public String getDescriptor() + { + return descriptor; + } + /** + * Set new simple descriptor (such as parent class name) for this SimulationManager, used in trace statements + * @param newDescriptor simple descriptor name for this interface + */ + public void setDescriptor(String newDescriptor) + { + this.descriptor = newDescriptor; + TRACE_PREFIX = "[" + (DisThreadedNetworkInterface.class.getSimpleName() + " " + descriptor).trim() + "] "; + } + + public void selfTest() + { + createDisThreadedNetworkInterface(); + + // TODO + + disThreadedNetworkInterface.close(); // tears down threads and sockets + } + + /** + * Main method for testing. + * @see <a href="https://docs.oracle.com/javase/tutorial/getStarted/application/index.html">Java Tutorials: A Closer Look at the "Hello World!" Application</a> + * @param args [address, port, descriptor] command-line arguments are an array of optional String parameters that are passed from execution environment during invocation + */ + public static void main(String[] args) + { + System.out.println("*** SimulationManager main() self test started..."); + + SimulationManager simulationManager = new SimulationManager("main() self test"); + + simulationManager.setDescriptor("main() self test"); + + simulationManager.selfTest(); + + System.out.println("*** SimulationManager main() self test complete."); + } } -- GitLab