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
1aa93c4d
Commit
1aa93c4d
authored
4 years ago
by
terry-norbraten
Browse files
Options
Downloads
Patches
Plain Diff
rework for threading
parent
6680f085
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
src/edu/nps/moves/dis7/examples/EntityUse.java
+18
-12
18 additions, 12 deletions
src/edu/nps/moves/dis7/examples/EntityUse.java
with
18 additions
and
12 deletions
src/edu/nps/moves/dis7/examples/EntityUse.java
+
18
−
12
View file @
1aa93c4d
...
...
@@ -75,6 +75,11 @@ public class EntityUse
*/
public
static
void
exampleUse
()
throws
Exception
{
DisThreadedNetIF
netif
=
new
DisThreadedNetIF
();
// uses defaults
// We want to listen also, so add a listener, using JDK8+ lambda grammar
netif
.
addListener
(
pdu
->
handleReceivedPdu
(
pdu
));
PduFactory
pduFactory
=
new
PduFactory
();
// uses defaults: usa, exercise id 1, site id 2, app id 3, absolute time
EntityStatePdu
espdu
=
pduFactory
.
makeEntityStatePdu
();
...
...
@@ -88,27 +93,28 @@ public class EntityUse
espdu
.
setEntityType
(
et
);
DisThreadedNetIF
netif
=
new
DisThreadedNetIF
();
// uses defaults
// We want to listen also, so add a listener, using JDK8+ lambda grammar
netif
.
addListener
(
pdu
->
handleReceivedPdu
(
pdu
));
netif
.
send
(
espdu
);
// possibly throws IOException
sleep
(
100L
);
/* Do the same for the second way of creating a Shenandoah entity type and show an alternate way of creating an ESPDU */
EntityStatePdu
espdu
2
=
(
EntityStatePdu
)
pduFactory
.
createPdu
(
DISPDUType
.
ENTITY_STATE
);
espdu
=
(
EntityStatePdu
)
pduFactory
.
createPdu
(
DISPDUType
.
ENTITY_STATE
);
/* set desired entity state fields here */
edu
.
nps
.
moves
.
dis7
.
entities
.
usa
.
platform
.
surface
.
AD44Shenandoah
et2
=
new
edu
.
nps
.
moves
.
dis7
.
entities
.
usa
.
platform
.
surface
.
AD44Shenandoah
();
/* Use import statement to make the code above more readable */
espdu2
.
setEntityType
(
et2
);
netif
.
send
(
espdu2
);
// possibly throws IOException
// Wait a bit to see output
try
{
Thread
.
sleep
(
250L
);
}
catch
(
InterruptedException
ex
)
{}
espdu
.
setEntityType
(
et2
);
netif
.
send
(
espdu
);
// possibly throws IOException
sleep
(
100L
);
}
private
static
void
sleep
(
long
ms
)
{
try
{
Thread
.
sleep
(
ms
);
}
catch
(
InterruptedException
ex
)
{}
}
private
static
void
handleReceivedPdu
(
Pdu
pdu
)
...
...
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