Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
NetworkedGraphicsMV3500
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Savage
NetworkedGraphicsMV3500
Commits
e90466ee
Commit
e90466ee
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
expose accessor methods for selected member variables
parent
478b9b95
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/src/OpenDis7Examples/ChannelOpenDis7.java
+62
-24
62 additions, 24 deletions
examples/src/OpenDis7Examples/ChannelOpenDis7.java
with
62 additions
and
24 deletions
examples/src/OpenDis7Examples/ChannelOpenDis7.java
+
62
−
24
View file @
e90466ee
...
...
@@ -17,15 +17,16 @@ import java.util.ArrayList;
// import jdk.internal.vm.annotation.IntrinsicCandidate;
/**
*
*
Handle most networking chores, provide clean interface for programs connecting to OpenDIS7 communications
* @author brutzman
*/
public
class
ChannelOpenDis7
{
public
class
ChannelOpenDis7
{
/**
* Output prefix to help with logging by identifying this class.
*/
private
static
String
TRACE_PREFIX
=
"[OpenDis7]"
;
static
String
thisHostName
=
"localhost"
;
private
String
TRACE_PREFIX
=
"[OpenDis7]"
;
// might have different ChannelOpenDis7 objects created on different channels, so non-static
private
static
String
thisHostName
=
"localhost"
;
private
static
final
String
NETWORK_ADDRESS_DEFAULT
=
"239.1.2.3"
;
private
static
final
int
NETWORK_PORT_DEFAULT
=
3000
;
private
static
final
String
DEFAULT_PDULOG_OUTPUT_DIRECTORY
=
"./pduLog"
;
...
...
@@ -36,13 +37,13 @@ public class ChannelOpenDis7 {
static
DisTime
.
TimestampStyle
timestampStyle
=
DisTime
.
TimestampStyle
.
IEEE_ABSOLUTE
;
/** Creates DIS Protocol Data Unit (PDU) classes for simulation entities */
static
PduFactory
pduFactory
;
private
static
PduFactory
pduFactory
;
// class variables
DisThreadedNetworkInterface
disNetworkInterface
;
DisThreadedNetworkInterface
.
PduListener
pduListener
;
Pdu
receivedPdu
;
PduRecorder
pduRecorder
;
private
DisThreadedNetworkInterface
disNetworkInterface
;
DisThreadedNetworkInterface
.
PduListener
pduListener
;
Pdu
receivedPdu
;
private
PduRecorder
pduRecorder
;
public
ChannelOpenDis7
()
{
...
...
@@ -56,7 +57,7 @@ public class ChannelOpenDis7 {
}
catch
(
UnknownHostException
uhe
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
thisHostName
+
"not connected to network: "
+
uhe
.
getMessage
());
System
.
out
.
println
(
TRACE_PREFIX
+
thisHostName
+
"
id
not connected to network: "
+
uhe
.
getMessage
());
}
}
...
...
@@ -114,9 +115,9 @@ public class ChannelOpenDis7 {
*/
public
void
setUpNetworkInterface
()
{
disNetworkInterface
=
new
DisThreadedNetworkInterface
(
getNetworkAddress
(),
getNetworkPort
());
d
isNetworkInterface
.
setDescriptor
(
"ExampleSimulationProgram pdu looping"
);
System
.
out
.
println
(
"Network confirmation:"
+
" address="
+
d
isNetworkInterface
.
getAddress
()
+
// disNetworkInterface.getMulticastGroup() +
" port="
+
d
isNetworkInterface
.
getPort
());
// + disNetworkInterface.getDisPort());
getD
isNetworkInterface
()
.
setDescriptor
(
"ExampleSimulationProgram pdu looping"
);
System
.
out
.
println
(
"Network confirmation:"
+
" address="
+
getD
isNetworkInterface
()
.
getAddress
()
+
// disNetworkInterface.getMulticastGroup() +
" port="
+
getD
isNetworkInterface
()
.
getPort
());
// + disNetworkInterface.getDisPort());
pduListener
=
new
DisThreadedNetworkInterface
.
PduListener
()
{
/** Callback handler for listener */
@Override
...
...
@@ -124,18 +125,18 @@ public class ChannelOpenDis7 {
receivedPdu
=
newPdu
;
}
};
d
isNetworkInterface
.
addListener
(
pduListener
);
getD
isNetworkInterface
()
.
addListener
(
pduListener
);
String
pduLogOutputDirectory
=
DEFAULT_PDULOG_OUTPUT_DIRECTORY
;
System
.
out
.
println
(
"Beginning pdu save to directory "
+
pduLogOutputDirectory
);
pduRecorder
=
new
PduRecorder
(
pduLogOutputDirectory
,
getNetworkAddress
(),
getNetworkPort
());
// assumes save
p
duRecorder
.
setEncodingPduLog
(
PduRecorder
.
ENCODING_PLAINTEXT
);
p
duRecorder
.
setVerbose
(
true
);
// either sending, receiving or both
p
duRecorder
.
start
();
// begin running
getP
duRecorder
()
.
setEncodingPduLog
(
PduRecorder
.
ENCODING_PLAINTEXT
);
getP
duRecorder
()
.
setVerbose
(
true
);
// either sending, receiving or both
getP
duRecorder
()
.
start
();
// begin running
}
/** All done, release network resources */
public
void
tearDownNetworkInterface
()
{
p
duRecorder
.
stop
();
// handles disNetworkInterface.close(), tears down threads and sockets
getP
duRecorder
()
.
stop
();
// handles disNetworkInterface.close(), tears down threads and sockets
}
/**
...
...
@@ -144,11 +145,11 @@ public class ChannelOpenDis7 {
*/
protected
void
sendSinglePdu
(
Pdu
pdu
)
{
if
(
d
isNetworkInterface
==
null
)
if
(
getD
isNetworkInterface
()
==
null
)
setUpNetworkInterface
();
// ensure connected
try
{
d
isNetworkInterface
.
send
(
pdu
);
getD
isNetworkInterface
()
.
send
(
pdu
);
Thread
.
sleep
(
100
);
// TODO consider refactoring the wait logic and moving externally
}
catch
(
InterruptedException
ex
)
...
...
@@ -179,14 +180,14 @@ public class ChannelOpenDis7 {
}
if
(!
newCommentsList
.
isEmpty
())
{
if
(
d
isNetworkInterface
==
null
)
if
(
getD
isNetworkInterface
()
==
null
)
setUpNetworkInterface
();
// ensure connected
if
(
commentType
==
null
)
commentType
=
VariableRecordType
.
OTHER
;
// fallback value; TODO consider pushing into pduFactory
// now build the commentPdu from these string inputs, thus constructing a narrative entry
@SuppressWarnings
(
"CollectionsToArray"
)
CommentPdu
commentPdu
=
p
duFactory
.
makeCommentPdu
(
commentType
,
newCommentsList
.
toArray
(
new
String
[
0
]));
// comments);
CommentPdu
commentPdu
=
getP
duFactory
()
.
makeCommentPdu
(
commentType
,
newCommentsList
.
toArray
(
new
String
[
0
]));
// comments);
sendSinglePdu
(
commentPdu
);
if
(
isVerboseComments
())
{
...
...
@@ -216,14 +217,14 @@ public class ChannelOpenDis7 {
/**
* @return the TRACE_PREFIX
*/
public
static
String
getTRACE_PREFIX
()
{
public
String
getTRACE_PREFIX
()
{
return
TRACE_PREFIX
;
}
/**
* @param aTRACE_PREFIX the TRACE_PREFIX to set
*/
public
static
void
setTRACE_PREFIX
(
String
aTRACE_PREFIX
)
{
public
void
setTRACE_PREFIX
(
String
aTRACE_PREFIX
)
{
TRACE_PREFIX
=
aTRACE_PREFIX
;
}
...
...
@@ -241,4 +242,41 @@ public class ChannelOpenDis7 {
public
void
printlnTRACE
(
String
message
)
{
System
.
out
.
println
(
TRACE_PREFIX
+
message
);
}
/**
* @return the pduFactory, simplifying program imports and configuration
*/
public
PduFactory
getPduFactory
()
{
if
(
pduFactory
==
null
)
pduFactory
=
new
PduFactory
(
timestampStyle
);
return
pduFactory
;
}
/**
* @return the disNetworkInterface
*/
public
DisThreadedNetworkInterface
getDisNetworkInterface
()
{
return
disNetworkInterface
;
}
/**
* @return the thisHostName
*/
public
static
String
getThisHostName
()
{
return
thisHostName
;
}
/**
* @param aThisHostName the thisHostName to set
*/
public
static
void
setThisHostName
(
String
aThisHostName
)
{
thisHostName
=
aThisHostName
;
}
/**
* @return the pduRecorder
*/
public
PduRecorder
getPduRecorder
()
{
return
pduRecorder
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment