@@ -119,10 +119,10 @@ public class Consumer { |
119 | 119 | private volatile int messagePermits = 0; |
120 | 120 | /** |
121 | 121 | * Guards the Flow-side compound update of {@link #messagePermits} and |
122 | | - * {@link #pendingDispatcherFlowPermits}. A Flow command increases the consumer permits before the dispatcher |
123 | | - * processes the corresponding update asynchronously. Consumer removal can happen between those two operations, |
124 | | - * so both values must be observed consistently when calculating how many permits are already included in the |
125 | | - * dispatcher total. |
| 122 | + * {@link #pendingDispatcherFlowPermits}. A Flow command increases the consumer permits before entering the |
| 123 | + * dispatcher. Consumer removal can happen while the Flow caller is waiting for the dispatcher monitor, so both |
| 124 | + * values must be observed consistently when calculating how many permits are already included in the dispatcher |
| 125 | + * total. |
126 | 126 | * |
127 | 127 | * <p>The dispatcher callback is invoked only after this lock is released. This avoids holding the lock while |
128 | 128 | * calling into the subscription and preserves the lock order used by dispatcher flow processing and removal. |
@@ -969,7 +969,8 @@ public int getAvailablePermits() { |
969 | 969 |
|
970 | 970 | /** |
971 | 971 | * Adds permits after a Flow command is accepted and immediately before notifying the dispatcher. The pending |
972 | | - * count covers the interval until the dispatcher's asynchronous Flow task starts processing the same permits. |
| 972 | + * count covers the interval until the dispatcher starts processing the same permits, including time spent waiting |
| 973 | + * for the dispatcher monitor. |
973 | 974 | */ |
974 | 975 | private int addPermitsPendingDispatcherUpdate(int additionalNumberOfPermits) { |
975 | 976 | if (!shouldTrackPendingDispatcherFlowPermits()) { |
@@ -986,9 +987,9 @@ private boolean shouldTrackPendingDispatcherFlowPermits() { |
986 | 987 | } |
987 | 988 |
|
988 | 989 | /** |
989 | | - * Called at the start of the dispatcher's asynchronous Flow task, before checking whether this consumer is still |
990 | | - * connected. At this point the Flow update is no longer pending: the dispatcher will either add the permits to |
991 | | - * its total or ignore them because the consumer has already been removed. |
| 990 | + * Called at the start of dispatcher Flow processing, before checking whether this consumer is still connected. At |
| 991 | + * this point the Flow update is no longer pending: the dispatcher will either add the permits to its total or |
| 992 | + * ignore them because the consumer has already been removed. |
992 | 993 | */ |
993 | 994 | public void completePendingDispatcherFlow(int additionalNumberOfPermits) { |
994 | 995 | synchronized (flowPermitAccountingLock) { |
@@ -998,19 +999,19 @@ public void completePendingDispatcherFlow(int additionalNumberOfPermits) { |
998 | 999 | } |
999 | 1000 |
|
1000 | 1001 | /** |
1001 | | - * Called while the dispatcher removes this consumer. Permits belonging to Flow tasks that have not started yet |
1002 | | - * are excluded because those permits have not been added to the dispatcher total and must not be subtracted from |
1003 | | - * it during removal. |
| 1002 | + * Called while the dispatcher removes this consumer. Permits belonging to Flow updates that the dispatcher has |
| 1003 | + * not started processing are excluded because those permits have not been added to the dispatcher total and must |
| 1004 | + * not be subtracted from it during removal. |
1004 | 1005 | * |
1005 | | - * <p>This accounting is enabled for persistent Shared and Key_Shared dispatchers. It relies on every dispatcher |
1006 | | - * Flow task calling {@link #completePendingDispatcherFlow(int)} before applying or ignoring the update. For these |
| 1006 | + * <p>This accounting is enabled for persistent Shared and Key_Shared dispatchers. It requires every dispatcher |
| 1007 | + * Flow update to call {@link #completePendingDispatcherFlow(int)} before applying or ignoring it. For these |
1007 | 1008 | * dispatchers, when observed under the dispatcher monitor, the total available permits equal the sum of this |
1008 | 1009 | * balance over all connected consumers. |
1009 | 1010 | * |
1010 | 1011 | * <p>The returned balance can be negative. A pending Flow makes permits visible on the consumer before its |
1011 | | - * asynchronous dispatcher update runs, so the dispatcher can consume those permits while they are still counted |
1012 | | - * as pending. Subtracting the negative balance during removal is required to restore the dispatcher total; callers |
1013 | | - * must not clamp it to zero. |
| 1012 | + * dispatcher update runs, so the dispatcher can consume those permits while they are still counted as pending. |
| 1013 | + * Subtracting the negative balance during removal is required to restore the dispatcher total; callers must not |
| 1014 | + * clamp it to zero. |
1014 | 1015 | */ |
1015 | 1016 | public int getAvailablePermitsForDispatcherRemoval() { |
1016 | 1017 | synchronized (flowPermitAccountingLock) { |
|