Skip to content

Commit e5e0705

Browse files
committed
Waiting for PTAG before executing startup reactions
Also, now `_react()` is called when `this._isDone` is false and LTC is not sent if any of network input port is `unknown`.
1 parent f66892d commit e5e0705

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/core/federation.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,11 @@ export class FederatedApp extends App {
14311431
return false;
14321432
}
14331433
}
1434+
if (this.maxLevelAllowedToAdvance != Number.MAX_SAFE_INTEGER) {
1435+
// The reaction queue is empty but some network receivers are waiting for
1436+
// network inputs.
1437+
return false;
1438+
}
14341439
Log.global.debug("Finished handling all events at current time.");
14351440
return true;
14361441
}
@@ -1875,6 +1880,23 @@ export class FederatedApp extends App {
18751880
}
18761881
}
18771882

1883+
/**
1884+
* Start executing reactions.
1885+
*/
1886+
protected _startExecuting(): void {
1887+
Log.info(this, () => Log.hr);
1888+
Log.info(this, () => Log.hr);
1889+
1890+
Log.info(
1891+
this,
1892+
() => `>>> Start of execution: ${this.util.getCurrentTag()}`
1893+
);
1894+
Log.info(this, () => Log.hr);
1895+
1896+
// Send RTI a NET and wait for PTAG or TAG.
1897+
this.sendRTINextEventTag(this.util.getCurrentTag());
1898+
}
1899+
18781900
/**
18791901
* @override
18801902
* Register this federated app with the RTI and request a start time.

src/core/reactor.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,7 +1835,9 @@ export class App extends Reactor {
18351835

18361836
/**
18371837
* Stores whether the current tag's reactions queue is empty.
1838-
* This will be false when a federate waits some network inputs.
1838+
* This will be false when a federate waits for network inputs.
1839+
* Note that this should be initialized with false to handle startup
1840+
* reactions of each federate.
18391841
*/
18401842
private _isDone = false;
18411843

@@ -2388,8 +2390,10 @@ export class App extends Reactor {
23882390
*/
23892391
private _next(): void {
23902392
let nextEvent = this._eventQ.peek();
2391-
if (nextEvent != null) {
2392-
if (this._isDone) {
2393+
if (nextEvent != null || !this._isDone) {
2394+
if (nextEvent != null && this._isDone) {
2395+
// We're trying to advance a tag to the next event.
2396+
23932397
// Check whether the next event can be handled, or not quite yet.
23942398
// A holdup can occur in a federated execution.
23952399
if (!this._canProceed(nextEvent)) {

0 commit comments

Comments
 (0)