diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-12-07 23:14:16 +0000 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-12-07 23:33:22 +0000 |
| commit | de739998fde6b856e40f8a98f78efddc0c57f167 (patch) | |
| tree | 0a9829fcc837dd7ac041ab75e1a0ed18644c53df /opendc-simulator/opendc-simulator-flow/src/main/java | |
| parent | b88f07ebb056293b1a29f24e4f42203c09bcbcf8 (diff) | |
bug(sim/flow): Record capacity changes on idle outlets
This change fixes an issue with the `ForwardingFlowMultiplexer` where
the capacity of new outlets were not recorded correctly due to no
handler being attached to idle outlets, causing the `pull` events to be
disregarded.
This bug manifested in an issue where the CPU counters where reporting
negative values. This was caused by the CPU usage/demand being
subtracted from a zero capacity.
Diffstat (limited to 'opendc-simulator/opendc-simulator-flow/src/main/java')
| -rw-r--r-- | opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/flow2/mux/ForwardingFlowMultiplexer.java | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/flow2/mux/ForwardingFlowMultiplexer.java b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/flow2/mux/ForwardingFlowMultiplexer.java index abe3510b..e0564cd2 100644 --- a/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/flow2/mux/ForwardingFlowMultiplexer.java +++ b/opendc-simulator/opendc-simulator-flow/src/main/java/org/opendc/simulator/flow2/mux/ForwardingFlowMultiplexer.java @@ -182,6 +182,9 @@ public final class ForwardingFlowMultiplexer implements FlowMultiplexer, FlowSta activeOutputs.set(slot); availableOutputs.set(slot); + + port.setHandler(IDLE_OUT_HANDLER); + return port; } @@ -270,11 +273,15 @@ public final class ForwardingFlowMultiplexer implements FlowMultiplexer, FlowSta public void onUpstreamFinish(InPort port, Throwable cause) {} } - private static class IdleOutHandler implements OutHandler { + private class IdleOutHandler implements OutHandler { @Override - public void onPull(OutPort port, float capacity) {} + public void onPull(OutPort port, float capacity) { + ForwardingFlowMultiplexer.this.capacity += -port.getCapacity() + capacity; + } @Override - public void onDownstreamFinish(OutPort port, Throwable cause) {} + public void onDownstreamFinish(OutPort port, Throwable cause) { + ForwardingFlowMultiplexer.this.capacity -= port.getCapacity(); + } } } |
