Skip to content
Snippets Groups Projects
Commit 1aa93c4d authored by terry-norbraten's avatar terry-norbraten
Browse files

rework for threading

parent 6680f085
No related branches found
No related tags found
No related merge requests found
......@@ -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 espdu2 = (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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment