├── .classpath ├── .gitignore ├── .project ├── .settings ├── net.sf.jautodoc.prefs ├── org.eclipse.jdt.core.prefs └── org.eclipse.m2e.core.prefs ├── LICENSE ├── README.md ├── pom.xml ├── repo └── hla │ ├── mak │ └── hla │ │ └── 4.4.0 │ │ └── hla-4.4.0.jar │ └── pitch │ ├── booster1516 │ └── 5.0.1 │ │ └── booster1516-5.0.1.jar │ ├── prti │ └── 5.0.1 │ │ └── prti-5.0.1.jar │ ├── prti1516e │ └── 5.0.1 │ │ └── prti1516e-5.0.1.jar │ └── prticore │ └── 5.0.1 │ └── prticore-5.0.1.jar └── src ├── main ├── java │ └── dkf │ │ ├── coder │ │ ├── Coder.java │ │ ├── HLAasciiCharCoder.java │ │ ├── HLAasciiStringCoder.java │ │ ├── HLAbooleanCoder.java │ │ ├── HLAbyteCoder.java │ │ ├── HLAfloat32BECoder.java │ │ ├── HLAfloat32LECoder.java │ │ ├── HLAfloat64BECoder.java │ │ ├── HLAfloat64LECoder.java │ │ ├── HLAinteger16BECoder.java │ │ ├── HLAinteger16LECoder.java │ │ ├── HLAinteger32BECoder.java │ │ ├── HLAinteger32LECoder.java │ │ ├── HLAinteger64BECoder.java │ │ ├── HLAinteger64LECoder.java │ │ ├── HLAunicodeCharCoder.java │ │ └── HLAunicodeStringCoder.java │ │ ├── config │ │ ├── Configuration.java │ │ ├── ConfigurationFactory.java │ │ ├── ConfigurationFactoryInterface.java │ │ └── ConfigurationInterface.java │ │ ├── core │ │ ├── DKFAbstractFederate.java │ │ ├── DKFAbstractFederateAmbassador.java │ │ ├── DKFFederateInterface.java │ │ ├── DKFHLAModule.java │ │ ├── DKFRTIAmbassador.java │ │ ├── ExecutionTask.java │ │ └── observer │ │ │ └── Subject.java │ │ ├── exception │ │ ├── ConfigurationSyntaxException.java │ │ ├── FirewallExeption.java │ │ ├── PublishException.java │ │ ├── RegisterElementNameException.java │ │ ├── SubscribeException.java │ │ ├── TimeRepresentationException.java │ │ ├── UnsubscribeException.java │ │ └── UpdateException.java │ │ ├── model │ │ ├── Order.java │ │ ├── Sharing.java │ │ ├── Transportation.java │ │ ├── interaction │ │ │ ├── InteractionClassEntity.java │ │ │ ├── InteractionClassModel.java │ │ │ ├── InteractionClassModelManager.java │ │ │ ├── InteractionClassModelParser.java │ │ │ └── annotations │ │ │ │ ├── InteractionClass.java │ │ │ │ └── Parameter.java │ │ ├── object │ │ │ ├── AbstractClassEntity.java │ │ │ ├── NameReservationStatus.java │ │ │ ├── ObjectClassEntity.java │ │ │ ├── ObjectClassHandleEntity.java │ │ │ ├── ObjectClassModel.java │ │ │ ├── ObjectClassModelManager.java │ │ │ ├── ObjectClassModelParser.java │ │ │ ├── ObjectModelStatus.java │ │ │ └── annotations │ │ │ │ ├── Attribute.java │ │ │ │ ├── ObjectClass.java │ │ │ │ ├── Ownership.java │ │ │ │ └── UpdateType.java │ │ └── parser │ │ │ └── AbstractObjectModelParser.java │ │ ├── time │ │ ├── Float64Time.java │ │ ├── Integer64Time.java │ │ ├── TimeAbstract.java │ │ ├── TimeFactory.java │ │ ├── TimeFactoryInterface.java │ │ └── TimeInterface.java │ │ └── utility │ │ ├── JulianDateType.java │ │ ├── SystemUtility.java │ │ ├── TimeUnit.java │ │ ├── TimeUtility.java │ │ └── access │ │ ├── FOMDataInspector.java │ │ ├── FOMDataInspectoryFactory.java │ │ └── TimeType.java └── resources │ └── log4j2.xml └── test ├── java └── dkf │ ├── config │ └── ConfigurationFactoryTest.java │ ├── core │ └── DKFAbstractFederateTest.java │ └── utility │ └── access │ └── FOMDataInspectorTest.java └── resources └── configuration.json /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | /logs/ 3 | /repo/ 4 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | HLADevelopmentKit 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.eclipse.m2e.core.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.eclipse.jdt.core.javanature 21 | org.eclipse.m2e.core.maven2Nature 22 | 23 | 24 | -------------------------------------------------------------------------------- /.settings/net.sf.jautodoc.prefs: -------------------------------------------------------------------------------- 1 | add_header=true 2 | add_todo=false 3 | create_dummy_doc=false 4 | eclipse.preferences.version=1 5 | filter_fields=false 6 | filter_methods=false 7 | filter_types=false 8 | header_text=/*****************************************************************\r\n\r\n${project} - A Java framework to develop HLA Federates.\r\nCopyright (c) ${year}, ${owner}, \r\nAll rights reserved.\r\n\r\nGNU Lesser General Public License (GNU LGPL).\r\n\r\nThis library is free software; you can redistribute it and/or\r\nmodify it under the terms of the GNU Lesser General Public\r\nLicense as published by the Free Software Foundation; either\r\nversion 3.0 of the License, or (at your option) any later version.\r\n\r\nThis library is distributed in the hope that it will be useful,\r\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\r\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r\nLesser General Public License for more details.\r\n\r\nYou should have received a copy of the GNU Lesser General Public\r\nLicense along with this library. \r\nIf not, see ${lgpl_website}\r\n\r*****************************************************************/ 9 | project_specific_settings=true 10 | properties=project,owner,year,lgpl_website, 11 | properties.lgpl_website=http\://http\://www.gnu.org/licenses/ 12 | properties.owner=SMASH Lab - University of Calabria (Italy) 13 | properties.project=HLADevelopmentKit 14 | properties.year=2015 15 | replace_header=true 16 | replacements=\n\n\nGets the\nSets the\nAdds the\nEdits the\nRemoves the\nInits the\nParses the\nCreates the\nBuilds the\nChecks if is\nPrints the\nChecks for\n\n\n 17 | single_line_comment=false 18 | visibility_package=false 19 | visibility_private=false 20 | visibility_protected=false 21 | visibility_public=false 22 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.7 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.7 13 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | 10 | This version of the GNU Lesser General Public License incorporates 11 | the terms and conditions of version 3 of the GNU General Public 12 | License, supplemented by the additional permissions listed below. 13 | 14 | 0. Additional Definitions. 15 | 16 | As used herein, "this License" refers to version 3 of the GNU Lesser 17 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 18 | General Public License. 19 | 20 | "The Library" refers to a covered work governed by this License, 21 | other than an Application or a Combined Work as defined below. 22 | 23 | An "Application" is any work that makes use of an interface provided 24 | by the Library, but which is not otherwise based on the Library. 25 | Defining a subclass of a class defined by the Library is deemed a mode 26 | of using an interface provided by the Library. 27 | 28 | A "Combined Work" is a work produced by combining or linking an 29 | Application with the Library. The particular version of the Library 30 | with which the Combined Work was made is also called the "Linked 31 | Version". 32 | 33 | The "Minimal Corresponding Source" for a Combined Work means the 34 | Corresponding Source for the Combined Work, excluding any source code 35 | for portions of the Combined Work that, considered in isolation, are 36 | based on the Application, and not on the Linked Version. 37 | 38 | The "Corresponding Application Code" for a Combined Work means the 39 | object code and/or source code for the Application, including any data 40 | and utility programs needed for reproducing the Combined Work from the 41 | Application, but excluding the System Libraries of the Combined Work. 42 | 43 | 1. Exception to Section 3 of the GNU GPL. 44 | 45 | You may convey a covered work under sections 3 and 4 of this License 46 | without being bound by section 3 of the GNU GPL. 47 | 48 | 2. Conveying Modified Versions. 49 | 50 | If you modify a copy of the Library, and, in your modifications, a 51 | facility refers to a function or data to be supplied by an Application 52 | that uses the facility (other than as an argument passed when the 53 | facility is invoked), then you may convey a copy of the modified 54 | version: 55 | 56 | a) under this License, provided that you make a good faith effort to 57 | ensure that, in the event an Application does not supply the 58 | function or data, the facility still operates, and performs 59 | whatever part of its purpose remains meaningful, or 60 | 61 | b) under the GNU GPL, with none of the additional permissions of 62 | this License applicable to that copy. 63 | 64 | 3. Object Code Incorporating Material from Library Header Files. 65 | 66 | The object code form of an Application may incorporate material from 67 | a header file that is part of the Library. You may convey such object 68 | code under terms of your choice, provided that, if the incorporated 69 | material is not limited to numerical parameters, data structure 70 | layouts and accessors, or small macros, inline functions and templates 71 | (ten or fewer lines in length), you do both of the following: 72 | 73 | a) Give prominent notice with each copy of the object code that the 74 | Library is used in it and that the Library and its use are 75 | covered by this License. 76 | 77 | b) Accompany the object code with a copy of the GNU GPL and this license 78 | document. 79 | 80 | 4. Combined Works. 81 | 82 | You may convey a Combined Work under terms of your choice that, 83 | taken together, effectively do not restrict modification of the 84 | portions of the Library contained in the Combined Work and reverse 85 | engineering for debugging such modifications, if you also do each of 86 | the following: 87 | 88 | a) Give prominent notice with each copy of the Combined Work that 89 | the Library is used in it and that the Library and its use are 90 | covered by this License. 91 | 92 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 93 | document. 94 | 95 | c) For a Combined Work that displays copyright notices during 96 | execution, include the copyright notice for the Library among 97 | these notices, as well as a reference directing the user to the 98 | copies of the GNU GPL and this license document. 99 | 100 | d) Do one of the following: 101 | 102 | 0) Convey the Minimal Corresponding Source under the terms of this 103 | License, and the Corresponding Application Code in a form 104 | suitable for, and under terms that permit, the user to 105 | recombine or relink the Application with a modified version of 106 | the Linked Version to produce a modified Combined Work, in the 107 | manner specified by section 6 of the GNU GPL for conveying 108 | Corresponding Source. 109 | 110 | 1) Use a suitable shared library mechanism for linking with the 111 | Library. A suitable mechanism is one that (a) uses at run time 112 | a copy of the Library already present on the user's computer 113 | system, and (b) will operate properly with a modified version 114 | of the Library that is interface-compatible with the Linked 115 | Version. 116 | 117 | e) Provide Installation Information, but only if you would otherwise 118 | be required to provide such information under section 6 of the 119 | GNU GPL, and only to the extent that such information is 120 | necessary to install and execute a modified version of the 121 | Combined Work produced by recombining or relinking the 122 | Application with a modified version of the Linked Version. (If 123 | you use option 4d0, the Installation Information must accompany 124 | the Minimal Corresponding Source and Corresponding Application 125 | Code. If you use option 4d1, you must provide the Installation 126 | Information in the manner specified by section 6 of the GNU GPL 127 | for conveying Corresponding Source.) 128 | 129 | 5. Combined Libraries. 130 | 131 | You may place library facilities that are a work based on the 132 | Library side by side in a single library together with other library 133 | facilities that are not Applications and are not covered by this 134 | License, and convey such a combined library under terms of your 135 | choice, if you do both of the following: 136 | 137 | a) Accompany the combined library with a copy of the same work based 138 | on the Library, uncombined with any other library facilities, 139 | conveyed under the terms of this License. 140 | 141 | b) Give prominent notice with the combined library that part of it 142 | is a work based on the Library, and explaining where to find the 143 | accompanying uncombined form of the same work. 144 | 145 | 6. Revised Versions of the GNU Lesser General Public License. 146 | 147 | The Free Software Foundation may publish revised and/or new versions 148 | of the GNU Lesser General Public License from time to time. Such new 149 | versions will be similar in spirit to the present version, but may 150 | differ in detail to address new problems or concerns. 151 | 152 | Each version is given a distinguishing version number. If the 153 | Library as you received it specifies that a certain numbered version 154 | of the GNU Lesser General Public License "or any later version" 155 | applies to it, you have the option of following the terms and 156 | conditions either of that published version or of any later version 157 | published by the Free Software Foundation. If the Library as you 158 | received it does not specify a version number of the GNU Lesser 159 | General Public License, you may choose any version of the GNU Lesser 160 | General Public License ever published by the Free Software Foundation. 161 | 162 | If the Library as you received it specifies that a proxy can decide 163 | whether future versions of the GNU Lesser General Public License shall 164 | apply, that proxy's public statement of acceptance of any version is 165 | permanent authorization for you to choose that version for the 166 | Library. 167 | 168 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # HLA Development Kit 2 | 3 | The development of a HLA Federation with its Federates is a quite complex task and there are few training resources for developers [2, 4]. The HLA Development Kit aims at easing the development of HLA Federates by providing the following resources: (i) a _software framework (the DKF)_ for the development in Java of HLA Federates; (ii) a _technical documentation_ that describes the DKF; (iii) a _user guide_ to support developers in the use of the DKF; (iv) a set of _reference examples_ of HLA Federates created by using the DKF; and, (v) _video-tutorials_, which show how to create both the structure and the behavior of a HLA Federate by using the DKF. 4 | The DKF is a general-purpose, domain-independent framework, released under the open source policy Lesser GNU Public License (LGPL), which facilitates the development of HLA Federates. Indeed, the DKF allows developers to focus on the specific aspects of their own Federates rather than dealing with the common HLA functionalities, such as the management of the simulation time; the connection/disconnection on/from the HLA RTI [1, 3]; the publishing, subscribing and updating of ObjectClass and InteractionClass elements. 5 | The DKF is fully implemented in the Java language and is based on the following three principles: (i) _Interoperability_, DKF is fully compliant with the IEEE 1516-2010 specifications; as a consequence, it is platform-independent and can interoperate with different HLA RTI implementations (e.g. PITCH, VT/MÄK, PoRTIco, CERTI); (ii) _Portability and Uniformity_, DKF provides a homogeneous set of APIs that are independent from the underlying HLA RTI and Java version. In this way, developers could decide the HLA RTI and the Java run-time environment at development-time; and (iii) _Usability_, the complexity of the features provided by the DKF framework are hidden behind an intuitive set of APIs. 6 | 7 | The HLA Development Kit is designed, developed, released and managed by the SEI (Systems Engineering and Integration) team, operating in the System Modeling and Simulation Hub (SMASH) Lab of the Department of Informatics, Modeling, Electronics and Systems Engineering (DIMES), University of Calabria (Italy), working in cooperation with NASA JSC (Johnson Space Center), Houston (TX, USA). 8 | 9 | 10 | ## **External links** 11 | 12 | * Official website [link](https://smash-lab.github.io/HLA-Development-Kit/); 13 | * DKF all-in-one package [link](https://drive.google.com/open?id=0B6Txsul1iIJmVFdTX0Roc2tGeFk); 14 | * Documentation (API) [link](https://smash-lab.github.io/HLA-Development-Kit/docs/index.html); 15 | * Technical documentations [link](https://smash-lab.github.io/HLA-Development-Kit/document/HLA_Development_Kit_ver_0.0.1.pdf); 16 | * Examples and video-tutorials: How to build a Federate from scratch in 30 minutes! [link](https://drive.google.com/open?id=0B6Txsul1iIJma3pITXE1M2hSOVk); 17 | * The [SEE](http://exploresim.com/) HLA Starter Kit: The SEE-specific extension of the HLA Development Kit [link](https://code.google.com/p/see-hla-starterkit/). 18 | 19 | ## **Working team** 20 | 21 | * Alfredo Garro, [alfredo.garro@unical.it](mailto:alfredo.garro@unical.it) (coordinator); 22 | * Alberto Falcone, [alberto.falcone@dimes.unical.it](mailto:alberto.falcone@dimes.unical.it) (main developer); 23 | * Andrea Tundis, [andrea.tundis@dimes.unical.it](mailto:andrea.tundis@dimes.unical.it) (developer). 24 | 25 | ## **Acknowledgments** 26 | 27 | The DKF working team would like to thank Edwin Z. Crues (NASA JCS) for his precious advice and suggestions in the development of the HLA Development Kit. A special note of thanks goes also to all the NASA staff involved in the Simulation Exploration Experience (SEE) Project: Priscilla Elfrey, Stephen Paglialonga, Michael Conroy, Dan Dexter, Daniel Oneil, to Björn Möller (PITCH Technologies), and to all the members of SEE teams. 28 | 29 |
30 | 31 | ##**References** 32 | 33 | 1. Anagnostou, A., Chaudhry, N.R., Falcone, A., Garro, A., Salah, O., Taylor, S.J.E., _Easing the development of HLA Federates: the HLA Development Kit and its exploitation in the SEE Project_. In Proc. of the 19th IEEE/ACM International Symposium on Distributed Simulation and Real Time Applications (ACM/IEEE DS-RT), Chengdu, China, October, 14-16, IEEE Computer Society, (2015). 34 | 35 | 2. Anagnostou, A., Chaudhry, N.R., Falcone, A., Garro, A., Salah, O., Taylor, S.J.E., _A Prototype HLA Development Kit: Results from the 2015 Simulation Exploration Experience_. In Proc. of the ACM SIGSIM PADS 2015, London, UK, June, 10-12, (2015). 36 | 37 | 3. Bocciarelli, P., D’Ambrogio, A., Falcone, A., Garro, A., Giglio, A., _A model-driven approach to enable the distributed simulation of complex systems_. In Proc. of the 6th Complex Systems Design & Management (CSD&M) 2015, Paris, France, November 23-25, (2015). 38 | 39 | 4. Falcone, A., Garro, A., Longo, F., Spadafora, F., _SimulationExploration Experience: A Communication System and a 3D Real Time Visualization for a Moon base simulated scenario_. In Proc. of the 18th IEEE/ACM International Symposium on Distributed Simulation and Real Time Applications (ACM/IEEE DS-RT), Toulouse, France, October, 1-3, IEEE Computer Society, (2014). -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | com.unical.smashlab 5 | HLADevelopmentKit 6 | 0.0.2 7 | HLADevelopmentKit 8 | 9 | 10 | 1.7 11 | ${basedir}/target 12 | dkf 13 | 14 | 15 | 16 | 17 | localrepository 18 | file://${basedir}/repo 19 | 20 | 21 | 22 | 23 | 24 | org.apache.commons 25 | commons-collections4 26 | 4.0 27 | 28 | 29 | joda-time 30 | joda-time 31 | 2.8 32 | 33 | 34 | com.fasterxml.jackson.core 35 | jackson-databind 36 | 2.8.11 37 | 38 | 39 | com.fasterxml.jackson.datatype 40 | jackson-datatype-joda 41 | 2.8.11 42 | 43 | 44 | org.apache.logging.log4j 45 | log4j-core 46 | 2.3 47 | 48 | 49 | 50 | org.jodd 51 | jodd-core 52 | 3.6.6 53 | 54 | 55 | 56 | junit 57 | junit 58 | 4.12 59 | 61 | provided 62 | 63 | 64 | 65 | org.jdom 66 | jdom2 67 | 2.0.6 68 | 69 | 70 | 71 | jaxen 72 | jaxen 73 | 1.1.6 74 | 75 | 76 | 77 | 78 | hla.pitch 79 | booster1516 80 | 5.0.1 81 | 83 | provided 84 | 85 | 86 | hla.pitch 87 | prti 88 | 5.0.1 89 | 91 | provided 92 | 93 | 94 | hla.pitch 95 | prti1516e 96 | 5.0.1 97 | 99 | provided 100 | 101 | 102 | hla.pitch 103 | prticore 104 | 5.0.1 105 | 107 | provided 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | org.apache.maven.plugins 118 | maven-eclipse-plugin 119 | 2.10 120 | 121 | true 122 | false 123 | 124 | 125 | 126 | 127 | 128 | org.apache.maven.plugins 129 | maven-compiler-plugin 130 | 2.3.2 131 | 132 | ${jdk.version} 133 | ${jdk.version} 134 | 135 | 136 | 137 | 138 | 139 | org.apache.maven.plugins 140 | maven-assembly-plugin 141 | 2.5.5 142 | 143 | 144 | 145 | jar-with-dependencies 146 | 147 | 148 | 149 | ${jar.name}-${project.version} 150 | false 151 | 152 | 153 | 154 | 155 | 156 | org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader 157 | 158 | 159 | 160 | 161 | 162 | make-assembly 163 | 164 | package 165 | 166 | single 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | org.apache.maven.plugins 175 | maven-javadoc-plugin 176 | 2.10.3 177 | 178 | test.* 179 | ${targerDir}/ 180 | docs 181 | 182 | 183 | 184 | attach-javadoc 185 | 186 | prepare-package 187 | 188 | aggregate 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /repo/hla/mak/hla/4.4.0/hla-4.4.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SMASH-Lab/HLA-Development-Kit/84dce897d8c5d475dfbca93e574715475b23e2ee/repo/hla/mak/hla/4.4.0/hla-4.4.0.jar -------------------------------------------------------------------------------- /repo/hla/pitch/booster1516/5.0.1/booster1516-5.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SMASH-Lab/HLA-Development-Kit/84dce897d8c5d475dfbca93e574715475b23e2ee/repo/hla/pitch/booster1516/5.0.1/booster1516-5.0.1.jar -------------------------------------------------------------------------------- /repo/hla/pitch/prti/5.0.1/prti-5.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SMASH-Lab/HLA-Development-Kit/84dce897d8c5d475dfbca93e574715475b23e2ee/repo/hla/pitch/prti/5.0.1/prti-5.0.1.jar -------------------------------------------------------------------------------- /repo/hla/pitch/prti1516e/5.0.1/prti1516e-5.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SMASH-Lab/HLA-Development-Kit/84dce897d8c5d475dfbca93e574715475b23e2ee/repo/hla/pitch/prti1516e/5.0.1/prti1516e-5.0.1.jar -------------------------------------------------------------------------------- /repo/hla/pitch/prticore/5.0.1/prticore-5.0.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SMASH-Lab/HLA-Development-Kit/84dce897d8c5d475dfbca93e574715475b23e2ee/repo/hla/pitch/prticore/5.0.1/prticore-5.0.1.jar -------------------------------------------------------------------------------- /src/main/java/dkf/coder/Coder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.encoding.DecoderException; 25 | 26 | public interface Coder { 27 | 28 | public T decode(byte[] code) throws DecoderException; 29 | 30 | public byte[] encode(T element); 31 | 32 | public Class getAllowedType(); 33 | 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAasciiCharCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAASCIIchar; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAasciiCharCoder implements Coder { 31 | 32 | private HLAASCIIchar coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAasciiCharCoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAASCIIchar(); 38 | } 39 | 40 | public Byte decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(Byte value) { 46 | coder.setValue(value); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return Byte.class; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAasciiStringCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAASCIIstring; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAasciiStringCoder implements Coder { 31 | 32 | private HLAASCIIstring coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAasciiStringCoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAASCIIstring(); 38 | } 39 | 40 | public String decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(String element) { 46 | coder.setValue(element); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return String.class; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAbooleanCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAboolean; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAbooleanCoder implements Coder{ 33 | 34 | private HLAboolean coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAbooleanCoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAboolean(); 40 | } 41 | 42 | public Boolean decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Boolean element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Boolean.class; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAbyteCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAbyte; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAbyteCoder implements Coder{ 33 | 34 | private HLAbyte coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAbyteCoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAbyte(); 40 | } 41 | 42 | public Byte decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Byte element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Byte.class; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAfloat32BECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAfloat32BE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAfloat32BECoder implements Coder{ 33 | 34 | private HLAfloat32BE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAfloat32BECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAfloat32BE(); 40 | } 41 | 42 | public Float decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Float element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Float.class; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAfloat32LECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAfloat32LE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAfloat32LECoder implements Coder{ 33 | 34 | private HLAfloat32LE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAfloat32LECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAfloat32LE(); 40 | } 41 | 42 | public Float decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Float element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Float.class; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAfloat64BECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAfloat64BE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAfloat64BECoder implements Coder{ 31 | 32 | private HLAfloat64BE coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAfloat64BECoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAfloat64BE(); 38 | } 39 | 40 | public Double decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(Double element) { 46 | coder.setValue(element); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return Double.class; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAfloat64LECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAfloat64LE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAfloat64LECoder implements Coder{ 31 | 32 | private HLAfloat64LE coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAfloat64LECoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAfloat64LE(); 38 | } 39 | 40 | public Double decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(Double element) { 46 | coder.setValue(element); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return Double.class; 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger16BECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger16BE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | public class HLAinteger16BECoder implements Coder{ 32 | 33 | private HLAinteger16BE coder = null; 34 | private EncoderFactory factory = null; 35 | 36 | public HLAinteger16BECoder() throws RTIinternalError { 37 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 38 | this.coder = factory.createHLAinteger16BE(); 39 | } 40 | 41 | public Short decode(byte[] code) throws DecoderException { 42 | coder.decode(code); 43 | return coder.getValue(); 44 | } 45 | 46 | public byte[] encode(Short element) { 47 | coder.setValue(element); 48 | return coder.toByteArray(); 49 | } 50 | 51 | public Class getAllowedType() { 52 | return Short.class; 53 | } 54 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger16LECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger16LE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | public class HLAinteger16LECoder implements Coder{ 32 | 33 | private HLAinteger16LE coder = null; 34 | private EncoderFactory factory = null; 35 | 36 | public HLAinteger16LECoder() throws RTIinternalError { 37 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 38 | this.coder = factory.createHLAinteger16LE(); 39 | } 40 | 41 | public Short decode(byte[] code) throws DecoderException { 42 | coder.decode(code); 43 | return coder.getValue(); 44 | } 45 | 46 | public byte[] encode(Short element) { 47 | coder.setValue(element); 48 | return coder.toByteArray(); 49 | } 50 | 51 | public Class getAllowedType() { 52 | return Short.class; 53 | } 54 | 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger32BECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger32BE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAinteger32BECoder implements Coder{ 33 | 34 | private HLAinteger32BE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAinteger32BECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAinteger32BE(); 40 | } 41 | 42 | public Integer decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Integer element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Integer.class; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger32LECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger32LE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAinteger32LECoder implements Coder{ 33 | 34 | private HLAinteger32LE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAinteger32LECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAinteger32LE(); 40 | } 41 | 42 | public Integer decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Integer element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Integer.class; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger64BECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger64BE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAinteger64BECoder implements Coder{ 33 | 34 | private HLAinteger64BE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAinteger64BECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAinteger64BE(); 40 | } 41 | 42 | public Long decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Long element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Long.class; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAinteger64LECoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAinteger64LE; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | 31 | 32 | public class HLAinteger64LECoder implements Coder{ 33 | 34 | private HLAinteger64LE coder = null; 35 | private EncoderFactory factory = null; 36 | 37 | public HLAinteger64LECoder() throws RTIinternalError { 38 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 39 | this.coder = factory.createHLAinteger64LE(); 40 | } 41 | 42 | public Long decode(byte[] code) throws DecoderException { 43 | coder.decode(code); 44 | return coder.getValue(); 45 | } 46 | 47 | public byte[] encode(Long element) { 48 | coder.setValue(element); 49 | return coder.toByteArray(); 50 | } 51 | 52 | public Class getAllowedType() { 53 | return Long.class; 54 | } 55 | 56 | } -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAunicodeCharCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAunicodeChar; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAunicodeCharCoder implements Coder { 31 | 32 | private HLAunicodeChar coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAunicodeCharCoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAunicodeChar(); 38 | } 39 | 40 | public Short decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(Short value) { 46 | coder.setValue(value); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return Short.class; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dkf/coder/HLAunicodeStringCoder.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.coder; 23 | 24 | import hla.rti1516e.RtiFactoryFactory; 25 | import hla.rti1516e.encoding.DecoderException; 26 | import hla.rti1516e.encoding.EncoderFactory; 27 | import hla.rti1516e.encoding.HLAunicodeString; 28 | import hla.rti1516e.exceptions.RTIinternalError; 29 | 30 | public class HLAunicodeStringCoder implements Coder { 31 | 32 | private HLAunicodeString coder = null; 33 | private EncoderFactory factory = null; 34 | 35 | public HLAunicodeStringCoder() throws RTIinternalError { 36 | this.factory = RtiFactoryFactory.getRtiFactory().getEncoderFactory(); 37 | this.coder = factory.createHLAunicodeString(); 38 | } 39 | 40 | public String decode(byte[] code) throws DecoderException { 41 | coder.decode(code); 42 | return coder.getValue(); 43 | } 44 | 45 | public byte[] encode(String element) { 46 | coder.setValue(element); 47 | return coder.toByteArray(); 48 | } 49 | 50 | public Class getAllowedType() { 51 | return String.class; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dkf/config/Configuration.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.config; 23 | 24 | import java.io.File; 25 | import java.util.regex.Matcher; 26 | import java.util.regex.Pattern; 27 | 28 | import org.joda.time.DateTime; 29 | 30 | /** 31 | * 32 | * @author SMASH-Lab University of Calabria 33 | * @version 0.1 34 | * 35 | */ 36 | public class Configuration implements ConfigurationInterface { 37 | 38 | 39 | private static final String IP_PATTERN = "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + 40 | "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + 41 | "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + 42 | "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; 43 | 44 | private boolean isAsynchronousDelivery; 45 | private String crcHost; 46 | private int crcPort; 47 | private String federationName; 48 | private String federateName; 49 | private String federateType; 50 | private File fomDirectory; 51 | private boolean isRealtime; 52 | private boolean isTimeConstrained; 53 | private boolean isTimeRegulating; 54 | private DateTime simulationEphoc; 55 | 56 | protected Configuration() {} 57 | 58 | public boolean isAsynchronousDelivery() { 59 | return isAsynchronousDelivery; 60 | } 61 | 62 | public void setAsynchronousDelivery(boolean isAsynchronousDelivery) { 63 | this.isAsynchronousDelivery = isAsynchronousDelivery; 64 | } 65 | 66 | public String getCrcHost() { 67 | return crcHost; 68 | } 69 | 70 | public void setCrcHost(String crcHost) { 71 | if( crcHost == null || (!crcHost.equalsIgnoreCase("localhost") && !ipIsValid(crcHost)) ) 72 | throw new IllegalArgumentException("Invalid IP Address"); 73 | this.crcHost = crcHost; 74 | } 75 | 76 | public int getCrcPort() { 77 | return crcPort; 78 | } 79 | 80 | public void setCrcPort(int crcPort) { 81 | if(crcPort < 1024 || crcPort > 49151) 82 | throw new IllegalArgumentException("Invalid CRC Port, The CRC Port must be in the range [1024 - 49151]"); 83 | this.crcPort = crcPort; 84 | } 85 | 86 | public String getFederationName() { 87 | return federationName; 88 | } 89 | 90 | public void setFederationName(String federationName) { 91 | this.federationName = federationName; 92 | } 93 | 94 | public String getFederateName() { 95 | return federateName; 96 | } 97 | 98 | public void setFederateName(String federateName) { 99 | this.federateName = federateName; 100 | } 101 | 102 | public String getFederateType() { 103 | return federateType; 104 | } 105 | 106 | public void setFederateType(String federateType) { 107 | this.federateType = federateType; 108 | } 109 | 110 | public File getFomDirectory() { 111 | return fomDirectory; 112 | } 113 | 114 | public void setFomDirectory(File fomDirectory) { 115 | if(fomDirectory == null || !fomDirectory.isDirectory()) 116 | throw new IllegalArgumentException("The parameter must be a directory"); 117 | this.fomDirectory = fomDirectory; 118 | } 119 | 120 | public boolean isRealtime() { 121 | return isRealtime; 122 | } 123 | 124 | public void setRealtime(boolean isRealtime) { 125 | this.isRealtime = isRealtime; 126 | } 127 | 128 | public boolean isTimeConstrained() { 129 | return isTimeConstrained; 130 | } 131 | 132 | public void setTimeConstrained(boolean isTimeConstrained) { 133 | this.isTimeConstrained = isTimeConstrained; 134 | } 135 | 136 | public boolean isTimeRegulating() { 137 | return isTimeRegulating; 138 | } 139 | 140 | public void setTimeRegulating(boolean isTimeRegulating) { 141 | this.isTimeRegulating = isTimeRegulating; 142 | } 143 | 144 | private boolean ipIsValid(String ip){ 145 | 146 | Pattern pattern = Pattern.compile(IP_PATTERN); 147 | Matcher matcher = pattern.matcher(ip); 148 | return matcher.matches(); 149 | } 150 | 151 | public DateTime getSimulationEphoc() { 152 | return simulationEphoc; 153 | } 154 | 155 | public void setSimulationEphoc(DateTime simulationEphoc) { 156 | this.simulationEphoc = simulationEphoc; 157 | } 158 | 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/dkf/config/ConfigurationFactory.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.config; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | 27 | import org.apache.logging.log4j.LogManager; 28 | import org.apache.logging.log4j.Logger; 29 | 30 | import com.fasterxml.jackson.core.JsonGenerationException; 31 | import com.fasterxml.jackson.core.JsonParseException; 32 | import com.fasterxml.jackson.databind.JsonMappingException; 33 | import com.fasterxml.jackson.databind.MapperFeature; 34 | import com.fasterxml.jackson.databind.ObjectMapper; 35 | import com.fasterxml.jackson.databind.SerializationFeature; 36 | import com.fasterxml.jackson.datatype.joda.JodaModule; 37 | 38 | public class ConfigurationFactory implements ConfigurationFactoryInterface { 39 | 40 | Logger logger = LogManager.getLogger(ConfigurationFactory.class); 41 | 42 | private ObjectMapper mapper = null; 43 | 44 | public Configuration importConfiguration(File file) throws JsonParseException, JsonMappingException, IOException { 45 | logger.info("Importing the DKF configuration file"); 46 | return getObjectMapper().readValue(file, Configuration.class); 47 | 48 | } 49 | 50 | 51 | public void exportConfiguration(Configuration config, File outputFile) throws JsonGenerationException, JsonMappingException, IOException { 52 | logger.info("Exporting the DKF configuration file"); 53 | getObjectMapper().writerWithDefaultPrettyPrinter().writeValue(outputFile, config); 54 | 55 | } 56 | 57 | public Configuration createConfiguration() { 58 | return new Configuration(); 59 | } 60 | 61 | private ObjectMapper getObjectMapper() { 62 | if(mapper == null){ 63 | mapper = new ObjectMapper(); 64 | mapper.registerModule(new JodaModule()); 65 | mapper.configure(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY, true); 66 | mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false); 67 | } 68 | return mapper; 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /src/main/java/dkf/config/ConfigurationFactoryInterface.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.config; 23 | 24 | import java.io.File; 25 | import java.io.FileNotFoundException; 26 | import java.io.IOException; 27 | 28 | import com.fasterxml.jackson.core.JsonParseException; 29 | import com.fasterxml.jackson.databind.JsonMappingException; 30 | 31 | /** 32 | * 33 | * @author SMASH-Lab University of Calabria 34 | * @version 0.1 35 | * 36 | */ 37 | public interface ConfigurationFactoryInterface { 38 | 39 | /** 40 | * Imports the configuration parameters from a given file 41 | * @param file configuration file 42 | * @throws FileNotFoundException 43 | * @throws IOException 44 | * @throws JsonMappingException 45 | * @throws JsonParseException 46 | */ 47 | public Configuration importConfiguration(File file) throws FileNotFoundException, JsonParseException, JsonMappingException, IOException; 48 | 49 | /** 50 | * Export the configuration parameters into a given directory 51 | * @param config AbstractConfiguration object 52 | * @param outputFile output file 53 | * @throws IOException 54 | */ 55 | public void exportConfiguration(Configuration config, File outputFile) throws IOException; 56 | 57 | 58 | /** 59 | * Create an empty Configuration object 60 | * @return an empty Configuration object 61 | */ 62 | public Configuration createConfiguration(); 63 | 64 | } -------------------------------------------------------------------------------- /src/main/java/dkf/config/ConfigurationInterface.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.config; 23 | 24 | import java.io.File; 25 | 26 | import org.joda.time.DateTime; 27 | 28 | /** 29 | * 30 | * The root interface in the Configuration hierarchy. 31 | * A configuration is a set of parameters, which are used by the DKF framework 32 | * to set up a Federate on the specific RTI infrastructure. 33 | * 34 | * @author SMASH-Lab University of Calabria 35 | * @version 0.1 36 | * 37 | */ 38 | public interface ConfigurationInterface { 39 | 40 | /** 41 | * @return The IP address of the host 42 | */ 43 | public String getCrcHost(); 44 | 45 | /** 46 | * @return The CRC port 47 | */ 48 | public int getCrcPort(); 49 | 50 | /** 51 | * @return The name of the SEE Federation 52 | */ 53 | public String getFederationName(); 54 | 55 | /** 56 | * @return The name of the SEE Federate 57 | */ 58 | public String getFederateName(); 59 | 60 | /** 61 | * @return The type of the SEE Federate 62 | */ 63 | public String getFederateType(); 64 | 65 | /** 66 | * @return The directory that contains the FOMs module 67 | */ 68 | public File getFomDirectory(); 69 | 70 | /** 71 | * @return true: if the Asynchronous Delivery is enabled 72 | */ 73 | public boolean isAsynchronousDelivery(); 74 | 75 | /** 76 | * @return true: if the Realtime Clock is enabled 77 | */ 78 | public boolean isRealtime(); 79 | 80 | /** 81 | * @return true: if the Time Constrained is enabled 82 | */ 83 | public boolean isTimeConstrained(); 84 | 85 | /** 86 | * @return true: if the Time Regulating is enabled 87 | */ 88 | public boolean isTimeRegulating(); 89 | 90 | /** 91 | * Sets the CRC host to the specified value passed as parameter 92 | * @param crcHost the new value for the CRC host 93 | */ 94 | public void setCrcHost(String crcHost); 95 | 96 | /** 97 | * Sets the CRC port to the specified value passed as parameter 98 | * @param crcHost the new value for the CRC port 99 | */ 100 | public void setCrcPort(int crcHost); 101 | 102 | /** 103 | * Sets the Asynchronous delivery to the specified value passed as parameter 104 | * @param bool the new value for the Asynchronous delivery 105 | */ 106 | public void setAsynchronousDelivery(boolean bool); 107 | 108 | /** 109 | * Sets the federation name to the specified value passed as parameter 110 | * @param federationName the new value for the federation name 111 | */ 112 | public void setFederationName(String federationName); 113 | 114 | /** 115 | * Sets the name of the federate to the specified value passed as parameter 116 | * @param federateName the new name 117 | */ 118 | public void setFederateName(String federateName); 119 | 120 | /** 121 | * Sets the type of the federate to the specified value passed as parameter 122 | * @param federateType the new type 123 | */ 124 | public void setFederateType(String federateType); 125 | 126 | /** 127 | * Sets the FOMs directory to the specified value passed as parameter 128 | * @param dir the FOMs directory 129 | */ 130 | public void setFomDirectory(File dir); 131 | 132 | /** 133 | * Sets the realtime clock to the specified value passed as parameter 134 | * @param bool the new value for the realtime clock 135 | */ 136 | public void setRealtime(boolean bool); 137 | 138 | /** 139 | * Sets the time regulating to the specified value passed as parameter 140 | * @param bool the new value for the time regulating 141 | */ 142 | public void setTimeRegulating(boolean bool); 143 | 144 | /** 145 | * Sets the time constrained to the specified value passed as parameter 146 | * @param bool the new value for the time constrained 147 | */ 148 | public void setTimeConstrained(boolean bool); 149 | 150 | /** 151 | * 152 | * @return The simulation start ephoc 153 | */ 154 | public DateTime getSimulationEphoc(); 155 | 156 | /** 157 | * Sets the simulation start ephoc 158 | * @param simulationEphoc 159 | */ 160 | public void setSimulationEphoc(DateTime simulationEphoc); 161 | 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/dkf/core/DKFFederateInterface.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.core; 23 | 24 | import java.net.MalformedURLException; 25 | import java.util.Observer; 26 | 27 | import dkf.config.Configuration; 28 | import dkf.exception.PublishException; 29 | import dkf.exception.SubscribeException; 30 | import dkf.exception.UnsubscribeException; 31 | import dkf.exception.UpdateException; 32 | import hla.rti1516e.exceptions.AttributeNotDefined; 33 | import hla.rti1516e.exceptions.AttributeNotOwned; 34 | import hla.rti1516e.exceptions.CallNotAllowedFromWithinCallback; 35 | import hla.rti1516e.exceptions.ConnectionFailed; 36 | import hla.rti1516e.exceptions.CouldNotCreateLogicalTimeFactory; 37 | import hla.rti1516e.exceptions.CouldNotOpenFDD; 38 | import hla.rti1516e.exceptions.ErrorReadingFDD; 39 | import hla.rti1516e.exceptions.FederateIsExecutionMember; 40 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 41 | import hla.rti1516e.exceptions.FederateOwnsAttributes; 42 | import hla.rti1516e.exceptions.FederateServiceInvocationsAreBeingReportedViaMOM; 43 | import hla.rti1516e.exceptions.IllegalName; 44 | import hla.rti1516e.exceptions.InconsistentFDD; 45 | import hla.rti1516e.exceptions.InteractionClassNotDefined; 46 | import hla.rti1516e.exceptions.InteractionClassNotPublished; 47 | import hla.rti1516e.exceptions.InteractionParameterNotDefined; 48 | import hla.rti1516e.exceptions.InvalidInteractionClassHandle; 49 | import hla.rti1516e.exceptions.InvalidLocalSettingsDesignator; 50 | import hla.rti1516e.exceptions.InvalidObjectClassHandle; 51 | import hla.rti1516e.exceptions.InvalidResignAction; 52 | import hla.rti1516e.exceptions.NameNotFound; 53 | import hla.rti1516e.exceptions.NotConnected; 54 | import hla.rti1516e.exceptions.ObjectClassNotDefined; 55 | import hla.rti1516e.exceptions.ObjectClassNotPublished; 56 | import hla.rti1516e.exceptions.ObjectInstanceNameInUse; 57 | import hla.rti1516e.exceptions.ObjectInstanceNameNotReserved; 58 | import hla.rti1516e.exceptions.ObjectInstanceNotKnown; 59 | import hla.rti1516e.exceptions.OwnershipAcquisitionPending; 60 | import hla.rti1516e.exceptions.RTIinternalError; 61 | import hla.rti1516e.exceptions.RestoreInProgress; 62 | import hla.rti1516e.exceptions.SaveInProgress; 63 | import hla.rti1516e.exceptions.UnsupportedCallbackModel; 64 | 65 | public interface DKFFederateInterface { 66 | 67 | /** 68 | * Configures the HLA federate on the HLA Federation 69 | * @param config 70 | */ 71 | public void configure(Configuration config); 72 | 73 | /** 74 | * Connects the HLA Federate on the HLA Federation 75 | * 76 | * @param local_settings_designator represents the "local settings designator" string related to the specific 77 | * RTI vendor 78 | *

79 | * For PITCH RTI the local_settings_designator parameter MUST be "crcHost=" + {crc_host} + "\ncrcPort=" + {crc_port}
80 | * e.g. "crcHost=localhost\ncrcPort=8989" 81 | *

82 | * For MAK RTI the local_settings_designator parameter MUST be an empty string
83 | * e.g. "" 84 | * @throws RTIinternalError 85 | * @throws CallNotAllowedFromWithinCallback 86 | * @throws UnsupportedCallbackModel 87 | * @throws InvalidLocalSettingsDesignator 88 | * @throws ConnectionFailed 89 | * @throws NotConnected 90 | * @throws FederateNotExecutionMember 91 | */ 92 | public void connectToRTI(String local_settings_designator) throws RTIinternalError, ConnectionFailed, InvalidLocalSettingsDesignator, UnsupportedCallbackModel, CallNotAllowedFromWithinCallback; 93 | 94 | /** 95 | * Joins the Federate to the specified Federation Execution. 96 | * @throws MalformedURLException 97 | * @throws RTIinternalError 98 | * @throws CallNotAllowedFromWithinCallback 99 | * @throws NotConnected 100 | * @throws RestoreInProgress 101 | * @throws SaveInProgress 102 | * @throws CouldNotOpenFDD 103 | * @throws ErrorReadingFDD 104 | * @throws InconsistentFDD 105 | * @throws CouldNotCreateLogicalTimeFactory 106 | * @throws FederateNotExecutionMember 107 | */ 108 | public void joinFederationExecution() throws CouldNotCreateLogicalTimeFactory, InconsistentFDD, ErrorReadingFDD, CouldNotOpenFDD, SaveInProgress, RestoreInProgress, NotConnected, CallNotAllowedFromWithinCallback, RTIinternalError, MalformedURLException, FederateNotExecutionMember; 109 | 110 | /** 111 | * Disconnects the HLA Federate from the HLA Federation 112 | * @throws RTIinternalError 113 | * @throws CallNotAllowedFromWithinCallback 114 | * @throws NotConnected 115 | * @throws FederateNotExecutionMember 116 | * @throws FederateOwnsAttributes 117 | * @throws OwnershipAcquisitionPending 118 | * @throws InvalidResignAction 119 | * @throws FederateIsExecutionMember 120 | * @throws RestoreInProgress 121 | * @throws SaveInProgress 122 | */ 123 | public void diconnectFromRTI() throws InvalidResignAction, OwnershipAcquisitionPending, FederateOwnsAttributes, FederateNotExecutionMember, NotConnected, CallNotAllowedFromWithinCallback, RTIinternalError, FederateIsExecutionMember, SaveInProgress, RestoreInProgress; 124 | 125 | /** 126 | * Starts Simulation Execution 127 | */ 128 | public void startExecution(); 129 | 130 | /** 131 | * Subscribes the HLA Federate to the Subject, in order to be notified about updates. 132 | * @param observer 133 | */ 134 | public void subscribeSubject(Observer observer); 135 | 136 | /** 137 | * Unsubscribes the HLA Federate from the Subject. 138 | * @param observer 139 | */ 140 | public void unsubscribeSubject(Observer observer); 141 | 142 | /** 143 | * Publishes the Element on HLA/RTI platform 144 | * @param element 145 | * @throws NameNotFound 146 | * @throws FederateNotExecutionMember 147 | * @throws NotConnected 148 | * @throws RTIinternalError 149 | * @throws InvalidObjectClassHandle 150 | * @throws AttributeNotDefined 151 | * @throws ObjectClassNotDefined 152 | * @throws SaveInProgress 153 | * @throws RestoreInProgress 154 | * @throws InstantiationException 155 | * @throws IllegalAccessException 156 | * @throws IllegalName 157 | * @throws ObjectInstanceNameInUse 158 | * @throws ObjectInstanceNameNotReserved 159 | * @throws ObjectClassNotPublished 160 | * @throws AttributeNotOwned 161 | * @throws ObjectInstanceNotKnown 162 | * @throws PublishException 163 | * @throws UpdateException 164 | */ 165 | public void publishElement(Object element) throws NameNotFound, FederateNotExecutionMember, NotConnected, RTIinternalError, InvalidObjectClassHandle, AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, RestoreInProgress, InstantiationException, IllegalAccessException, IllegalName, ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, ObjectClassNotPublished, AttributeNotOwned, ObjectInstanceNotKnown, PublishException, UpdateException; 166 | 167 | /** 168 | * Publishes the Element on HLA/RTI platform with the specified name 169 | * @param element 170 | * @param name 171 | * @throws NameNotFound 172 | * @throws FederateNotExecutionMember 173 | * @throws NotConnected 174 | * @throws RTIinternalError 175 | * @throws InvalidObjectClassHandle 176 | * @throws AttributeNotDefined 177 | * @throws ObjectClassNotDefined 178 | * @throws SaveInProgress 179 | * @throws RestoreInProgress 180 | * @throws PublishException 181 | * @throws InstantiationException 182 | * @throws IllegalAccessException 183 | * @throws IllegalName 184 | * @throws ObjectInstanceNameInUse 185 | * @throws ObjectInstanceNameNotReserved 186 | * @throws ObjectClassNotPublished 187 | * @throws AttributeNotOwned 188 | * @throws ObjectInstanceNotKnown 189 | * @throws UpdateException 190 | */ 191 | public void publishElement(Object element, String name) throws NameNotFound, FederateNotExecutionMember, NotConnected, RTIinternalError, InvalidObjectClassHandle, AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, RestoreInProgress, PublishException, InstantiationException, IllegalAccessException, IllegalName, ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, ObjectClassNotPublished, AttributeNotOwned, ObjectInstanceNotKnown, UpdateException; 192 | 193 | /** 194 | * Publishes the Interaction on HLA/RTI platform 195 | * @param element 196 | * @throws RTIinternalError 197 | * @throws NameNotFound 198 | * @throws FederateNotExecutionMember 199 | * @throws NotConnected 200 | * @throws InvalidInteractionClassHandle 201 | * @throws PublishException 202 | * @throws InteractionParameterNotDefined 203 | * @throws InteractionClassNotPublished 204 | * @throws RestoreInProgress 205 | * @throws SaveInProgress 206 | * @throws InteractionClassNotDefined 207 | */ 208 | public void publishInteraction(Object element) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidInteractionClassHandle, PublishException, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, InteractionClassNotPublished, InteractionParameterNotDefined; 209 | 210 | 211 | /** 212 | * Updates the Element on HLA/RTI platform 213 | * @param element 214 | * @throws FederateNotExecutionMember 215 | * @throws NotConnected 216 | * @throws AttributeNotOwned 217 | * @throws AttributeNotDefined 218 | * @throws ObjectInstanceNotKnown 219 | * @throws SaveInProgress 220 | * @throws RestoreInProgress 221 | * @throws RTIinternalError 222 | * @throws UpdateException 223 | * @throws ObjectClassNotDefined 224 | * @throws ObjectClassNotPublished 225 | * @throws ObjectInstanceNameNotReserved 226 | * @throws ObjectInstanceNameInUse 227 | * @throws IllegalName 228 | */ 229 | public void updateElement(Object element) throws FederateNotExecutionMember, NotConnected, AttributeNotOwned, AttributeNotDefined, ObjectInstanceNotKnown, SaveInProgress, RestoreInProgress, RTIinternalError, UpdateException, IllegalName, ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, ObjectClassNotPublished, ObjectClassNotDefined; 230 | 231 | /** 232 | * Updates the Interaction on HLA/RTI platform 233 | * @param interaction 234 | * @throws InteractionClassNotPublished 235 | * @throws InteractionParameterNotDefined 236 | * @throws InteractionClassNotDefined 237 | * @throws SaveInProgress 238 | * @throws RestoreInProgress 239 | * @throws FederateNotExecutionMember 240 | * @throws NotConnected 241 | * @throws RTIinternalError 242 | * @throws UpdateException 243 | */ 244 | public void updateInteraction(Object interaction) throws InteractionClassNotPublished, InteractionParameterNotDefined, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError, UpdateException; 245 | 246 | /** 247 | * Subscribes an ElementObject 248 | * @param objectClass 249 | * @throws InstantiationException 250 | * @throws IllegalAccessException 251 | * @throws NameNotFound 252 | * @throws FederateNotExecutionMember 253 | * @throws NotConnected 254 | * @throws RTIinternalError 255 | * @throws InvalidObjectClassHandle 256 | * @throws AttributeNotDefined 257 | * @throws ObjectClassNotDefined 258 | * @throws SaveInProgress 259 | * @throws RestoreInProgress 260 | * @throws SubscribeException 261 | */ 262 | @SuppressWarnings("rawtypes") 263 | public void subscribeElement(Class objectClass) throws InstantiationException, IllegalAccessException, NameNotFound, FederateNotExecutionMember, NotConnected, RTIinternalError, InvalidObjectClassHandle, AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, RestoreInProgress, SubscribeException; 264 | 265 | /** 266 | * Subscribes an InteractionObject 267 | * @param interactionClass 268 | * @throws RTIinternalError 269 | * @throws InstantiationException 270 | * @throws IllegalAccessException 271 | * @throws NameNotFound 272 | * @throws FederateNotExecutionMember 273 | * @throws NotConnected 274 | * @throws InvalidInteractionClassHandle 275 | * @throws FederateServiceInvocationsAreBeingReportedViaMOM 276 | * @throws InteractionClassNotDefined 277 | * @throws SaveInProgress 278 | * @throws RestoreInProgress 279 | * @throws SubscribeException 280 | */ 281 | @SuppressWarnings("rawtypes") 282 | public void subscribeInteraction(Class interactionClass) throws RTIinternalError, InstantiationException, IllegalAccessException, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidInteractionClassHandle, FederateServiceInvocationsAreBeingReportedViaMOM, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, SubscribeException; 283 | 284 | /** 285 | * Unsubscribes an ElementObject 286 | * @param objectClass 287 | * @throws ObjectClassNotDefined 288 | * @throws SaveInProgress 289 | * @throws RestoreInProgress 290 | * @throws FederateNotExecutionMember 291 | * @throws NotConnected 292 | * @throws RTIinternalError 293 | * @throws UnsubscribeException 294 | */ 295 | @SuppressWarnings("rawtypes") 296 | public void unsubscribeElement(Class objectClass) throws ObjectClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError, UnsubscribeException; 297 | 298 | /** 299 | * Unsubscribes an InteractionObject 300 | * @param objectClass 301 | * @throws InteractionClassNotDefined 302 | * @throws SaveInProgress 303 | * @throws RestoreInProgress 304 | * @throws FederateNotExecutionMember 305 | * @throws NotConnected 306 | * @throws RTIinternalError 307 | * @throws UnsubscribeException 308 | */ 309 | @SuppressWarnings("rawtypes") 310 | public void unsubscribeInteraction(Class objectClass) throws InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError, UnsubscribeException; 311 | 312 | } 313 | -------------------------------------------------------------------------------- /src/main/java/dkf/core/DKFRTIAmbassador.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.core; 23 | 24 | import org.apache.logging.log4j.LogManager; 25 | import org.apache.logging.log4j.Logger; 26 | 27 | import hla.rti1516e.RTIambassador; 28 | import hla.rti1516e.RtiFactory; 29 | import hla.rti1516e.RtiFactoryFactory; 30 | import hla.rti1516e.exceptions.RTIinternalError; 31 | 32 | public final class DKFRTIAmbassador { 33 | 34 | private static final Logger logger = LogManager.getLogger(DKFRTIAmbassador.class); 35 | 36 | private static RTIambassador rtiambassador = null; 37 | private static RtiFactory rtifactory = null; 38 | 39 | private DKFRTIAmbassador() throws RTIinternalError { 40 | rtifactory = RtiFactoryFactory.getRtiFactory(); 41 | rtiambassador = rtifactory.getRtiAmbassador(); 42 | 43 | // Get information on the HLA/RTI 44 | logger.info("Vendor HLA/RTI: name:"+rtifactory.rtiName()+", rtiVersion: "+rtifactory.rtiVersion()+ 45 | ", hlaVersion: "+rtiambassador.getHLAversion()); 46 | 47 | } 48 | 49 | public static synchronized RTIambassador getInstance() throws RTIinternalError { 50 | if(rtiambassador == null) 51 | new DKFRTIAmbassador(); 52 | return rtiambassador; 53 | } 54 | 55 | public String rtiName() { 56 | return rtifactory.rtiName(); 57 | } 58 | 59 | public String rtiVersion() { 60 | return rtifactory.rtiVersion(); 61 | } 62 | 63 | public String hlaVersion() { 64 | return rtiambassador.getHLAversion(); 65 | } 66 | 67 | @Override 68 | protected Object clone() throws CloneNotSupportedException { 69 | throw new CloneNotSupportedException("Clone not supported!"); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/dkf/core/ExecutionTask.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.core; 23 | 24 | import java.util.concurrent.atomic.AtomicBoolean; 25 | 26 | import dkf.time.TimeInterface; 27 | import hla.rti1516e.exceptions.RTIexception; 28 | 29 | public class ExecutionTask implements Runnable { 30 | 31 | private DKFAbstractFederate federate = null; 32 | private DKFAbstractFederateAmbassador fedamb = null; 33 | private DKFHLAModule hlamodule = null; 34 | 35 | private AtomicBoolean CONTINUE_EXECUTION = null; 36 | 37 | private long exec_loop_counter = 0; 38 | 39 | // Simulation time parameters. 40 | private TimeInterface time = null; 41 | 42 | protected ExecutionTask(DKFHLAModule hlamodule, TimeInterface time) { 43 | this.hlamodule = hlamodule; 44 | this.federate = hlamodule.getFederate(); 45 | this.fedamb = hlamodule.getAmbassador(); 46 | this.time = time; 47 | this.CONTINUE_EXECUTION = new AtomicBoolean(true); 48 | } 49 | 50 | @Override 51 | public void run() { 52 | 53 | while(CONTINUE_EXECUTION.get()){ 54 | time.setFederateExecutionTimeCycle((exec_loop_counter * time.getTimeClycle())); 55 | 56 | // check realtime execution 57 | if (federate.getConfig().isRealtime()) { 58 | try { 59 | Thread.sleep(1000); 60 | } catch(Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | // Wait for the time advance grant. 65 | while(!fedamb.isAdvancing()){ 66 | try { 67 | Thread.sleep(10); 68 | } catch( Exception e ) { 69 | e.printStackTrace(); 70 | } 71 | } 72 | 73 | federate.doAction(); 74 | 75 | // Request a time advance by the logical time interval. 76 | try { 77 | hlamodule.makeTARequest(); 78 | } catch (RTIexception e) { 79 | e.printStackTrace(); 80 | } 81 | exec_loop_counter++; 82 | } 83 | 84 | } 85 | 86 | protected void shutdown() { 87 | this.CONTINUE_EXECUTION.set(false); 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/dkf/core/observer/Subject.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.core.observer; 23 | 24 | import java.util.Observable; 25 | 26 | public class Subject extends Observable { 27 | 28 | public Subject() { 29 | 30 | } 31 | 32 | public void notifyUpdate(Object obj){ 33 | this.setChanged(); 34 | this.notifyObservers(obj); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/ConfigurationSyntaxException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | /** 25 | * 26 | * @author SMASH-Lab University of Calabria 27 | * @version 0.1 28 | * 29 | */ 30 | public class ConfigurationSyntaxException extends RuntimeException { 31 | 32 | private static final long serialVersionUID = 1L; 33 | 34 | public ConfigurationSyntaxException(String message){ 35 | super(message); 36 | } 37 | 38 | public ConfigurationSyntaxException(String message, Throwable cause){ 39 | super(message, cause); 40 | } 41 | 42 | public ConfigurationSyntaxException(Throwable cause){ 43 | super(cause); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/FirewallExeption.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class FirewallExeption extends RuntimeException { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public FirewallExeption(String message) { 29 | super(message); 30 | } 31 | 32 | public FirewallExeption(String message, Throwable cause) { 33 | super(message, cause); 34 | } 35 | 36 | public FirewallExeption(Throwable cause) { 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/PublishException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class PublishException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public PublishException(String message){ 29 | super(message); 30 | } 31 | 32 | public PublishException(String message, Throwable cause){ 33 | super(message, cause); 34 | } 35 | 36 | public PublishException(Throwable cause){ 37 | super(cause); 38 | } 39 | 40 | 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/RegisterElementNameException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class RegisterElementNameException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public RegisterElementNameException(String message){ 29 | super(message); 30 | } 31 | 32 | public RegisterElementNameException(String message, Throwable cause){ 33 | super(message, cause); 34 | } 35 | 36 | public RegisterElementNameException(Throwable cause){ 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/SubscribeException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class SubscribeException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public SubscribeException(String message){ 29 | super(message); 30 | } 31 | 32 | public SubscribeException(String message, Throwable cause){ 33 | super(message, cause); 34 | } 35 | 36 | public SubscribeException(Throwable cause){ 37 | super(cause); 38 | } 39 | } -------------------------------------------------------------------------------- /src/main/java/dkf/exception/TimeRepresentationException.java: -------------------------------------------------------------------------------- 1 | package dkf.exception; 2 | 3 | public class TimeRepresentationException extends Exception { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public TimeRepresentationException(String message){ 8 | super(message); 9 | } 10 | 11 | public TimeRepresentationException(String message, Throwable cause){ 12 | super(message, cause); 13 | } 14 | 15 | public TimeRepresentationException(Throwable cause){ 16 | super(cause); 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/UnsubscribeException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class UnsubscribeException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public UnsubscribeException(String message){ 29 | super(message); 30 | } 31 | 32 | public UnsubscribeException(String message, Throwable cause){ 33 | super(message, cause); 34 | } 35 | 36 | public UnsubscribeException(Throwable cause){ 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/dkf/exception/UpdateException.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.exception; 23 | 24 | public class UpdateException extends Exception { 25 | 26 | private static final long serialVersionUID = 1L; 27 | 28 | public UpdateException(String message){ 29 | super(message); 30 | } 31 | 32 | public UpdateException(String message, Throwable cause){ 33 | super(message, cause); 34 | } 35 | 36 | public UpdateException(Throwable cause){ 37 | super(cause); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/Order.java: -------------------------------------------------------------------------------- 1 | package dkf.model; 2 | 3 | public enum Order { 4 | 5 | TIMESTAMP, RECEIVE, UNKNOWN 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/Sharing.java: -------------------------------------------------------------------------------- 1 | package dkf.model; 2 | 3 | public enum Sharing { 4 | 5 | PUBLISH, SUBSCRIBE, PUBLISH_SUBSCRIBE,UNKNOWN 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/Transportation.java: -------------------------------------------------------------------------------- 1 | package dkf.model; 2 | 3 | public enum Transportation { 4 | 5 | HLA_BEST_EFFORT, HLA_REILABLE, UNKNOWN 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/InteractionClassEntity.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.interaction; 23 | 24 | import dkf.model.object.AbstractClassEntity; 25 | 26 | public class InteractionClassEntity extends AbstractClassEntity { 27 | 28 | public InteractionClassEntity(String instanceName, Object element) { 29 | super(element); 30 | this.instanceName = instanceName; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/InteractionClassModel.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.interaction; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.Map.Entry; 27 | 28 | import hla.rti1516e.InteractionClassHandle; 29 | import hla.rti1516e.ParameterHandle; 30 | import hla.rti1516e.ParameterHandleValueMap; 31 | import hla.rti1516e.RTIambassador; 32 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 33 | import hla.rti1516e.exceptions.FederateServiceInvocationsAreBeingReportedViaMOM; 34 | import hla.rti1516e.exceptions.InteractionClassNotDefined; 35 | import hla.rti1516e.exceptions.InteractionClassNotPublished; 36 | import hla.rti1516e.exceptions.InteractionParameterNotDefined; 37 | import hla.rti1516e.exceptions.InvalidInteractionClassHandle; 38 | import hla.rti1516e.exceptions.NameNotFound; 39 | import hla.rti1516e.exceptions.NotConnected; 40 | import hla.rti1516e.exceptions.RTIinternalError; 41 | import hla.rti1516e.exceptions.RestoreInProgress; 42 | import hla.rti1516e.exceptions.SaveInProgress; 43 | 44 | import org.apache.logging.log4j.LogManager; 45 | import org.apache.logging.log4j.Logger; 46 | 47 | import dkf.core.DKFRTIAmbassador; 48 | import dkf.model.object.ObjectModelStatus; 49 | 50 | public class InteractionClassModel { 51 | 52 | private static Logger logger = LogManager.getLogger(InteractionClassModel.class); 53 | 54 | private ObjectModelStatus status = ObjectModelStatus.UNKNOWN; 55 | private InteractionClassHandle interactionClassHandle = null; 56 | 57 | private Map mapFieldNameParameterHandle = null; 58 | 59 | private RTIambassador rti_ambassador = null; 60 | 61 | private InteractionClassEntity interactionEntity = null; 62 | private InteractionClassModelParser parser = null; 63 | 64 | private ParameterHandleValueMap parameter_values = null; 65 | 66 | @SuppressWarnings({ "rawtypes", "unchecked" }) 67 | public InteractionClassModel(Class interactionClass) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidInteractionClassHandle { 68 | this.rti_ambassador = DKFRTIAmbassador.getInstance(); 69 | this.parser = new InteractionClassModelParser(interactionClass); 70 | initialize(); 71 | } 72 | 73 | private void initialize() throws NameNotFound, FederateNotExecutionMember, NotConnected, RTIinternalError, InvalidInteractionClassHandle { 74 | 75 | if(status == ObjectModelStatus.UNKNOWN){ 76 | 77 | // Get a handle to the class. 78 | this.interactionClassHandle = rti_ambassador.getInteractionClassHandle(parser.getClassHandleName()); 79 | this.mapFieldNameParameterHandle = new HashMap(); 80 | 81 | // Get handles to all the attributes. 82 | ParameterHandle tmp = null; 83 | for(String str : parser.getMapFieldCoder().keySet()){ 84 | tmp = rti_ambassador.getParameterHandle(interactionClassHandle, str); 85 | mapFieldNameParameterHandle.put(str, tmp); 86 | } 87 | 88 | this.parameter_values = rti_ambassador.getParameterHandleValueMapFactory().create(mapFieldNameParameterHandle.size()); 89 | status = ObjectModelStatus.INITIALIZED; 90 | 91 | } 92 | } 93 | 94 | public void subscribe() throws FederateServiceInvocationsAreBeingReportedViaMOM, InteractionClassNotDefined, SaveInProgress, 95 | RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 96 | 97 | if(status == ObjectModelStatus.INITIALIZED){ 98 | 99 | rti_ambassador.subscribeInteractionClass(this.interactionClassHandle); 100 | status = ObjectModelStatus.SUBSCRIBED; 101 | } 102 | else{ 103 | logger.error("You can't subscribe an uninitialized interaction!"); 104 | throw new IllegalStateException("You can't subscribe an uninitialized interaction!"); 105 | } 106 | } 107 | 108 | public void unsubscribe() throws InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 109 | if(status == ObjectModelStatus.SUBSCRIBED){ 110 | 111 | rti_ambassador.unsubscribeInteractionClass(this.interactionClassHandle); 112 | status = ObjectModelStatus.UNKNOWN; 113 | } 114 | else{ 115 | logger.error("You can't unsubscribe "+this.interactionClassHandle+" because it is not subscribed"); 116 | throw new IllegalStateException("You can't unsubscribe "+this.interactionClassHandle+" because it is not subscribed"); 117 | } 118 | } 119 | 120 | public void publish() throws InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 121 | 122 | if(status == ObjectModelStatus.INITIALIZED){ 123 | rti_ambassador.publishInteractionClass(interactionClassHandle); 124 | status = ObjectModelStatus.PUBLISHED; 125 | } 126 | else{ 127 | logger.error("You can't publish an uninitialized or an already published InteractionClassModel!"); 128 | throw new IllegalStateException("You can't publish an uninitialized or an already published InteractionClassModel!"); 129 | } 130 | } 131 | 132 | public void unpublish() throws InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 133 | 134 | if(status == ObjectModelStatus.PUBLISHED){ 135 | rti_ambassador.unpublishInteractionClass(interactionClassHandle); 136 | status = ObjectModelStatus.UNKNOWN; 137 | } 138 | else{ 139 | logger.error("You can't unpublish an uninitialized or an unpublished InteractionClassModel!"); 140 | throw new IllegalStateException("You can't unpublish an uninitialized or an unpublished InteractionClassModel!"); 141 | } 142 | } 143 | 144 | public void updatePublishedInteraction() throws InteractionClassNotPublished, InteractionParameterNotDefined, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 145 | 146 | 147 | if(status == ObjectModelStatus.PUBLISHED) { 148 | Map ris = parser.encode(interactionEntity.getElement()); 149 | for(Entry entry : mapFieldNameParameterHandle.entrySet()) 150 | parameter_values.put(entry.getValue(), ris.get(entry.getKey())); 151 | 152 | rti_ambassador.sendInteraction(interactionClassHandle, parameter_values, null); 153 | } 154 | else{ 155 | logger.error("Can't update the ' "+interactionEntity+" ', because it is not published!"); 156 | throw new IllegalStateException("Can't update the ' "+interactionEntity+" ', because it is not published!"); 157 | } 158 | 159 | } 160 | 161 | public void updateSubscribedInteraction(ParameterHandleValueMap arg1) { 162 | 163 | if(status == ObjectModelStatus.SUBSCRIBED) 164 | parser.decode(interactionEntity.getElement(), mapFieldNameParameterHandle, arg1); 165 | else{ 166 | logger.error("Can't update the ' "+interactionEntity+" ', because it is not subscribed !"); 167 | throw new IllegalStateException("Can't update the ' "+interactionEntity+" ', because it is not subscribed !"); 168 | } 169 | } 170 | 171 | public InteractionClassHandle getInteractionClassHandle() { 172 | return this.interactionClassHandle; 173 | } 174 | 175 | public void addEntity(Object interaction){ 176 | this.interactionEntity = new InteractionClassEntity(interaction.getClass().getName()+interaction.hashCode(), interaction); 177 | } 178 | 179 | public InteractionClassEntity getEntity() { 180 | return this.interactionEntity; 181 | } 182 | 183 | } 184 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/InteractionClassModelManager.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.interaction; 23 | 24 | import hla.rti1516e.InteractionClassHandle; 25 | import hla.rti1516e.ParameterHandleValueMap; 26 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 27 | import hla.rti1516e.exceptions.FederateServiceInvocationsAreBeingReportedViaMOM; 28 | import hla.rti1516e.exceptions.InteractionClassNotDefined; 29 | import hla.rti1516e.exceptions.InteractionClassNotPublished; 30 | import hla.rti1516e.exceptions.InteractionParameterNotDefined; 31 | import hla.rti1516e.exceptions.InvalidInteractionClassHandle; 32 | import hla.rti1516e.exceptions.NameNotFound; 33 | import hla.rti1516e.exceptions.NotConnected; 34 | import hla.rti1516e.exceptions.RTIinternalError; 35 | import hla.rti1516e.exceptions.RestoreInProgress; 36 | import hla.rti1516e.exceptions.SaveInProgress; 37 | 38 | import java.util.HashMap; 39 | import java.util.Map; 40 | 41 | import org.apache.commons.collections4.BidiMap; 42 | import org.apache.commons.collections4.bidimap.DualHashBidiMap; 43 | 44 | import dkf.model.interaction.annotations.InteractionClass; 45 | 46 | @SuppressWarnings("rawtypes") 47 | public class InteractionClassModelManager { 48 | 49 | //maps for published element 50 | private Map published = null; 51 | private Map mapInstanceNameInteractionClassEntity = null; 52 | 53 | //maps for subscribed element 54 | private Map subscribed = null; 55 | private BidiMap mapInteractionClassHandleClass = null; 56 | 57 | 58 | public InteractionClassModelManager() { 59 | this.published = new HashMap(); 60 | this.mapInstanceNameInteractionClassEntity = new HashMap(); 61 | 62 | this.subscribed = new HashMap(); 63 | this.mapInteractionClassHandleClass = new DualHashBidiMap(); 64 | } 65 | 66 | public Map getPublishedMap() { 67 | return this.published; 68 | } 69 | 70 | public Map getSubscribedMap() { 71 | return this.subscribed; 72 | } 73 | 74 | public void publish(Object interaction) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidInteractionClassHandle, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, InteractionClassNotPublished, InteractionParameterNotDefined { 75 | 76 | InteractionClassModel icm = published.get(interaction.getClass().getAnnotation(InteractionClass.class).name()); 77 | 78 | if(icm == null){ 79 | icm = new InteractionClassModel(interaction.getClass()); 80 | icm.addEntity(interaction); 81 | icm.publish(); 82 | this.published.put(interaction.getClass().getAnnotation(InteractionClass.class).name(), icm); 83 | this.mapInstanceNameInteractionClassEntity.put(icm.getEntity().getInstanceName(), icm.getEntity()); 84 | } 85 | } 86 | 87 | @SuppressWarnings("unchecked") 88 | public void subscribe(Class interactionClass) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidInteractionClassHandle, FederateServiceInvocationsAreBeingReportedViaMOM, InteractionClassNotDefined, SaveInProgress, RestoreInProgress, InstantiationException, IllegalAccessException { 89 | 90 | InteractionClassModel icm = new InteractionClassModel(interactionClass); 91 | icm.addEntity(interactionClass.newInstance()); 92 | icm.subscribe(); 93 | this.subscribed.put(((Class)interactionClass).getAnnotation(InteractionClass.class).name(), icm); 94 | this.mapInteractionClassHandleClass.put(icm.getInteractionClassHandle(), interactionClass); 95 | } 96 | 97 | @SuppressWarnings("unchecked") 98 | public void unsubscribe(Class interactionClass) throws InteractionClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 99 | this.subscribed.remove(((Class)interactionClass).getAnnotation(InteractionClass.class).name()).unsubscribe(); 100 | this.mapInteractionClassHandleClass.inverseBidiMap().remove(interactionClass); 101 | } 102 | 103 | public boolean interactionInstanceHandleIsSubscribed(InteractionClassHandle arg0) { 104 | return this.mapInteractionClassHandleClass.get(arg0) != null; 105 | } 106 | 107 | @SuppressWarnings("unchecked") 108 | public Object receiveInteraction(InteractionClassHandle arg0, ParameterHandleValueMap arg1) { 109 | 110 | InteractionClassModel icm = subscribed.get(((Class)mapInteractionClassHandleClass.get(arg0)).getAnnotation(InteractionClass.class).name()); 111 | if(icm != null){ 112 | icm.updateSubscribedInteraction(arg1); 113 | return icm.getEntity().getElement(); 114 | } 115 | return null; 116 | } 117 | 118 | } 119 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/InteractionClassModelParser.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | 23 | package dkf.model.interaction; 24 | 25 | import hla.rti1516e.ParameterHandle; 26 | import hla.rti1516e.ParameterHandleValueMap; 27 | import hla.rti1516e.encoding.DecoderException; 28 | 29 | import java.beans.IntrospectionException; 30 | import java.beans.PropertyDescriptor; 31 | import java.lang.reflect.Field; 32 | import java.lang.reflect.InvocationTargetException; 33 | import java.util.HashMap; 34 | import java.util.Map; 35 | 36 | import org.apache.logging.log4j.LogManager; 37 | import org.apache.logging.log4j.Logger; 38 | 39 | import dkf.coder.Coder; 40 | import dkf.model.interaction.annotations.InteractionClass; 41 | import dkf.model.interaction.annotations.Parameter; 42 | import dkf.model.parser.AbstractObjectModelParser; 43 | 44 | 45 | 46 | public class InteractionClassModelParser extends AbstractObjectModelParser { 47 | 48 | private static final Logger logger = LogManager.getLogger(InteractionClassModelParser.class); 49 | 50 | protected Class interactionClassModel = null; 51 | 52 | 53 | public InteractionClassModelParser(Class interactionClassModel) { 54 | super(); 55 | this.interactionClassModel = interactionClassModel; 56 | retrieveClassModelStructure(); 57 | } 58 | 59 | @SuppressWarnings({ "rawtypes" }) 60 | protected void retrieveClassModelStructure() { 61 | 62 | this.classHandleName = interactionClassModel.getAnnotation(InteractionClass.class).name(); 63 | fields = interactionClassModel.getDeclaredFields(); 64 | Map tmpMapCoder = new HashMap(); 65 | Coder coderTmp = null; 66 | 67 | try { 68 | for(Field f : fields){ 69 | if(f.isAnnotationPresent(Parameter.class)){ 70 | coderTmp = tmpMapCoder.get(f.getAnnotation(Parameter.class).coder()); 71 | if(coderTmp == null){ 72 | coderTmp = f.getAnnotation(Parameter.class).coder().newInstance(); 73 | tmpMapCoder.put(f.getAnnotation(Parameter.class).coder(), coderTmp); 74 | } 75 | matchingObjectCoderIsValid(f, coderTmp); 76 | mapFieldCoder.put(f.getAnnotation(Parameter.class).name(), coderTmp); 77 | } 78 | } 79 | } catch (InstantiationException | IllegalAccessException e) { 80 | logger.error("Error in retreving the annotations of the fields"); 81 | e.printStackTrace(); 82 | } finally { 83 | tmpMapCoder = null; 84 | coderTmp = null; 85 | } 86 | 87 | } 88 | 89 | @SuppressWarnings("unchecked") 90 | public Map encode(Object interaction) { 91 | 92 | if(interaction == null){ 93 | logger.error("The argument is null"); 94 | throw new IllegalArgumentException("The parameter value cannot be null"); 95 | } 96 | 97 | logger.debug("Encoding: "+interaction.toString()); 98 | 99 | PropertyDescriptor pd = null; 100 | Object fieldValue = null; 101 | Coder fieldCoder = null; 102 | 103 | try { 104 | for(Field f : fields) 105 | if(f.isAnnotationPresent(Parameter.class)){ 106 | pd = new PropertyDescriptor(f.getName(), interaction.getClass()); 107 | fieldValue = pd.getReadMethod().invoke(interaction); 108 | if(fieldValue != null){ 109 | fieldCoder = mapFieldCoder.get(f.getAnnotation(Parameter.class).name()); 110 | logger.trace(interaction.getClass().getName()+ " Update [ Field "+f.getName()+", value: "+fieldValue+" ]"); 111 | encoderMap.put(f.getAnnotation(Parameter.class).name(), fieldCoder.encode(fieldValue)); 112 | } 113 | else{ 114 | logger.error("The parameter ' "+f.getName()+" ' is null"); 115 | throw new NullPointerException("The parameter ' "+f.getName()+" ' is null"); 116 | } 117 | } 118 | } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 119 | logger.error("Error in retreving the value of the fields"); 120 | e.printStackTrace(); 121 | } 122 | 123 | return encoderMap; 124 | } 125 | 126 | @SuppressWarnings("unchecked") 127 | public void decode(Object interaction, Map mapFieldNameParameterHandle, ParameterHandleValueMap arg1) { 128 | 129 | if(interaction == null || arg1 == null || mapFieldNameParameterHandle == null){ 130 | logger.error("Some arguments are null"); 131 | throw new IllegalArgumentException("Some arguments are null"); 132 | } 133 | 134 | PropertyDescriptor pd = null; 135 | Coder fieldCoder = null; 136 | byte[] currValue = null; 137 | try { 138 | for(Field f : fields) 139 | if(f.isAnnotationPresent(Parameter.class)){ 140 | pd = new PropertyDescriptor(f.getName(), interaction.getClass()); 141 | fieldCoder = mapFieldCoder.get(f.getAnnotation(Parameter.class).name()); 142 | currValue = arg1.get(mapFieldNameParameterHandle.get(f.getAnnotation(Parameter.class).name())); 143 | pd.getWriteMethod().invoke(interaction, fieldCoder.decode(currValue)); 144 | logger.debug("Parameter decoded [ Field "+f.getName()+", value: "+fieldCoder.decode(currValue)+" ]"); 145 | } 146 | } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | DecoderException e) { 147 | e.printStackTrace(); 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/annotations/InteractionClass.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.interaction.annotations; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | import dkf.model.Order; 30 | import dkf.model.Sharing; 31 | import dkf.model.Transportation; 32 | 33 | @Retention(RetentionPolicy.RUNTIME) 34 | @Target(ElementType.TYPE) 35 | public @interface InteractionClass { 36 | 37 | /** 38 | * The name of the InteractionClass defined in the FOM file 39 | * @return The name of the InteractionClass 40 | */ 41 | public String name(); 42 | 43 | /** 44 | * The transportation type of the InteractionClass defined in the FOM file 45 | * @return The transportation type of the InteractionClass 46 | */ 47 | public Transportation transportation() default Transportation.UNKNOWN; 48 | 49 | /** 50 | * The Sharing type of the InteractionClass defined in the FOM file 51 | * @return The type of the Sharing 52 | */ 53 | public Sharing sharing() default Sharing.UNKNOWN; 54 | 55 | /** 56 | * The Order type of the InteractionClass defined in the FOM file 57 | * @return The type of the Order 58 | */ 59 | public Order order() default Order.UNKNOWN; 60 | 61 | /** 62 | * The semantic of the InteractionClass defined in the FOM file 63 | * @return The semantic of the InteractionClass 64 | */ 65 | public String semantic() default ""; 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/interaction/annotations/Parameter.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.interaction.annotations; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | import dkf.coder.Coder; 30 | 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.FIELD) 33 | public @interface Parameter { 34 | 35 | /** 36 | * the name of the parameter defined in the FOM file 37 | * @return the filed's name 38 | */ 39 | public String name(); 40 | 41 | /** 42 | * the coder of the paramteter defined in the FOM file 43 | * @return the filed's coder 44 | */ 45 | @SuppressWarnings("rawtypes") 46 | public Class coder(); 47 | 48 | /** 49 | * The semantic of the parameter defined in the FOM file 50 | * @return The semantic of the parameter 51 | */ 52 | public String semantic() default ""; 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/AbstractClassEntity.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | public abstract class AbstractClassEntity { 25 | 26 | protected String instanceName = null; 27 | protected Object element = null; 28 | 29 | public AbstractClassEntity(Object element) { 30 | this.element = element; 31 | } 32 | 33 | public String getInstanceName() { 34 | return this.instanceName; 35 | } 36 | 37 | public Object getElement() { 38 | return element; 39 | } 40 | 41 | public void setElement(Object element) { 42 | this.element = element; 43 | 44 | } 45 | 46 | public void setInstanceName(String instanceName) { 47 | this.instanceName = instanceName; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/NameReservationStatus.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | public enum NameReservationStatus { 25 | 26 | UNKNOWN, SUCCEDED, FAILED 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectClassEntity.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | import hla.rti1516e.ObjectInstanceHandle; 25 | 26 | public class ObjectClassEntity extends AbstractClassEntity { 27 | 28 | private ObjectInstanceHandle instanceHandle = null; 29 | private NameReservationStatus status = NameReservationStatus.UNKNOWN; 30 | 31 | 32 | public ObjectClassEntity(String instanceName, Object element) { 33 | super(element); 34 | this.instanceName = instanceName; 35 | } 36 | 37 | 38 | public ObjectClassEntity(ObjectInstanceHandle instanceHandle, Object element) { 39 | super(element); 40 | this.instanceHandle = instanceHandle; 41 | } 42 | 43 | 44 | public ObjectInstanceHandle getObjectInstanceHandle() { 45 | return this.instanceHandle; 46 | } 47 | 48 | public void setObjectInstanceHandle(ObjectInstanceHandle instanceHandle) { 49 | this.instanceHandle = instanceHandle; 50 | } 51 | 52 | public void setStatus(NameReservationStatus status){ 53 | this.status = status; 54 | } 55 | 56 | public NameReservationStatus getStatus(){ 57 | return this.status; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectClassHandleEntity.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | import hla.rti1516e.ObjectClassHandle; 25 | 26 | public class ObjectClassHandleEntity { 27 | 28 | private ObjectClassHandle objectClassHandle = null; 29 | 30 | private String instanceName = null; 31 | 32 | public ObjectClassHandleEntity(ObjectClassHandle objectClassHandle, String instanceName) { 33 | this.objectClassHandle = objectClassHandle; 34 | this.instanceName = instanceName; 35 | } 36 | 37 | public ObjectClassHandle getObjectClassHandle() { 38 | return objectClassHandle; 39 | } 40 | 41 | public void setObjectClassHandle(ObjectClassHandle objectClassHandle) { 42 | this.objectClassHandle = objectClassHandle; 43 | } 44 | 45 | public String getInstanceName() { 46 | return instanceName; 47 | } 48 | 49 | public void setInstanceName(String instanceName) { 50 | this.instanceName = instanceName; 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | final int prime = 31; 56 | int result = 1; 57 | result = prime 58 | * result 59 | + ((objectClassHandle == null) ? 0 : objectClassHandle 60 | .hashCode()); 61 | return result; 62 | } 63 | 64 | @Override 65 | public boolean equals(Object obj) { 66 | if (this == obj) 67 | return true; 68 | if (obj == null) 69 | return false; 70 | if (getClass() != obj.getClass()) 71 | return false; 72 | ObjectClassHandleEntity other = (ObjectClassHandleEntity) obj; 73 | if (objectClassHandle == null) { 74 | if (other.objectClassHandle != null) 75 | return false; 76 | } else if (!objectClassHandle.equals(other.objectClassHandle)) 77 | return false; 78 | return true; 79 | } 80 | 81 | @Override 82 | public String toString() { 83 | return "ObjectClassHandleEntity [objectClassHandle=" 84 | + objectClassHandle + ", instanceName=" + instanceName + "]"; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectClassModel.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | import java.util.Map.Entry; 27 | 28 | import hla.rti1516e.AttributeHandle; 29 | import hla.rti1516e.AttributeHandleSet; 30 | import hla.rti1516e.AttributeHandleValueMap; 31 | import hla.rti1516e.ObjectClassHandle; 32 | import hla.rti1516e.ObjectInstanceHandle; 33 | import hla.rti1516e.RTIambassador; 34 | import hla.rti1516e.exceptions.AttributeNotDefined; 35 | import hla.rti1516e.exceptions.AttributeNotOwned; 36 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 37 | import hla.rti1516e.exceptions.IllegalName; 38 | import hla.rti1516e.exceptions.InvalidObjectClassHandle; 39 | import hla.rti1516e.exceptions.NameNotFound; 40 | import hla.rti1516e.exceptions.NotConnected; 41 | import hla.rti1516e.exceptions.ObjectClassNotDefined; 42 | import hla.rti1516e.exceptions.ObjectClassNotPublished; 43 | import hla.rti1516e.exceptions.ObjectInstanceNameInUse; 44 | import hla.rti1516e.exceptions.ObjectInstanceNameNotReserved; 45 | import hla.rti1516e.exceptions.ObjectInstanceNotKnown; 46 | import hla.rti1516e.exceptions.OwnershipAcquisitionPending; 47 | import hla.rti1516e.exceptions.RTIinternalError; 48 | import hla.rti1516e.exceptions.RestoreInProgress; 49 | import hla.rti1516e.exceptions.SaveInProgress; 50 | 51 | import org.apache.logging.log4j.LogManager; 52 | import org.apache.logging.log4j.Logger; 53 | 54 | import dkf.core.DKFRTIAmbassador; 55 | import dkf.exception.UpdateException; 56 | 57 | @SuppressWarnings("rawtypes") 58 | public class ObjectClassModel { 59 | 60 | private static Logger logger = LogManager.getLogger(ObjectClassModel.class); 61 | 62 | private ObjectModelStatus status = ObjectModelStatus.UNKNOWN; 63 | private ObjectClassHandle objectClassHandle = null; 64 | 65 | private Map mapFieldNameAttributeHandle = null; 66 | 67 | private RTIambassador rti_ambassador = null; 68 | 69 | private Map entityMap = null; 70 | private Map mapObjectInstanceHandleObjectClassEntity = null; 71 | 72 | private ObjectClassModelParser parser = null; 73 | 74 | private AttributeHandleValueMap attribute_values = null; 75 | 76 | @SuppressWarnings("unchecked") 77 | public ObjectClassModel(Class objectClass) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidObjectClassHandle, InstantiationException, IllegalAccessException { 78 | this.rti_ambassador = DKFRTIAmbassador.getInstance(); 79 | this.parser = new ObjectClassModelParser(objectClass); 80 | 81 | this.entityMap = new HashMap(); 82 | this.mapObjectInstanceHandleObjectClassEntity = new HashMap(); 83 | initialize(); 84 | } 85 | 86 | private void initialize() throws NameNotFound, FederateNotExecutionMember, NotConnected, RTIinternalError, InvalidObjectClassHandle, 87 | InstantiationException, IllegalAccessException { 88 | 89 | if(status == ObjectModelStatus.UNKNOWN){ 90 | 91 | // Get a handle to the class. 92 | this.objectClassHandle = rti_ambassador.getObjectClassHandle(parser.getClassHandleName()); 93 | this.mapFieldNameAttributeHandle = new HashMap(); 94 | 95 | // Get handles to all the attributes. 96 | AttributeHandle tmp = null; 97 | for(String str : parser.getMapFieldCoder().keySet()){ 98 | tmp = rti_ambassador.getAttributeHandle(objectClassHandle, str); 99 | mapFieldNameAttributeHandle.put(str, tmp); 100 | } 101 | 102 | this.attribute_values = rti_ambassador.getAttributeHandleValueMapFactory().create(mapFieldNameAttributeHandle.size()); 103 | 104 | status = ObjectModelStatus.INITIALIZED; 105 | } 106 | 107 | }// initialize 108 | 109 | public void subscribe() throws AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 110 | 111 | if(status == ObjectModelStatus.INITIALIZED){ 112 | 113 | AttributeHandleSet attributeSet = rti_ambassador.getAttributeHandleSetFactory().create(); 114 | for(AttributeHandle val : mapFieldNameAttributeHandle.values()) 115 | attributeSet.add(val); 116 | 117 | rti_ambassador.subscribeObjectClassAttributes(objectClassHandle, attributeSet); 118 | status = ObjectModelStatus.SUBSCRIBED; 119 | 120 | } 121 | else{ 122 | logger.error("You can't subscribe an uninitialized element!"); 123 | throw new IllegalStateException("You can't subscribe an uninitialized element!"); 124 | } 125 | 126 | }//subscribe 127 | 128 | public void unsubscribe() throws ObjectClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, NotConnected, RTIinternalError { 129 | 130 | if(status == ObjectModelStatus.SUBSCRIBED){ 131 | rti_ambassador.unsubscribeObjectClass(this.objectClassHandle); 132 | status = ObjectModelStatus.UNKNOWN; 133 | } 134 | else{ 135 | logger.error("You can't unsubscribe "+this.objectClassHandle+" because it is not subscribed"); 136 | throw new IllegalStateException("You can't unsubscribe "+this.objectClassHandle+" because it is not subscribed"); 137 | } 138 | 139 | }//subscribe 140 | 141 | public void publish() throws FederateNotExecutionMember, NotConnected, AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, 142 | RestoreInProgress, RTIinternalError{ 143 | 144 | if(status == ObjectModelStatus.INITIALIZED){ 145 | 146 | AttributeHandleSet attributeSet = rti_ambassador.getAttributeHandleSetFactory().create(); 147 | 148 | for(AttributeHandle element: mapFieldNameAttributeHandle.values()) 149 | attributeSet.add(element); 150 | 151 | rti_ambassador.publishObjectClassAttributes(objectClassHandle, attributeSet); 152 | 153 | status = ObjectModelStatus.PUBLISHED; 154 | } 155 | else{ 156 | logger.error("You can't publish an uninitialized or an already published ObjectClassModel!"); 157 | throw new IllegalStateException("You can't publish an uninitialized or an already published ObjectClassModel!"); 158 | } 159 | 160 | } 161 | 162 | public void unpublish() throws FederateNotExecutionMember, NotConnected, OwnershipAcquisitionPending, AttributeNotDefined, 163 | ObjectClassNotDefined, SaveInProgress, RestoreInProgress, RTIinternalError { 164 | 165 | if(status == ObjectModelStatus.PUBLISHED){ 166 | 167 | AttributeHandleSet attributeSet = rti_ambassador.getAttributeHandleSetFactory().create(); 168 | attributeSet.addAll(mapFieldNameAttributeHandle.values()); 169 | rti_ambassador.unpublishObjectClassAttributes(objectClassHandle, attributeSet); 170 | 171 | status = ObjectModelStatus.UNKNOWN; 172 | } 173 | else{ 174 | logger.error("You can't unpublish an uninitialized or an unpublished ObjectClassModel!"); 175 | throw new IllegalStateException("You can't unpublish an uninitialized or an unpublished ObjectClassModel!"); 176 | } 177 | 178 | } 179 | 180 | public void addEntity(ObjectClassEntity element){ 181 | entityMap.put(element.getElement(), element); 182 | mapObjectInstanceHandleObjectClassEntity.put(element.getObjectInstanceHandle(), element); 183 | } 184 | 185 | public void updatePublishedObject(ObjectClassEntity element) throws UpdateException, IllegalName, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, 186 | NotConnected, RTIinternalError, ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, ObjectClassNotPublished, 187 | ObjectClassNotDefined, AttributeNotOwned, AttributeNotDefined, ObjectInstanceNotKnown { 188 | 189 | ObjectClassEntity entity = entityMap.get(element.getElement()); 190 | 191 | if(entity == null){ 192 | logger.error("Can't find the ' "+element+" ' !"); 193 | throw new IllegalStateException("Can't find the ' "+element+" ' !"); 194 | } 195 | 196 | if(status == ObjectModelStatus.PUBLISHED) { 197 | if(entity.getObjectInstanceHandle() == null) 198 | entity.setObjectInstanceHandle(reserveObjectInstanceName(entity)); 199 | 200 | Map ris = parser.encode(element.getElement()); 201 | for(Entry entry : mapFieldNameAttributeHandle.entrySet()) 202 | attribute_values.put(entry.getValue(), ris.get(entry.getKey())); 203 | 204 | rti_ambassador.updateAttributeValues(entity.getObjectInstanceHandle(), attribute_values , null); 205 | } 206 | else{ 207 | logger.error("Can't update the Object ' "+element+" ', because it is not published!"); 208 | throw new IllegalStateException("Can't update the Object ' "+element+" ', because it is not published!"); 209 | } 210 | 211 | } 212 | 213 | 214 | public void updateSubscribedObject(ObjectClassEntity element, AttributeHandleValueMap arg1){ 215 | 216 | ObjectClassEntity entity = entityMap.get(element.getElement()); 217 | 218 | if(entity == null){ 219 | logger.error("Can't find the ' "+element+" ' !"); 220 | throw new IllegalStateException("Can't find the ' "+element+" ' !"); 221 | } 222 | 223 | if(status == ObjectModelStatus.SUBSCRIBED) 224 | parser.decode(element.getElement(), mapFieldNameAttributeHandle, arg1); 225 | 226 | else{ 227 | logger.error("Can't update the ' "+element+" ', because it is not subscribed !"); 228 | throw new IllegalStateException("Can't update the ' "+element+" ', because it is not subscribed !"); 229 | } 230 | } 231 | 232 | private ObjectInstanceHandle reserveObjectInstanceName(ObjectClassEntity entity) throws IllegalName, SaveInProgress, RestoreInProgress, 233 | FederateNotExecutionMember, NotConnected, RTIinternalError, 234 | ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, 235 | ObjectClassNotPublished, ObjectClassNotDefined { 236 | 237 | // Reserve the name. 238 | rti_ambassador.reserveObjectInstanceName(entity.getInstanceName()); 239 | 240 | // Need to wait here until name reservation callback is recieved. 241 | while (entity.getStatus() == NameReservationStatus.UNKNOWN) 242 | Thread.yield(); 243 | 244 | if (entity.getStatus() == NameReservationStatus.FAILED) { 245 | logger.error("Name Resevation Failed [name= "+entity+" ]"); 246 | throw new IllegalName("Name Resevation Failed [name= "+entity+" ]"); 247 | } 248 | 249 | // If name is reserved then register the instance. 250 | if (entity.getStatus() == NameReservationStatus.SUCCEDED) 251 | return rti_ambassador.registerObjectInstance(objectClassHandle,entity.getInstanceName()); 252 | 253 | return null; 254 | } 255 | 256 | public Map getEntities() { 257 | return this.entityMap; 258 | } 259 | 260 | public ObjectClassHandle getObjectClassHandle() { 261 | return this.objectClassHandle; 262 | } 263 | 264 | public ObjectClassEntity getObjectClassEntity(ObjectInstanceHandle instanceHandle) { 265 | return mapObjectInstanceHandleObjectClassEntity.get(instanceHandle); 266 | } 267 | 268 | } 269 | 270 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectClassModelManager.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | import hla.rti1516e.AttributeHandleValueMap; 25 | import hla.rti1516e.ObjectClassHandle; 26 | import hla.rti1516e.ObjectInstanceHandle; 27 | import hla.rti1516e.exceptions.AttributeNotDefined; 28 | import hla.rti1516e.exceptions.AttributeNotOwned; 29 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 30 | import hla.rti1516e.exceptions.IllegalName; 31 | import hla.rti1516e.exceptions.InvalidObjectClassHandle; 32 | import hla.rti1516e.exceptions.NameNotFound; 33 | import hla.rti1516e.exceptions.NotConnected; 34 | import hla.rti1516e.exceptions.ObjectClassNotDefined; 35 | import hla.rti1516e.exceptions.ObjectClassNotPublished; 36 | import hla.rti1516e.exceptions.ObjectInstanceNameInUse; 37 | import hla.rti1516e.exceptions.ObjectInstanceNameNotReserved; 38 | import hla.rti1516e.exceptions.ObjectInstanceNotKnown; 39 | import hla.rti1516e.exceptions.RTIinternalError; 40 | import hla.rti1516e.exceptions.RestoreInProgress; 41 | import hla.rti1516e.exceptions.SaveInProgress; 42 | 43 | import java.util.HashMap; 44 | import java.util.Map; 45 | import java.util.Map.Entry; 46 | 47 | import org.apache.commons.collections4.BidiMap; 48 | import org.apache.commons.collections4.bidimap.DualHashBidiMap; 49 | 50 | import dkf.model.object.annotations.ObjectClass; 51 | import dkf.exception.UpdateException; 52 | 53 | @SuppressWarnings("rawtypes") 54 | public class ObjectClassModelManager { 55 | 56 | //maps for published element 57 | private Map published = null; 58 | private BidiMap mapInstanceNameObjectClassEntity = null; 59 | 60 | //maps for subscribed element 61 | private Map subscribed = null; 62 | private Map mapHandleClassObjectClass = null; 63 | private Map objectInstanceHandleObjectClassHandle = null; 64 | 65 | public ObjectClassModelManager() { 66 | this.published = new HashMap(); 67 | this.mapInstanceNameObjectClassEntity = new DualHashBidiMap(); 68 | 69 | this.subscribed = new HashMap(); 70 | this.mapHandleClassObjectClass = new HashMap(); 71 | this.objectInstanceHandleObjectClassHandle = new HashMap(); 72 | } 73 | 74 | public Map getPublishedMap() { 75 | return this.published; 76 | } 77 | 78 | public Map getSubscribedMap() { 79 | return this.subscribed; 80 | } 81 | 82 | @SuppressWarnings("unchecked") 83 | public void subscribe(Class objectClass) throws RTIinternalError, InstantiationException, IllegalAccessException, NameNotFound, 84 | FederateNotExecutionMember, NotConnected, InvalidObjectClassHandle, AttributeNotDefined, 85 | ObjectClassNotDefined, SaveInProgress, RestoreInProgress { 86 | 87 | 88 | ObjectClassModel ocm = new ObjectClassModel(objectClass); 89 | ocm.subscribe(); 90 | 91 | this.subscribed.put(((Class)objectClass).getAnnotation(ObjectClass.class).name(), ocm); 92 | this.mapHandleClassObjectClass.put(ocm.getObjectClassHandle(), objectClass); 93 | } 94 | 95 | @SuppressWarnings("unchecked") 96 | public void unsubscribe(Class objectClass) throws ObjectClassNotDefined, SaveInProgress, RestoreInProgress, FederateNotExecutionMember, 97 | NotConnected, RTIinternalError { 98 | 99 | ObjectClassModel ocm = subscribed.get(((Class)objectClass).getAnnotation(ObjectClass.class).name()); 100 | ocm.unsubscribe(); 101 | 102 | this.mapHandleClassObjectClass.remove(ocm.getObjectClassHandle()); 103 | 104 | for(Entry entry : ocm.getEntities().entrySet()) 105 | this.objectInstanceHandleObjectClassHandle.remove(entry.getValue().getObjectInstanceHandle()); 106 | 107 | this.subscribed.remove(ocm); 108 | 109 | } 110 | 111 | public void publish(Object element, String name) throws RTIinternalError, NameNotFound, FederateNotExecutionMember, NotConnected, InvalidObjectClassHandle, InstantiationException, IllegalAccessException, AttributeNotDefined, ObjectClassNotDefined, SaveInProgress, RestoreInProgress, IllegalName, ObjectInstanceNameInUse, ObjectInstanceNameNotReserved, ObjectClassNotPublished, AttributeNotOwned, ObjectInstanceNotKnown, UpdateException { 112 | 113 | ObjectClassModel ocm = published.get(element.getClass().getAnnotation(ObjectClass.class).name()); 114 | 115 | if(ocm == null){ 116 | ocm = new ObjectClassModel(element.getClass()); 117 | ocm.publish(); 118 | this.published.put(element.getClass().getAnnotation(ObjectClass.class).name(), ocm); 119 | } 120 | 121 | ObjectClassEntity entity = null; 122 | if(name != null) 123 | entity = new ObjectClassEntity(name, element); 124 | else 125 | entity = new ObjectClassEntity(element.getClass().getName()+element.hashCode(), element); 126 | 127 | ocm.addEntity(entity); 128 | this.mapInstanceNameObjectClassEntity.put(entity.getInstanceName(), entity); 129 | 130 | } 131 | 132 | public ObjectClassEntity getObjectClassEntityByIstanceName(String instance_name) { 133 | return this.mapInstanceNameObjectClassEntity.get(instance_name); 134 | } 135 | 136 | public void addDiscoverObjectInstance(ObjectInstanceHandle instanceHandle, ObjectClassHandle objectClassHandle, String instanceName) { 137 | this.objectInstanceHandleObjectClassHandle.put(instanceHandle, new ObjectClassHandleEntity(objectClassHandle, instanceName)); 138 | } 139 | 140 | @SuppressWarnings("unchecked") 141 | public Object reflectAttributeValues(ObjectInstanceHandle instanceHandle, AttributeHandleValueMap attributes) throws InstantiationException, IllegalAccessException { 142 | 143 | ObjectClassHandleEntity oche = objectInstanceHandleObjectClassHandle.get(instanceHandle); 144 | ObjectClassHandle och = oche.getObjectClassHandle(); 145 | ObjectClassModel ocm = subscribed.get(((Class)mapHandleClassObjectClass.get(och)).getAnnotation(ObjectClass.class).name()); 146 | 147 | ObjectClassEntity entity = ocm.getObjectClassEntity(instanceHandle); 148 | if(entity == null){ 149 | Object element = mapHandleClassObjectClass.get(och).newInstance(); 150 | entity = new ObjectClassEntity(instanceHandle, element); 151 | entity.setInstanceName(oche.getInstanceName()); 152 | entity.setStatus(NameReservationStatus.SUCCEDED); 153 | ocm.addEntity(entity); 154 | } 155 | ocm.updateSubscribedObject(entity, attributes); 156 | return entity.getElement(); 157 | } 158 | 159 | public boolean objectClassIsSubscribed(ObjectClassHandle arg1) { 160 | return this.mapHandleClassObjectClass.get(arg1) != null; 161 | } 162 | 163 | public boolean objectInstanceHandleIsSubscribed(ObjectInstanceHandle arg0) { 164 | return this.objectInstanceHandleObjectClassHandle.get(arg0) != null; 165 | } 166 | 167 | } 168 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectClassModelParser.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | import hla.rti1516e.AttributeHandle; 25 | import hla.rti1516e.AttributeHandleValueMap; 26 | import hla.rti1516e.encoding.DecoderException; 27 | 28 | import java.beans.IntrospectionException; 29 | import java.beans.PropertyDescriptor; 30 | import java.lang.reflect.Field; 31 | import java.lang.reflect.InvocationTargetException; 32 | import java.util.HashMap; 33 | import java.util.Map; 34 | 35 | import org.apache.logging.log4j.LogManager; 36 | import org.apache.logging.log4j.Logger; 37 | 38 | import dkf.coder.Coder; 39 | import dkf.model.object.annotations.Attribute; 40 | import dkf.model.object.annotations.ObjectClass; 41 | import dkf.model.parser.AbstractObjectModelParser; 42 | 43 | 44 | @SuppressWarnings("rawtypes") 45 | public class ObjectClassModelParser extends AbstractObjectModelParser { 46 | 47 | private static final Logger logger = LogManager.getLogger(ObjectClassModelParser.class); 48 | 49 | protected Class objectClassModel = null; 50 | 51 | public ObjectClassModelParser(Class objectClassModel) { 52 | super(); 53 | this.objectClassModel = objectClassModel; 54 | retrieveClassModelStructure(); 55 | } 56 | 57 | protected void retrieveClassModelStructure() { 58 | 59 | this.classHandleName = objectClassModel.getAnnotation(ObjectClass.class).name(); 60 | 61 | fields = objectClassModel.getDeclaredFields(); 62 | Map tmpMapCoder = new HashMap(); 63 | Coder coderTmp = null; 64 | 65 | try { 66 | for(Field f : fields){ 67 | if(f.isAnnotationPresent(Attribute.class)){ 68 | coderTmp = tmpMapCoder.get(f.getAnnotation(Attribute.class).coder()); 69 | if(coderTmp == null){ 70 | coderTmp = f.getAnnotation(Attribute.class).coder().newInstance(); 71 | tmpMapCoder.put(f.getAnnotation(Attribute.class).coder(), coderTmp); 72 | } 73 | matchingObjectCoderIsValid(f, coderTmp); 74 | mapFieldCoder.put(f.getAnnotation(Attribute.class).name(), coderTmp); 75 | } 76 | } 77 | } catch (InstantiationException | IllegalAccessException e) { 78 | logger.error("Error in retreving the annotations of the fields"); 79 | e.printStackTrace(); 80 | } finally { 81 | tmpMapCoder = null; 82 | coderTmp = null; 83 | } 84 | 85 | } 86 | 87 | @SuppressWarnings("unchecked") 88 | public Map encode(Object element) { 89 | 90 | if(element == null){ 91 | logger.error("The argument is null"); 92 | throw new IllegalArgumentException("The argument is null"); 93 | } 94 | 95 | logger.debug("Encoding: "+element.toString()); 96 | 97 | PropertyDescriptor pd = null; 98 | Object fieldValue = null; 99 | Coder fieldCoder = null; 100 | 101 | try { 102 | for(Field f : fields) 103 | if(f.isAnnotationPresent(Attribute.class)){ 104 | pd = new PropertyDescriptor(f.getName(), element.getClass()); 105 | fieldValue = pd.getReadMethod().invoke(element); 106 | if(fieldValue != null){ 107 | fieldCoder = mapFieldCoder.get(f.getAnnotation(Attribute.class).name()); 108 | logger.trace(element.getClass().getName()+ " Update [ Field "+f.getName()+", value: "+fieldValue+" ]"); 109 | encoderMap.put(f.getAnnotation(Attribute.class).name(), fieldCoder.encode(fieldValue)); 110 | } 111 | else{ 112 | logger.error("The field ' "+f.getName()+" ' is null"); 113 | throw new NullPointerException("The field ' "+f.getName()+" ' is null"); 114 | } 115 | } 116 | } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 117 | logger.error("Error in retreving the value of the fields"); 118 | e.printStackTrace(); 119 | } 120 | 121 | return encoderMap; 122 | } 123 | 124 | @SuppressWarnings("unchecked") 125 | public void decode(Object element, Map mapFieldNameAttributeHandle, AttributeHandleValueMap arg1) { 126 | 127 | if(element == null || arg1 == null || mapFieldNameAttributeHandle == null){ 128 | logger.error("Some arguments are null"); 129 | throw new IllegalArgumentException("Some arguments are null"); 130 | } 131 | 132 | PropertyDescriptor pd = null; 133 | Coder fieldCoder = null; 134 | byte[] currValue = null; 135 | try { 136 | for(Field f : fields) 137 | if(f.isAnnotationPresent(Attribute.class)){ 138 | pd = new PropertyDescriptor(f.getName(), element.getClass()); 139 | fieldCoder = this.mapFieldCoder.get(f.getAnnotation(Attribute.class).name()); 140 | currValue = arg1.get(mapFieldNameAttributeHandle.get(f.getAnnotation(Attribute.class).name())); 141 | pd.getWriteMethod().invoke(element, fieldCoder.decode(currValue)); 142 | logger.debug("Attribute decoded [ Field "+f.getName()+", value: "+fieldCoder.decode(currValue)+" ]"); 143 | } 144 | } catch (IntrospectionException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | DecoderException e) { 145 | e.printStackTrace(); 146 | } 147 | 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/ObjectModelStatus.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object; 23 | 24 | public enum ObjectModelStatus { 25 | 26 | UNKNOWN, PUBLISHED, INITIALIZED, SUBSCRIBED 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/annotations/Attribute.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object.annotations; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | import dkf.coder.Coder; 30 | import dkf.model.Order; 31 | import dkf.model.Sharing; 32 | import dkf.model.Transportation; 33 | 34 | @Retention(RetentionPolicy.RUNTIME) 35 | @Target(ElementType.FIELD) 36 | public @interface Attribute { 37 | 38 | /** 39 | * the name of the attribute defined in the FOM file 40 | * @return the filed's name 41 | */ 42 | public String name(); 43 | 44 | /** 45 | * the coder of the attribute defined in the FOM file 46 | * @return the filed's coder 47 | */ 48 | @SuppressWarnings("rawtypes") 49 | public Class coder(); 50 | 51 | /** 52 | * The Sharing type of the attribute defined in the FOM file 53 | * @return The type of the Sharing 54 | */ 55 | public Sharing sharing() default Sharing.UNKNOWN; 56 | 57 | /** 58 | * The Ownership type of the attribute defined in the FOM file 59 | * @return The type of ownership 60 | */ 61 | public Ownership Ownership() default Ownership.UNKNOWN; 62 | 63 | /** 64 | * The UpdateType of the attribute defined in the FOM file 65 | * @return The type of Update 66 | */ 67 | public UpdateType updateType() default UpdateType.UNKNOWN; 68 | 69 | /** 70 | * The update condition of the attribute 71 | * @return The update condition 72 | */ 73 | public String updateCondition() default ""; 74 | 75 | /** 76 | * The Order type of the attribute defined in the FOM file 77 | * @return The type of the Sharing 78 | */ 79 | public Order order() default Order.UNKNOWN; 80 | 81 | /** 82 | * The transportation type of the attribute defined in the FOM file 83 | * @return The transportation type of the attribute 84 | */ 85 | public Transportation transportation() default Transportation.UNKNOWN; 86 | 87 | /** 88 | * The semantic of the parameter defined in the FOM file 89 | * @return The semantic of the attribute 90 | */ 91 | public String semantic() default ""; 92 | } 93 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/annotations/ObjectClass.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.object.annotations; 23 | 24 | import java.lang.annotation.ElementType; 25 | import java.lang.annotation.Retention; 26 | import java.lang.annotation.RetentionPolicy; 27 | import java.lang.annotation.Target; 28 | 29 | import dkf.model.Sharing; 30 | 31 | @Retention(RetentionPolicy.RUNTIME) 32 | @Target(ElementType.TYPE) 33 | public @interface ObjectClass { 34 | 35 | /** 36 | * The name of the ObjectClass defined in the FOM file 37 | * @return The name of the ObjectClass 38 | */ 39 | public String name(); 40 | 41 | /** 42 | * The Sharing type of the ObjectClass defined in the FOM file 43 | * @return The type of the Sharing 44 | */ 45 | public Sharing sharing() default Sharing.UNKNOWN; 46 | 47 | /** 48 | * The semantic of the ObjectClass defined in the FOM file 49 | * @return The semantic of the ObjectClass 50 | */ 51 | public String semantic() default ""; 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/annotations/Ownership.java: -------------------------------------------------------------------------------- 1 | package dkf.model.object.annotations; 2 | 3 | public enum Ownership { 4 | 5 | DIVEST, ACQUIRE, DIVEST_ACQUIRE, UNKNOWN 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/object/annotations/UpdateType.java: -------------------------------------------------------------------------------- 1 | package dkf.model.object.annotations; 2 | 3 | public enum UpdateType { 4 | 5 | NOT_APPLICABLE, STATIC, CONDITIONAL, PERIODIC, UNKNOWN 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/dkf/model/parser/AbstractObjectModelParser.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.model.parser; 23 | 24 | import java.lang.reflect.Field; 25 | import java.util.HashMap; 26 | import java.util.Map; 27 | 28 | import org.apache.logging.log4j.LogManager; 29 | import org.apache.logging.log4j.Logger; 30 | 31 | import dkf.coder.Coder; 32 | 33 | @SuppressWarnings("rawtypes") 34 | public abstract class AbstractObjectModelParser { 35 | 36 | private static final Logger logger = LogManager.getLogger(AbstractObjectModelParser.class); 37 | 38 | protected String classHandleName = null; 39 | protected Map mapFieldCoder = null; 40 | protected Field[] fields = null; 41 | 42 | 43 | protected Map encoderMap = null; 44 | 45 | 46 | public AbstractObjectModelParser () { 47 | this.mapFieldCoder = new HashMap(); 48 | this.encoderMap = new HashMap(); 49 | } 50 | 51 | protected abstract void retrieveClassModelStructure(); 52 | 53 | 54 | protected void matchingObjectCoderIsValid(Field f, Coder coderTmp) { 55 | if(!coderTmp.getAllowedType().equals(f.getType())){ 56 | logger.error("The Coder: "+coderTmp.getAllowedType()+" is not valid for the Object: "+f.getType()); 57 | throw new RuntimeException("The Coder: "+coderTmp.getAllowedType()+" is not valid for the Object: "+f.getType()); 58 | } 59 | } 60 | 61 | public String getClassHandleName() { 62 | return this.classHandleName; 63 | } 64 | 65 | public Map getMapFieldCoder() { 66 | return this.mapFieldCoder; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/Float64Time.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | import hla.rti1516e.LogicalTime; 4 | import hla.rti1516e.LogicalTimeInterval; 5 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 6 | import hla.rti1516e.exceptions.IllegalTimeArithmetic; 7 | import hla.rti1516e.exceptions.InvalidLogicalTimeInterval; 8 | import hla.rti1516e.exceptions.NotConnected; 9 | import hla.rti1516e.exceptions.RTIinternalError; 10 | import hla.rti1516e.time.HLAfloat64Interval; 11 | import hla.rti1516e.time.HLAfloat64Time; 12 | import hla.rti1516e.time.HLAfloat64TimeFactory; 13 | 14 | import org.apache.logging.log4j.LogManager; 15 | import org.apache.logging.log4j.Logger; 16 | import org.joda.time.DateTime; 17 | 18 | import dkf.core.DKFRTIAmbassador; 19 | import dkf.utility.JulianDateType; 20 | 21 | @SuppressWarnings("rawtypes") 22 | public class Float64Time extends TimeAbstract { 23 | 24 | private double LOOKAHEAD_FLOAT64TIME_STEP = 1000000; 25 | 26 | private static final Logger logger = LogManager.getLogger(Float64Time.class); 27 | 28 | public Float64Time(DateTime simulationEphoc) throws FederateNotExecutionMember, NotConnected, RTIinternalError { 29 | super(simulationEphoc); 30 | this.time_factory = (HLAfloat64TimeFactory) DKFRTIAmbassador.getInstance().getTimeFactory(); 31 | } 32 | 33 | @Override 34 | @SuppressWarnings("unchecked") 35 | public HLAfloat64Time nextTimeStep() throws IllegalTimeArithmetic, InvalidLogicalTimeInterval { 36 | super.setupNextTimeStep(); 37 | return (HLAfloat64Time) logical_time; 38 | } 39 | 40 | @Override 41 | public void setLogicalTime(LogicalTime logicaltime) { 42 | if(!(logicaltime instanceof HLAfloat64Time)){ 43 | logger.error("LogicalTime is not valid. It must be a HLAfloat64Time"); 44 | throw new IllegalArgumentException("LogicalTime is not valid. It must be a HLAfloat64Time"); 45 | } 46 | else 47 | super.setupLogicalTime(logicaltime); 48 | 49 | } 50 | 51 | @Override 52 | @SuppressWarnings("unchecked") 53 | public HLAfloat64Time getLogicalTime() { 54 | return (HLAfloat64Time)logical_time; 55 | } 56 | 57 | @Override 58 | public void initializeLookaheadInterval() { 59 | this.lookaheadInterval = ((HLAfloat64TimeFactory)time_factory).makeInterval(LOOKAHEAD_FLOAT64TIME_STEP); 60 | } 61 | 62 | @Override 63 | public void setLookaheadInterval(LogicalTimeInterval logicaltimeinterval) { 64 | if(!(logicaltimeinterval instanceof HLAfloat64Interval)){ 65 | logger.error("LogicalTimeInterval is not valid. It must be a HLAfloat64Interval"); 66 | throw new IllegalArgumentException("LogicalTimeInterval is not valid. It must be a HLAfloat64Interval"); 67 | } 68 | else 69 | super.setupLookaheadInterval(logicaltimeinterval); 70 | 71 | } 72 | 73 | @Override 74 | @SuppressWarnings("unchecked") 75 | public HLAfloat64Interval getLookaheadInterval() { 76 | return (HLAfloat64Interval)lookaheadInterval; 77 | } 78 | 79 | @Override 80 | public double getFederationExecutionTimeCycle() { 81 | return ((HLAfloat64Time)logical_time).getValue(); 82 | } 83 | 84 | @Override 85 | public DateTime getFederationExecutionTime() { 86 | return super.calculateFederationExecutionTime(((HLAfloat64Time)logical_time).getValue()); 87 | } 88 | 89 | @Override 90 | public double getFederationExecutionTimeInJulianDate(JulianDateType juliantype) { 91 | return super.calculateFederationExecutionTimeInJulianDate(((HLAfloat64Time)logical_time).getValue(), juliantype); 92 | } 93 | 94 | @Override 95 | public double getTimeClycle() { 96 | return LOOKAHEAD_FLOAT64TIME_STEP; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/Integer64Time.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | import hla.rti1516e.LogicalTime; 4 | import hla.rti1516e.LogicalTimeInterval; 5 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 6 | import hla.rti1516e.exceptions.IllegalTimeArithmetic; 7 | import hla.rti1516e.exceptions.InvalidLogicalTimeInterval; 8 | import hla.rti1516e.exceptions.NotConnected; 9 | import hla.rti1516e.exceptions.RTIinternalError; 10 | import hla.rti1516e.time.HLAinteger64Interval; 11 | import hla.rti1516e.time.HLAinteger64Time; 12 | import hla.rti1516e.time.HLAinteger64TimeFactory; 13 | 14 | import org.apache.logging.log4j.LogManager; 15 | import org.apache.logging.log4j.Logger; 16 | import org.joda.time.DateTime; 17 | 18 | import dkf.core.DKFRTIAmbassador; 19 | import dkf.utility.JulianDateType; 20 | 21 | @SuppressWarnings("rawtypes") 22 | public class Integer64Time extends TimeAbstract { 23 | 24 | private final long LOOKAHEAD_INTEGER64TIME_STEP = 1000000; 25 | 26 | private static final Logger logger = LogManager.getLogger(Integer64Time.class); 27 | 28 | public Integer64Time(DateTime simulationEphoc) throws FederateNotExecutionMember, NotConnected, RTIinternalError { 29 | super(simulationEphoc); 30 | this.time_factory = (HLAinteger64TimeFactory) DKFRTIAmbassador.getInstance().getTimeFactory(); 31 | } 32 | 33 | @Override 34 | @SuppressWarnings("unchecked") 35 | public HLAinteger64Time nextTimeStep() throws IllegalTimeArithmetic, InvalidLogicalTimeInterval { 36 | super.setupNextTimeStep(); 37 | return (HLAinteger64Time) logical_time; 38 | } 39 | 40 | @Override 41 | public void setLogicalTime(LogicalTime logicaltime) { 42 | if(!(logicaltime instanceof HLAinteger64Time)){ 43 | logger.error("LogicalTime is not valid. It must be a HLAinteger64Time"); 44 | throw new IllegalArgumentException("LogicalTime is not valid. It must be a HLAinteger64Time"); 45 | } 46 | else 47 | super.setupLogicalTime(logicaltime); 48 | 49 | } 50 | 51 | @Override 52 | @SuppressWarnings("unchecked") 53 | public HLAinteger64Time getLogicalTime() { 54 | return (HLAinteger64Time)logical_time; 55 | } 56 | 57 | @Override 58 | public void initializeLookaheadInterval() { 59 | this.lookaheadInterval = ((HLAinteger64TimeFactory)time_factory).makeInterval(LOOKAHEAD_INTEGER64TIME_STEP); 60 | } 61 | 62 | @Override 63 | public void setLookaheadInterval(LogicalTimeInterval logicaltimeinterval) { 64 | if(!(logicaltimeinterval instanceof HLAinteger64Interval)){ 65 | logger.error("LogicalTimeInterval is not valid. It must be a HLAinteger64Interval"); 66 | throw new IllegalArgumentException("LogicalTimeInterval is not valid. It must be a HLAinteger64Interval"); 67 | } 68 | else 69 | super.setupLookaheadInterval(logicaltimeinterval); 70 | 71 | } 72 | 73 | @Override 74 | @SuppressWarnings("unchecked") 75 | public HLAinteger64Interval getLookaheadInterval() { 76 | return (HLAinteger64Interval)lookaheadInterval; 77 | } 78 | 79 | @Override 80 | public double getFederationExecutionTimeCycle() { 81 | return ((HLAinteger64Time)logical_time).getValue(); 82 | } 83 | 84 | @Override 85 | public DateTime getFederationExecutionTime() { 86 | return super.calculateFederationExecutionTime(((HLAinteger64Time)logical_time).getValue()); 87 | } 88 | 89 | @Override 90 | public double getFederationExecutionTimeInJulianDate(JulianDateType juliantype) { 91 | return super.calculateFederationExecutionTimeInJulianDate(((HLAinteger64Time)logical_time).getValue(), juliantype); 92 | } 93 | 94 | @Override 95 | public double getTimeClycle() { 96 | return this.LOOKAHEAD_INTEGER64TIME_STEP; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/TimeAbstract.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | 4 | import jodd.datetime.JDateTime; 5 | import hla.rti1516e.LogicalTime; 6 | import hla.rti1516e.LogicalTimeFactory; 7 | import hla.rti1516e.LogicalTimeInterval; 8 | import hla.rti1516e.exceptions.IllegalTimeArithmetic; 9 | import hla.rti1516e.exceptions.InvalidLogicalTimeInterval; 10 | 11 | import org.apache.logging.log4j.LogManager; 12 | import org.apache.logging.log4j.Logger; 13 | import org.joda.time.DateTime; 14 | 15 | import dkf.utility.JulianDateType; 16 | import dkf.utility.TimeUnit; 17 | import dkf.utility.TimeUtility; 18 | 19 | @SuppressWarnings("rawtypes") 20 | public abstract class TimeAbstract implements TimeInterface { 21 | 22 | private static final Logger logger = LogManager.getLogger(TimeAbstract.class); 23 | 24 | protected DateTime simulationEphoc = null; 25 | 26 | protected LogicalTimeFactory time_factory = null; 27 | protected LogicalTime federateLogicalTime = null; 28 | protected LogicalTime logical_time = null; 29 | protected LogicalTimeInterval lookaheadInterval = null; 30 | 31 | protected JDateTime julianDate = null; 32 | protected double executionCounter; 33 | 34 | 35 | protected TimeAbstract(DateTime simulationEphoc) { 36 | this.simulationEphoc = new DateTime(simulationEphoc); 37 | } 38 | 39 | @Override 40 | public void setFederateTime(LogicalTime time) { 41 | this.federateLogicalTime = time; 42 | 43 | } 44 | 45 | @SuppressWarnings("unchecked") 46 | public void setupNextTimeStep() throws IllegalTimeArithmetic, InvalidLogicalTimeInterval { 47 | this.logical_time = this.logical_time.add(lookaheadInterval); 48 | } 49 | 50 | public void setupLogicalTime(LogicalTime logicaltime) { 51 | this.logical_time = logicaltime; 52 | } 53 | 54 | public void setupLookaheadInterval(LogicalTimeInterval logicaltimeinterval) { 55 | this.lookaheadInterval = logicaltimeinterval; 56 | } 57 | 58 | @Override 59 | public double getFederateExecutionTimeCycle() { 60 | return executionCounter; 61 | } 62 | 63 | @Override 64 | public void setFederateExecutionTimeCycle(double executiontime) { 65 | this.executionCounter = executiontime; 66 | 67 | } 68 | 69 | protected DateTime calculateFederationExecutionTime(double value) { 70 | return simulationEphoc.plusMillis((int) Math.round((TimeUtility.convert(value, TimeUnit.MICROSECONDS, TimeUnit.MILLISECONDS)))); 71 | 72 | } 73 | 74 | protected double calculateFederationExecutionTimeInJulianDate(double value, JulianDateType juliantype) { 75 | if(julianDate == null) 76 | julianDate = new JDateTime(); 77 | 78 | DateTime currTime = simulationEphoc.plusMillis((int) Math.round((TimeUtility.convert(value, TimeUnit.MICROSECONDS, TimeUnit.MILLISECONDS)))); 79 | julianDate.set(currTime.getYear(), currTime.getMonthOfYear(), currTime.getDayOfMonth(), currTime.getHourOfDay(), currTime.getMinuteOfHour(), currTime.getSecondOfMinute(), currTime.getMillisOfSecond()); 80 | 81 | switch (juliantype) { 82 | case DATE: 83 | return julianDate.getJulianDateDouble(); 84 | case MODIFIED: 85 | return julianDate.getJulianDate().getModifiedJulianDate().doubleValue(); 86 | case REDUCED: 87 | return julianDate.getJulianDate().getReducedJulianDate().doubleValue(); 88 | case TRUNCATED: 89 | return julianDate.getJulianDate().getTruncatedJulianDate().doubleValue(); 90 | default: 91 | logger.error("Illegal JulianDateType: "+juliantype); 92 | throw new IllegalArgumentException("Illegal JulianDateType: "+juliantype); 93 | } 94 | } 95 | 96 | 97 | public void initializeLogicalTime() { 98 | this.logical_time = time_factory.makeInitial(); 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/TimeFactory.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 4 | import hla.rti1516e.exceptions.NotConnected; 5 | import hla.rti1516e.exceptions.RTIinternalError; 6 | 7 | import java.io.IOException; 8 | 9 | import org.apache.logging.log4j.LogManager; 10 | import org.apache.logging.log4j.Logger; 11 | import org.jdom2.JDOMException; 12 | 13 | import dkf.config.Configuration; 14 | import dkf.exception.TimeRepresentationException; 15 | import dkf.utility.access.FOMDataInspectoryFactory; 16 | 17 | 18 | public class TimeFactory implements TimeFactoryInterface { 19 | 20 | Logger logger = LogManager.getLogger(TimeFactory.class); 21 | 22 | private FOMDataInspectoryFactory inspector = null; 23 | private Configuration config = null; 24 | 25 | public TimeFactory(Configuration config) { 26 | this.config = config; 27 | } 28 | 29 | @Override 30 | public TimeInterface createTimeInstance() throws FederateNotExecutionMember, NotConnected, RTIinternalError, JDOMException, IOException, TimeRepresentationException { 31 | inspector = new FOMDataInspectoryFactory(config.getFomDirectory()); 32 | 33 | switch (inspector.getTimestamp()) { 34 | case HLAinteger64Time: 35 | return new Integer64Time(config.getSimulationEphoc()); 36 | case HLAfloat64Time: 37 | return new Float64Time(config.getSimulationEphoc()); 38 | default: 39 | logger.error("Invalid Time type"); 40 | return null; 41 | } 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/TimeFactoryInterface.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | import java.io.IOException; 4 | 5 | import org.jdom2.JDOMException; 6 | 7 | import dkf.exception.TimeRepresentationException; 8 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 9 | import hla.rti1516e.exceptions.NotConnected; 10 | import hla.rti1516e.exceptions.RTIinternalError; 11 | 12 | public interface TimeFactoryInterface { 13 | 14 | /** 15 | * Creates a Time instance starting from the FOM 16 | * @return Time 17 | * @throws RTIinternalError 18 | * @throws NotConnected 19 | * @throws FederateNotExecutionMember 20 | * @throws TimeRepresentationException 21 | * @throws IOException 22 | * @throws JDOMException 23 | */ 24 | public TimeInterface createTimeInstance() throws FederateNotExecutionMember, NotConnected, RTIinternalError, JDOMException, IOException, TimeRepresentationException; 25 | 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/dkf/time/TimeInterface.java: -------------------------------------------------------------------------------- 1 | package dkf.time; 2 | 3 | import org.joda.time.DateTime; 4 | 5 | import dkf.utility.JulianDateType; 6 | import hla.rti1516e.LogicalTime; 7 | import hla.rti1516e.LogicalTimeInterval; 8 | import hla.rti1516e.exceptions.IllegalTimeArithmetic; 9 | import hla.rti1516e.exceptions.InvalidLogicalTimeInterval; 10 | 11 | @SuppressWarnings("rawtypes") 12 | public interface TimeInterface { 13 | 14 | public void setFederateTime(LogicalTime time); 15 | 16 | public T nextTimeStep() throws IllegalTimeArithmetic, InvalidLogicalTimeInterval; 17 | 18 | //logicaltime 19 | public void initializeLogicalTime(); 20 | public void setLogicalTime(LogicalTime logicaltime); 21 | public T getLogicalTime(); 22 | 23 | //lookaheadinterval 24 | public void initializeLookaheadInterval(); 25 | public void setLookaheadInterval(LogicalTimeInterval logicaltimeinterval); 26 | public T getLookaheadInterval(); 27 | 28 | public double getFederationExecutionTimeCycle(); 29 | public DateTime getFederationExecutionTime(); 30 | public double getFederationExecutionTimeInJulianDate(JulianDateType juliantype); 31 | 32 | public double getFederateExecutionTimeCycle(); 33 | public void setFederateExecutionTimeCycle(double executiontime); 34 | 35 | public double getTimeClycle(); 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/JulianDateType.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.utility; 23 | 24 | public enum JulianDateType { 25 | 26 | DATE, MODIFIED, REDUCED, TRUNCATED 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/SystemUtility.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.utility; 23 | 24 | import java.io.BufferedReader; 25 | import java.io.IOException; 26 | import java.io.InputStreamReader; 27 | 28 | /** 29 | * 30 | * @author SMASH-Lab University of Calabria 31 | * @version 0.1 32 | * 33 | */ 34 | public class SystemUtility { 35 | 36 | /** 37 | * Checks the state of the 'CurrentProfile' profile in Windows Firewall 38 | * @return true if it is set to 'ON' 39 | */ 40 | public static boolean windowsFirewallIsEnabled(){ 41 | 42 | Process process = null; 43 | String line = null; 44 | BufferedReader reader = null; 45 | Boolean status = false; 46 | 47 | try { 48 | process = Runtime.getRuntime().exec("netsh advfirewall show currentprofile state"); 49 | process.waitFor(); 50 | reader = new BufferedReader(new InputStreamReader(process.getInputStream())); 51 | 52 | while ((line = reader.readLine()) != null) 53 | if(line.contains("ON")) 54 | status = true; 55 | 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | } catch (InterruptedException e) { 59 | e.printStackTrace(); 60 | } finally{ 61 | try { 62 | process.destroy(); 63 | reader.close(); 64 | } catch (IOException e) { 65 | e.printStackTrace(); 66 | } 67 | } 68 | 69 | return status; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/TimeUnit.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.utility; 23 | 24 | public enum TimeUnit { 25 | 26 | MINUTES, 27 | SECONDS, 28 | MILLISECONDS, 29 | MICROSECONDS, 30 | NANOSECONDS 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/TimeUtility.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | HLADevelopmentKit - A Java framework to develop HLA Federates. 3 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 4 | All rights reserved. 5 | 6 | GNU Lesser General Public License (GNU LGPL). 7 | 8 | This library is free software; you can redistribute it and/or 9 | modify it under the terms of the GNU Lesser General Public 10 | License as published by the Free Software Foundation; either 11 | version 3.0 of the License, or (at your option) any later version. 12 | 13 | This library is distributed in the hope that it will be useful, 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 | Lesser General Public License for more details. 17 | 18 | You should have received a copy of the GNU Lesser General Public 19 | License along with this library. 20 | If not, see http://http://www.gnu.org/licenses/ 21 | *****************************************************************/ 22 | package dkf.utility; 23 | 24 | public class TimeUtility { 25 | 26 | private static final TimeUnit[] units = new TimeUnit[] { 27 | 28 | TimeUnit.MINUTES, 29 | TimeUnit.SECONDS, 30 | TimeUnit.MILLISECONDS, 31 | TimeUnit.MICROSECONDS, 32 | TimeUnit.NANOSECONDS, 33 | 34 | }; 35 | 36 | private static final float[] conversionFactors = new float[] { 37 | 60, 38 | 1000, 39 | 1000, 40 | 1000, 41 | 1000, 42 | }; 43 | 44 | 45 | public static double convert(double time, TimeUnit from, TimeUnit to) { 46 | 47 | if(time < 0) 48 | throw new IllegalArgumentException("Time must be greater than zero."); 49 | 50 | int start_index = getTimeUnitIndex(from); 51 | int stop_index = getTimeUnitIndex(to); 52 | double returnValue = time; 53 | 54 | if(start_index < stop_index){ 55 | for(int i = start_index+1; i <= stop_index; i++) 56 | returnValue = returnValue * conversionFactors[i]; 57 | } 58 | else if(start_index > stop_index){ 59 | for(int i = start_index-1; i >= stop_index; i--){ 60 | returnValue = returnValue / conversionFactors[i]; 61 | } 62 | } 63 | return returnValue; 64 | 65 | } 66 | 67 | 68 | private static int getTimeUnitIndex(TimeUnit from) { 69 | 70 | for(int i=0; i < units.length; i++) 71 | if(units[i] == from) 72 | return i; 73 | return -1; 74 | } 75 | 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/access/FOMDataInspector.java: -------------------------------------------------------------------------------- 1 | package dkf.utility.access; 2 | 3 | import java.io.File; 4 | import java.io.FileFilter; 5 | import java.io.IOException; 6 | import java.net.URL; 7 | 8 | import org.apache.logging.log4j.LogManager; 9 | import org.apache.logging.log4j.Logger; 10 | import org.jdom2.Document; 11 | import org.jdom2.JDOMException; 12 | import org.jdom2.Namespace; 13 | import org.jdom2.filter.Filters; 14 | import org.jdom2.input.SAXBuilder; 15 | import org.jdom2.xpath.XPathExpression; 16 | import org.jdom2.xpath.XPathFactory; 17 | import org.jdom2.Element; 18 | 19 | import dkf.exception.TimeRepresentationException; 20 | 21 | public class FOMDataInspector { 22 | 23 | Logger logger = LogManager.getLogger(FOMDataInspector.class); 24 | 25 | // default Namespace 26 | private static final Namespace defaultNs = Namespace.getNamespace("ns", "http://standards.ieee.org/IEEE1516-2010"); 27 | private XPathFactory expr = null; 28 | 29 | private File fomsDirectory = null; 30 | 31 | protected FOMDataInspector(File fomsDirectory) { 32 | this.fomsDirectory = fomsDirectory; 33 | this.expr = XPathFactory.instance(); 34 | } 35 | 36 | protected URL[] getFOMsURL() { 37 | 38 | //load FOMs Modules 39 | FileFilter filter = new FileFilter() { 40 | @Override 41 | public boolean accept(File file) { 42 | if(file.getName().endsWith(".xml")){ 43 | logger.debug("Loading the "+file+" file."); 44 | return true; 45 | } 46 | return false; 47 | } 48 | }; 49 | 50 | URL[] foms = new URL[fomsDirectory.listFiles(filter).length]; 51 | int index = 0; 52 | for(File file: fomsDirectory.listFiles(filter)){ 53 | try { 54 | foms[index] = file.toURI().toURL(); 55 | index ++; 56 | } catch (IOException e) { 57 | e.printStackTrace(); 58 | logger.error("An error occurred during the processing of the FOM modules "+e.getMessage()); 59 | } 60 | } 61 | 62 | return foms; 63 | 64 | } 65 | 66 | private TimeType retrieveTimeRepresentation(URL[] url, XPathExpression expression) throws JDOMException, IOException, TimeRepresentationException { 67 | 68 | SAXBuilder builder = new SAXBuilder(); 69 | Document document = null; 70 | Element timetag = null; 71 | 72 | for(URL turl : url){ 73 | document = (Document) builder.build(turl); 74 | timetag = expression.evaluateFirst(document); 75 | if(timetag!= null) 76 | return TimeType.valueOf(timetag.getText()); 77 | } 78 | return null; 79 | } 80 | 81 | protected TimeType getTimestamp(URL[] url) throws JDOMException, IOException, TimeRepresentationException { 82 | return retrieveTimeRepresentation(url, expr.compile("//ns:time/ns:timeStamp/ns:dataType", Filters.element(), null, defaultNs)); 83 | } 84 | 85 | protected TimeType getLookahead(URL[] url) throws JDOMException, IOException, TimeRepresentationException { 86 | return retrieveTimeRepresentation(url, expr.compile("//ns:time/ns:lookahead/ns:dataType", Filters.element(), null, defaultNs)); 87 | } 88 | 89 | } 90 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/access/FOMDataInspectoryFactory.java: -------------------------------------------------------------------------------- 1 | package dkf.utility.access; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URL; 6 | 7 | import org.jdom2.JDOMException; 8 | 9 | import dkf.exception.TimeRepresentationException; 10 | 11 | public class FOMDataInspectoryFactory { 12 | 13 | private static FOMDataInspector inspector = null; 14 | private static URL[] url = null; 15 | private static TimeType timestamp = null; 16 | private static TimeType lookahead = null; 17 | 18 | public FOMDataInspectoryFactory(File fomsDirectory) { 19 | if(inspector == null) 20 | inspector = new FOMDataInspector(fomsDirectory); 21 | } 22 | 23 | public URL[] getFOMsURL() { 24 | if(url == null) 25 | url = inspector.getFOMsURL(); 26 | return url; 27 | } 28 | 29 | public TimeType getTimestamp() throws JDOMException, IOException, TimeRepresentationException { 30 | if(timestamp == null){ 31 | if(url == null) 32 | url = inspector.getFOMsURL(); 33 | 34 | timestamp = inspector.getTimestamp(url); 35 | } 36 | return timestamp; 37 | } 38 | 39 | public TimeType getLookahead() throws JDOMException, IOException, TimeRepresentationException { 40 | if(lookahead == null){ 41 | if(url == null) 42 | url = inspector.getFOMsURL(); 43 | 44 | lookahead = inspector.getLookahead(url); 45 | } 46 | return lookahead; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/dkf/utility/access/TimeType.java: -------------------------------------------------------------------------------- 1 | package dkf.utility.access; 2 | 3 | public enum TimeType { 4 | 5 | HLAinteger64Time, HLAfloat64Time 6 | 7 | } 8 | -------------------------------------------------------------------------------- /src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | logs/dkf 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /src/test/java/dkf/config/ConfigurationFactoryTest.java: -------------------------------------------------------------------------------- 1 | /***************************************************************** 2 | 3 | HLADevelopmentKit - A Java framework to develop HLA Federates. 4 | Copyright (c) 2015, SMASH Lab - University of Calabria (Italy), 5 | All rights reserved. 6 | 7 | GNU Lesser General Public License (GNU LGPL). 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 3.0 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library. 21 | If not, see http://http://www.gnu.org/licenses/ 22 | 23 | *****************************************************************/ 24 | package dkf.config; 25 | 26 | import static org.junit.Assert.*; 27 | 28 | import java.io.File; 29 | import java.io.IOException; 30 | import java.net.URISyntaxException; 31 | 32 | import org.joda.time.DateTime; 33 | import org.junit.After; 34 | import org.junit.AfterClass; 35 | import org.junit.Before; 36 | import org.junit.BeforeClass; 37 | import org.junit.Test; 38 | 39 | import com.fasterxml.jackson.core.JsonGenerationException; 40 | import com.fasterxml.jackson.databind.JsonMappingException; 41 | 42 | public class ConfigurationFactoryTest { 43 | 44 | private ConfigurationFactory factory = null; 45 | private File confiuration = null; 46 | private Configuration conf = null; 47 | 48 | @BeforeClass 49 | public static void setUpBeforeClass() throws Exception { 50 | 51 | } 52 | 53 | @AfterClass 54 | public static void tearDownAfterClass() throws Exception { 55 | 56 | } 57 | 58 | @Before 59 | public void setUp() throws Exception { 60 | 61 | factory = new ConfigurationFactory(); 62 | confiuration = new File(getClass().getResource("/configuration.json").toURI()); 63 | conf = factory.importConfiguration(confiuration); 64 | 65 | } 66 | 67 | @After 68 | public void tearDown() throws Exception { 69 | } 70 | 71 | @Test(expected = NullPointerException.class) 72 | public void invalidConfigurationFile() throws Exception { 73 | 74 | factory = new ConfigurationFactory(); 75 | conf = factory.importConfiguration(new File(getClass().getResource("/configuration1.json").toURI())); 76 | 77 | } 78 | 79 | @Test 80 | public void testImportConfiguration() { 81 | assertNotNull(conf); 82 | assertTrue(conf.isAsynchronousDelivery()); 83 | assertTrue(conf.getCrcHost().equals("localhost")); 84 | assertTrue(conf.getCrcPort() == 8989); 85 | assertTrue(conf.getFederateName().equals("Consumer")); 86 | assertTrue(conf.getFederationName().equals("SEE 2015")); 87 | assertNotNull(conf.getFomDirectory()); 88 | assertFalse(conf.isRealtime()); 89 | assertNotNull(conf.getSimulationEphoc()); 90 | assertTrue(conf.isTimeConstrained()); 91 | assertFalse(conf.isTimeRegulating()); 92 | } 93 | 94 | @Test 95 | public void testExportConfiguration() throws JsonGenerationException, JsonMappingException, IOException, URISyntaxException { 96 | Configuration tmp = factory.createConfiguration(); 97 | tmp.setAsynchronousDelivery(true); 98 | tmp.setCrcHost("localhost"); 99 | tmp.setCrcPort(8989); 100 | tmp.setFederateName("Consumer"); 101 | tmp.setFederationName("SEE 2015"); 102 | tmp.setFomDirectory(new File("C:/Users/SEI01/Desktop/StarterKit project/out")); 103 | tmp.setRealtime(false); 104 | tmp.setTimeConstrained(true); 105 | tmp.setTimeRegulating(false); 106 | tmp.setSimulationEphoc(new DateTime(10, 10, 10, 10, 10)); 107 | factory.exportConfiguration(tmp, new File("C:/Users/SEI01/Desktop/StarterKit project/out/export.json")); 108 | } 109 | 110 | @Test 111 | public void testCreateConfiguration() throws URISyntaxException { 112 | Configuration tmp = factory.createConfiguration(); 113 | tmp.setAsynchronousDelivery(true); 114 | tmp.setCrcHost("localhost"); 115 | tmp.setCrcPort(8989); 116 | tmp.setFederateName("Consumer"); 117 | tmp.setFederationName("SEE 2015"); 118 | tmp.setFomDirectory(new File("C:/Users/SEI01/Desktop/StarterKit project/out")); 119 | tmp.setRealtime(false); 120 | tmp.setTimeConstrained(true); 121 | tmp.setTimeRegulating(false); 122 | tmp.setSimulationEphoc(new DateTime(10, 10, 10, 10, 10)); 123 | 124 | assertNotNull(tmp); 125 | assertTrue(tmp.isAsynchronousDelivery()); 126 | assertTrue(tmp.getCrcHost().equals("localhost")); 127 | assertTrue(tmp.getCrcPort() == 8989); 128 | assertTrue(tmp.getFederateName().equals("Consumer")); 129 | assertTrue(tmp.getFederationName().equals("SEE 2015")); 130 | assertTrue(tmp.getFomDirectory().exists()); 131 | assertFalse(tmp.isRealtime()); 132 | assertNotNull(tmp.getSimulationEphoc()); 133 | assertTrue(tmp.isTimeConstrained()); 134 | assertFalse(tmp.isTimeRegulating()); 135 | 136 | } 137 | 138 | } 139 | -------------------------------------------------------------------------------- /src/test/java/dkf/core/DKFAbstractFederateTest.java: -------------------------------------------------------------------------------- 1 | package dkf.core; 2 | 3 | import hla.rti1516e.exceptions.CallNotAllowedFromWithinCallback; 4 | import hla.rti1516e.exceptions.ConnectionFailed; 5 | import hla.rti1516e.exceptions.CouldNotCreateLogicalTimeFactory; 6 | import hla.rti1516e.exceptions.CouldNotOpenFDD; 7 | import hla.rti1516e.exceptions.ErrorReadingFDD; 8 | import hla.rti1516e.exceptions.FederateIsExecutionMember; 9 | import hla.rti1516e.exceptions.FederateNotExecutionMember; 10 | import hla.rti1516e.exceptions.FederateOwnsAttributes; 11 | import hla.rti1516e.exceptions.InconsistentFDD; 12 | import hla.rti1516e.exceptions.InvalidLocalSettingsDesignator; 13 | import hla.rti1516e.exceptions.InvalidResignAction; 14 | import hla.rti1516e.exceptions.NotConnected; 15 | import hla.rti1516e.exceptions.OwnershipAcquisitionPending; 16 | import hla.rti1516e.exceptions.RTIinternalError; 17 | import hla.rti1516e.exceptions.RestoreInProgress; 18 | import hla.rti1516e.exceptions.SaveInProgress; 19 | import hla.rti1516e.exceptions.UnsupportedCallbackModel; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | import java.net.URISyntaxException; 24 | 25 | import org.junit.After; 26 | import org.junit.AfterClass; 27 | import org.junit.Before; 28 | import org.junit.BeforeClass; 29 | import org.junit.Test; 30 | 31 | import com.fasterxml.jackson.core.JsonParseException; 32 | import com.fasterxml.jackson.databind.JsonMappingException; 33 | 34 | import dkf.config.Configuration; 35 | import dkf.config.ConfigurationFactory; 36 | 37 | public class DKFAbstractFederateTest { 38 | 39 | @BeforeClass 40 | public static void setUpBeforeClass() throws Exception { 41 | } 42 | 43 | @AfterClass 44 | public static void tearDownAfterClass() throws Exception { 45 | } 46 | 47 | @Before 48 | public void setUp() throws Exception { 49 | } 50 | 51 | @After 52 | public void tearDown() throws Exception { 53 | } 54 | 55 | @Test 56 | public void testJoinIntoFederationExecution() throws URISyntaxException, JsonParseException, JsonMappingException, IOException, ConnectionFailed, InvalidLocalSettingsDesignator, UnsupportedCallbackModel, CallNotAllowedFromWithinCallback, RTIinternalError, CouldNotCreateLogicalTimeFactory, InconsistentFDD, ErrorReadingFDD, CouldNotOpenFDD, SaveInProgress, RestoreInProgress, NotConnected, FederateNotExecutionMember, InvalidResignAction, OwnershipAcquisitionPending, FederateOwnsAttributes, FederateIsExecutionMember { 57 | 58 | ConfigurationFactory factory = new ConfigurationFactory(); 59 | File confiuration = new File(getClass().getResource("/configuration.json").toURI()); 60 | Configuration conf = factory.importConfiguration(confiuration); 61 | 62 | DKFAbstractFederateAmbassador ambassador = new DKFAbstractFederateAmbassador() { 63 | 64 | }; 65 | 66 | DKFAbstractFederate federate = new DKFAbstractFederate(ambassador) { 67 | 68 | @Override 69 | protected void doAction() { 70 | // TODO Auto-generated method stub 71 | 72 | } 73 | 74 | }; 75 | 76 | federate.configure(conf); 77 | federate.connectToRTI("crcHost=" + conf.getCrcHost() + "\ncrcPort=" +conf.getCrcPort()); 78 | federate.joinFederationExecution(); 79 | federate.diconnectFromRTI(); 80 | 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/dkf/utility/access/FOMDataInspectorTest.java: -------------------------------------------------------------------------------- 1 | package dkf.utility.access; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.io.File; 6 | import java.io.IOException; 7 | import java.net.URL; 8 | 9 | import org.jdom2.JDOMException; 10 | import org.junit.After; 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | 14 | import dkf.exception.TimeRepresentationException; 15 | 16 | public class FOMDataInspectorTest { 17 | 18 | private File fomdir = null; 19 | private FOMDataInspectoryFactory finspector = null; 20 | 21 | @Before 22 | public void setUp() throws Exception { 23 | fomdir = new File("C:\\Users\\SEI01\\Desktop\\StarterKit project\\out"); 24 | finspector = new FOMDataInspectoryFactory(fomdir); 25 | } 26 | 27 | @After 28 | public void tearDown() throws Exception { 29 | } 30 | 31 | @Test 32 | public void testFOMDataInspector() { 33 | assertNotNull(finspector); 34 | } 35 | 36 | @Test 37 | public void testGetFOMsURL() { 38 | 39 | URL[] url = finspector.getFOMsURL(); 40 | 41 | assertNotNull(url); 42 | assertTrue(url.length == 3); 43 | } 44 | 45 | @Test 46 | public void testGetTimestamp() throws JDOMException, IOException, TimeRepresentationException { 47 | assertTrue(finspector.getTimestamp() == TimeType.HLAinteger64Time); 48 | } 49 | 50 | @Test 51 | public void testGetLookahead() throws JDOMException, IOException, TimeRepresentationException { 52 | assertTrue(finspector.getLookahead() == TimeType.HLAinteger64Time); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/test/resources/configuration.json: -------------------------------------------------------------------------------- 1 | { 2 | "asynchronousDelivery" : true, 3 | "crcHost" : "localhost", 4 | "crcPort" : 8989, 5 | "federateName" : "Consumer", 6 | "federateType" : "Consumer", 7 | "federationName" : "SEE 2015", 8 | "fomDirectory" : "C:/Users/SEI01/Desktop/StarterKit project/out", 9 | "realtime" : false, 10 | "simulationEphoc" : "2013-04-10T20:00:00.000Z", 11 | "timeConstrained" : true, 12 | "timeRegulating" : false 13 | } --------------------------------------------------------------------------------