Skip to content
Snippets Groups Projects
Commit b4946419 authored by Brutzman, Don's avatar Brutzman, Don
Browse files

further scaffolding: descriptor, disThreadedNetworkInterface, constructor utility methods

parent 3c0bd9eb
No related branches found
No related tags found
No related merge requests found
/* /*
* Copyright (c) 2008-2021, MOVES Institute, Naval Postgraduate School (NPS). All rights reserved. Copyright (c) 1995-2021 held by the author(s). All rights reserved.
* This work is provided under a BSD open-source license, see project license.html and license.txt
*/ 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; package OpenDis7Examples;
import edu.nps.moves.dis7.utilities.DisThreadedNetworkInterface;
import java.util.ArrayList; import java.util.ArrayList;
/** /**
...@@ -16,9 +48,29 @@ import java.util.ArrayList; ...@@ -16,9 +48,29 @@ import java.util.ArrayList;
*/ */
public class SimulationManager public class SimulationManager
{ {
private DisThreadedNetworkInterface disThreadedNetworkInterface;
private ArrayList<RecordType> entityRecordList = new ArrayList<>(); private ArrayList<RecordType> entityRecordList = new ArrayList<>();
private ArrayList<RecordType> hostRecordList = new ArrayList<>(); private ArrayList<RecordType> hostRecordList = new ArrayList<>();
private ArrayList<RecordType> applicationRecordList = 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 * Start the simulation according to specifications
...@@ -311,4 +363,98 @@ public class SimulationManager ...@@ -311,4 +363,98 @@ public class SimulationManager
public ArrayList<RecordType> getApplicationRecordList() { public ArrayList<RecordType> getApplicationRecordList() {
return applicationRecordList; 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.");
}
} }
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