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
0cb6d87c
Commit
0cb6d87c
authored
3 years ago
by
Brutzman, Don
Browse files
Options
Downloads
Patches
Plain Diff
improved method interfaces, javadoc
parent
77bdae30
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/edu/nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
+122
-27
122 additions, 27 deletions
...nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
with
122 additions
and
27 deletions
src/edu/nps/moves/dis7/utilities/DisThreadedNetworkInterface.java
+
122
−
27
View file @
0cb6d87c
...
@@ -29,14 +29,18 @@ import java.util.logging.Logger;
...
@@ -29,14 +29,18 @@ import java.util.logging.Logger;
*/
*/
public
class
DisThreadedNetworkInterface
public
class
DisThreadedNetworkInterface
{
{
/** Default value */
/** Default multicast group address <code>229.1.2.3</code> for send and receive connections.
public
static
String
DEFAULT_MULTICAST_ADDRESS
=
"225.4.5.6"
;
* @see <a href="https://en.wikipedia.org/wiki/Multicast_address">https://en.wikipedia.org/wiki/Multicast_address</a> */
public
static
String
DEFAULT_MULTICAST_ADDRESS
=
"229.1.2.3"
;
/** Default value */
/** Default socket port <code>3000</code>, matches Wireshark DIS capture default
* @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a> */
public
static
int
DEFAULT_DIS_PORT
=
3000
;
public
static
int
DEFAULT_DIS_PORT
=
3000
;
private
static
final
String
TRACE_PREFIX
=
"["
+
DisThreadedNetworkInterface
.
class
.
getName
()
+
"] "
;
private
static
final
String
TRACE_PREFIX
=
"["
+
DisThreadedNetworkInterface
.
class
.
getName
()
+
"] "
;
private
boolean
verbose
=
true
;
private
boolean
verbose
=
true
;
private
boolean
verboseReceipt
=
true
;
private
boolean
verboseSending
=
true
;
private
boolean
verboseIncludesTimestamp
=
false
;
private
boolean
verboseIncludesTimestamp
=
false
;
/**
/**
...
@@ -113,7 +117,7 @@ public class DisThreadedNetworkInterface
...
@@ -113,7 +117,7 @@ public class DisThreadedNetworkInterface
private
DatagramSocket
datagramSocket
=
null
;
private
DatagramSocket
datagramSocket
=
null
;
/**
/**
*
Defaul
t constructor using default
port and
multicast address
*
Objec
t constructor using default multicast address
and port
*/
*/
public
DisThreadedNetworkInterface
()
public
DisThreadedNetworkInterface
()
{
{
...
@@ -121,7 +125,7 @@ public class DisThreadedNetworkInterface
...
@@ -121,7 +125,7 @@ public class DisThreadedNetworkInterface
}
}
/**
/**
*
C
onstructor
*
Object c
onstructor
using specified multicast address and port
* @param multicastGroup the multicast group address to utilize
* @param multicastGroup the multicast group address to utilize
* @param port the multicast port to utilize
* @param port the multicast port to utilize
*/
*/
...
@@ -223,20 +227,38 @@ public class DisThreadedNetworkInterface
...
@@ -223,20 +227,38 @@ public class DisThreadedNetworkInterface
sleep
(
100
l
);
// TODO needed?
sleep
(
100
l
);
// TODO needed?
}
}
/**
/** Deprecated, replaced by getPort()
* Get current port value
* @return current port value
* @return current port value
*/
*/
@Deprecated
public
int
getDisPort
()
public
int
getDisPort
()
{
return
getPort
();
}
/** Get network port used, multicast or unicast.
* @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a>
* @return current port value
*/
public
int
getPort
()
{
{
return
disPort
;
return
disPort
;
}
}
/**
/**
*
Get current multicast address value
*
Deprecated, replaced by getAddress()
* @return current multicast address value
* @return current multicast address value
*/
*/
@Deprecated
public
String
getMulticastGroup
()
public
String
getMulticastGroup
()
{
return
getAddress
();
}
/**
* Get current multicast (or unicast) address value
* @return current multicast address value
*/
public
String
getAddress
()
{
{
return
multicastAddress
;
return
multicastAddress
;
}
}
...
@@ -291,7 +313,7 @@ public class DisThreadedNetworkInterface
...
@@ -291,7 +313,7 @@ public class DisThreadedNetworkInterface
try
try
{
{
// The initial value of the SO_BROADCAST socket option is FALSE
// The initial value of the SO_BROADCAST socket option is FALSE
datagramSocket
=
new
MulticastSocket
(
get
Dis
Port
());
datagramSocket
=
new
MulticastSocket
(
getPort
());
((
MulticastSocket
)
datagramSocket
).
joinGroup
(
inetSocket
,
networkInterface
);
((
MulticastSocket
)
datagramSocket
).
joinGroup
(
inetSocket
,
networkInterface
);
}
}
catch
(
IOException
ex
)
catch
(
IOException
ex
)
...
@@ -303,7 +325,7 @@ public class DisThreadedNetworkInterface
...
@@ -303,7 +325,7 @@ public class DisThreadedNetworkInterface
private
Runnable
receiveThread
=
()
->
{
private
Runnable
receiveThread
=
()
->
{
int
c
ounter
=
0
;
int
pduReceiptC
ounter
=
0
;
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
// The raw listeners will strip off any extra padding and process what is
// The raw listeners will strip off any extra padding and process what is
...
@@ -328,11 +350,11 @@ public class DisThreadedNetworkInterface
...
@@ -328,11 +350,11 @@ public class DisThreadedNetworkInterface
if
(
pdu
!=
null
)
if
(
pdu
!=
null
)
{
{
c
ounter
++;
// TODO experimental, add to generator as a commented-out diagnostic; consider adding diagnostic mode
pduReceiptC
ounter
++;
// TODO experimental, add to generator as a commented-out diagnostic; consider adding diagnostic mode
if
(
i
sVerbose
())
if
(
ha
sVerbose
Output
()
&&
hasVerboseReceipt
())
{
{
String
message
=
TRACE_PREFIX
+
counter
+
". received
"
+
pdu
.
getPduType
().
toString
();
String
message
=
TRACE_PREFIX
+
"[receipt "
+
pduReceiptCounter
+
"]
"
+
pdu
.
getPduType
().
toString
();
if
(
i
sVerboseIncludesTimestamp
())
if
(
ha
sVerbose
Output
IncludesTimestamp
())
message
+=
" (timestamp "
+
DisTime
.
timeStampToString
(
pdu
.
getTimestamp
());
message
+=
" (timestamp "
+
DisTime
.
timeStampToString
(
pdu
.
getTimestamp
());
message
+=
", size "
+
pdu
.
getMarshalledSize
()
+
" bytes)"
;
message
+=
", size "
+
pdu
.
getMarshalledSize
()
+
" bytes)"
;
System
.
out
.
println
(
message
);
System
.
out
.
println
(
message
);
...
@@ -369,6 +391,8 @@ public class DisThreadedNetworkInterface
...
@@ -369,6 +391,8 @@ public class DisThreadedNetworkInterface
Pdu
pdu
;
Pdu
pdu
;
int
pduSentCounter
=
0
;
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
// The capacity could go up to MAX_DIS_PDU_SIZE, but this should be good for now
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
MAX_TRANSMISSION_UNIT_SIZE
);
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
(
MAX_TRANSMISSION_UNIT_SIZE
);
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
DataOutputStream
dos
=
new
DataOutputStream
(
baos
);
...
@@ -387,7 +411,17 @@ public class DisThreadedNetworkInterface
...
@@ -387,7 +411,17 @@ public class DisThreadedNetworkInterface
pdu
.
marshal
(
dos
);
pdu
.
marshal
(
dos
);
packet
.
setData
(
baos
.
toByteArray
());
packet
.
setData
(
baos
.
toByteArray
());
datagramSocket
.
send
(
packet
);
datagramSocket
.
send
(
packet
);
pduSentCounter
++;
// TODO experimental, add to generator as a commented-out diagnostic; consider adding diagnostic mode
if
(
hasVerboseOutput
()
&&
hasVerboseSending
())
{
String
message
=
TRACE_PREFIX
+
"[sending "
+
pduSentCounter
+
"] "
+
pdu
.
getPduType
().
toString
();
if
(
hasVerboseOutputIncludesTimestamp
())
message
+=
" (timestamp "
+
DisTime
.
timeStampToString
(
pdu
.
getTimestamp
());
message
+=
", size "
+
pdu
.
getMarshalledSize
()
+
" bytes)"
;
System
.
out
.
println
(
message
);
System
.
out
.
flush
();
}
dos
.
flush
();
// immediately force pdu write
dos
.
flush
();
// immediately force pdu write
baos
.
reset
();
baos
.
reset
();
}
}
...
@@ -399,7 +433,8 @@ public class DisThreadedNetworkInterface
...
@@ -399,7 +433,8 @@ public class DisThreadedNetworkInterface
}
}
try
{
try
{
dos
.
close
();
dos
.
close
();
}
catch
(
IOException
e
)
{}
}
catch
(
IOException
e
)
{}
// shutting down, no need to report exception
};
};
private
void
toListeners
(
Pdu
pdu
)
{
private
void
toListeners
(
Pdu
pdu
)
{
...
@@ -430,8 +465,16 @@ public class DisThreadedNetworkInterface
...
@@ -430,8 +465,16 @@ public class DisThreadedNetworkInterface
rawListeners
.
forEach
(
lis
->
lis
.
incomingPdu
(
bl
));
rawListeners
.
forEach
(
lis
->
lis
.
incomingPdu
(
bl
));
}
}
/** Terminate the instance */
/** Method renamed as <code>close()</code>.
*/
@Deprecated
public
void
kill
()
public
void
kill
()
{
close
();
}
/** Terminate the instance after completion of pending send/receive activity. */
public
void
close
()
{
{
killed
=
true
;
// set loop sentinel for threads
killed
=
true
;
// set loop sentinel for threads
}
}
...
@@ -484,30 +527,80 @@ public class DisThreadedNetworkInterface
...
@@ -484,30 +527,80 @@ public class DisThreadedNetworkInterface
}
}
/**
/**
* @return the verbose
* Set whether or not trace statements are provided when packets are sent or received.
* @param newValue the verbose status to set. Also resets verboseReceipt and verboseSending to match.
* @see verboseReceipt
* @see verboseSending
*/
*/
public
boolean
isVerbose
()
public
void
setVerbose
(
boolean
newValue
)
{
this
.
verbose
=
newValue
;
verboseReceipt
=
verbose
;
verboseSending
=
verbose
;
}
/**
* Whether or not trace statements are provided when packets are sent or received.
* @return the verbose status
* @see verboseReceipt
* @see verboseSending
*/
public
boolean
hasVerboseOutput
()
{
{
return
verbose
;
return
verbose
;
}
}
/**
/**
* @param verbose the verbose to set
* Set whether or not trace statements are provided when packets are received.
* @param newValue the verboseReceipt status to set
* @see verbose
* @see verboseSending
*/
public
void
setVerboseReceipt
(
boolean
newValue
)
{
this
.
verboseReceipt
=
newValue
;
verbose
=
(
verboseReceipt
||
verboseSending
);
}
/**
* Whether or not trace statements are provided when packets are received.
* @return the verboseReceipt status
*/
public
boolean
hasVerboseReceipt
()
{
return
verboseReceipt
;
}
/**
* Set whether or not trace statements are provided when packets are sent.
* @param newValue the verboseSending status to set
* @see verbose
* @see verboseReceipt
*/
public
void
setVerboseSending
(
boolean
newValue
)
{
this
.
verboseSending
=
newValue
;
verbose
=
(
verboseReceipt
||
verboseSending
);
}
/**
* Whether or not trace statements are provided when packets are sent.
* @return the verboseSending status
*/
*/
public
void
setVerbose
(
boolean
v
erbose
)
public
boolean
hasV
erbose
Sending
(
)
{
{
this
.
verbose
=
verbose
;
return
verbose
Sending
;
}
}
/**
/**
* Whether or not trace statements include timestamp values.
* @return the verboseIncludesTimestamp value
* @return the verboseIncludesTimestamp value
*/
*/
public
boolean
i
sVerboseIncludesTimestamp
()
public
boolean
ha
sVerbose
Output
IncludesTimestamp
()
{
{
return
verboseIncludesTimestamp
;
return
verboseIncludesTimestamp
;
}
}
/**
/**
* Set whether or not trace statements include timestamp values.
* @param verboseIncludesTimestamp the value to set
* @param verboseIncludesTimestamp the value to set
*/
*/
public
void
setVerboseIncludesTimestamp
(
boolean
verboseIncludesTimestamp
)
public
void
setVerboseIncludesTimestamp
(
boolean
verboseIncludesTimestamp
)
...
@@ -516,10 +609,12 @@ public class DisThreadedNetworkInterface
...
@@ -516,10 +609,12 @@ public class DisThreadedNetworkInterface
}
}
/**
/**
* @param disPort the disPort value to set
/** Set network port used, multicast or unicast.
* @see <a href="https://en.wikipedia.org/wiki/Port_(computer_networking)">https://en.wikipedia.org/wiki/Port_(computer_networking)</a>
* @param newPortValue the disPort value to set
*/
*/
public
void
set
Dis
Port
(
int
dis
Port
)
public
void
setPort
(
int
new
Port
Value
)
{
{
this
.
disPort
=
dis
Port
;
this
.
disPort
=
new
Port
Value
;
}
}
}
}
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