|
8 | 8 | import java.util.Collection; |
9 | 9 | import java.util.EnumSet; |
10 | 10 | import java.util.List; |
| 11 | +import java.util.Objects; |
11 | 12 | import java.util.concurrent.ArrayBlockingQueue; |
12 | 13 | import java.util.concurrent.BlockingQueue; |
13 | 14 | import java.util.concurrent.CancellationException; |
@@ -409,7 +410,7 @@ void setState(State nextState) { |
409 | 410 | State prev = state; |
410 | 411 | state = nextState; |
411 | 412 | state.onEnter(prev); |
412 | | - stateChanged.signal(); |
| 413 | + stateChanged.signalAll(); |
413 | 414 | } finally { |
414 | 415 | lock.unlock(); |
415 | 416 | } |
@@ -726,18 +727,21 @@ private void onAcks(Event.Acks acks) { |
726 | 727 | if (!acks.acked().containsAll(removed)) { |
727 | 728 | throw ProtocolViolationException.incompleteAcks(List.copyOf(removed)); |
728 | 729 | } |
729 | | - acks.acked().forEach(id -> { |
730 | | - TaskHandle task = wip.get(id); |
731 | | - if (task != null) { |
732 | | - task.setAcked(); |
733 | | - } |
734 | | - }); |
| 730 | + acks.acked().stream() |
| 731 | + .map(wip::get).filter(Objects::nonNull) |
| 732 | + .forEach(TaskHandle::setAcked); |
| 733 | + |
735 | 734 | setState(ACTIVE); |
736 | 735 | } |
737 | 736 |
|
738 | 737 | private void onResults(Event.Results results) { |
739 | | - results.successful().forEach(id -> wip.remove(id).setSuccess()); |
740 | | - results.errors().forEach((id, error) -> wip.remove(id).setError(error)); |
| 738 | + results.successful().stream() |
| 739 | + .map(wip::remove).filter(Objects::nonNull) |
| 740 | + .forEach(TaskHandle::setSuccess); |
| 741 | + |
| 742 | + results.errors().keySet().stream() |
| 743 | + .map(wip::remove).filter(Objects::nonNull) |
| 744 | + .forEach(taskHandle -> taskHandle.setError(results.errors().get(taskHandle.id()))); |
741 | 745 | } |
742 | 746 |
|
743 | 747 | private void onBackoff(Event.Backoff backoff) { |
@@ -916,7 +920,7 @@ public void onEvent(Event event) { |
916 | 920 | if (retries == maxRetries) { |
917 | 921 | onEvent(new Event.ClientError(new IOException("Server unavailable"))); |
918 | 922 | } else { |
919 | | - reconnectAfter(2 ^ retries); |
| 923 | + reconnectAfter((long) Math.pow(2, retries)); |
920 | 924 | } |
921 | 925 | } else if (event == Event.EOF) { |
922 | 926 | throw ProtocolViolationException.illegalStateTransition(this, event); |
|
0 commit comments