|
51 | 51 | import java.net.InetSocketAddress;
|
52 | 52 | import java.net.SocketAddress;
|
53 | 53 | import java.time.Duration;
|
| 54 | +import java.util.Queue; |
| 55 | +import java.util.concurrent.ConcurrentLinkedQueue; |
54 | 56 | import java.util.concurrent.CountDownLatch;
|
55 | 57 | import java.util.concurrent.ExecutionException;
|
56 | 58 | import java.util.concurrent.TimeUnit;
|
@@ -438,9 +440,42 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
|
438 | 440 | }
|
439 | 441 | }
|
440 | 442 |
|
| 443 | + private static class Event { |
| 444 | + private final long time; |
| 445 | + private final String label; |
| 446 | + |
| 447 | + public Event(long time, String label) { |
| 448 | + this.time = time; |
| 449 | + this.label = label; |
| 450 | + } |
| 451 | + |
| 452 | + @Override |
| 453 | + public String toString() { |
| 454 | + return this.label + " " + this.time; |
| 455 | + } |
| 456 | + } |
| 457 | + |
| 458 | + private static final int MAX_EVENTS = 100; |
| 459 | + private final Queue<Event> events = new ConcurrentLinkedQueue<>(); |
| 460 | + |
| 461 | + private void logEvents() { |
| 462 | + if (this.events.size() > 0) { |
| 463 | + long start = this.events.peek().time; |
| 464 | + LOGGER.info("channel writability history:"); |
| 465 | + events.forEach(e -> LOGGER.info("{}: {}", (e.time - start) / 1_000_000, e.label)); |
| 466 | + } |
| 467 | + } |
| 468 | + |
441 | 469 | @Override
|
442 | 470 | public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
|
443 | 471 | boolean canWrite = ctx.channel().isWritable();
|
| 472 | + Event event = new Event(System.nanoTime(), Boolean.toString(canWrite)); |
| 473 | + if (this.events.size() >= MAX_EVENTS) { |
| 474 | + this.events.poll(); |
| 475 | + this.events.offer(event); |
| 476 | + } |
| 477 | + this.events.add(event); |
| 478 | + |
444 | 479 | if (this.writable.compareAndSet(!canWrite, canWrite)) {
|
445 | 480 | if (canWrite) {
|
446 | 481 | CountDownLatch latch = writableLatch.getAndSet(new CountDownLatch(1));
|
|
0 commit comments