|
1 |
| -// Copyright (c) 2020-2021 VMware, Inc. or its affiliates. All rights reserved. |
| 1 | +// Copyright (c) 2020-2022 VMware, Inc. or its affiliates. All rights reserved. |
2 | 2 | //
|
3 | 3 | // This software, the RabbitMQ Stream Java client library, is dual-licensed under the
|
4 | 4 | // Mozilla Public License 2.0 ("MPL"), and the Apache License version 2 ("ASL").
|
|
36 | 36 | import java.util.List;
|
37 | 37 | import java.util.Map;
|
38 | 38 | import java.util.Map.Entry;
|
| 39 | +import java.util.Objects; |
39 | 40 | import java.util.SortedMap;
|
40 | 41 | import java.util.TreeMap;
|
41 | 42 | import java.util.concurrent.ConcurrentHashMap;
|
|
52 | 53 |
|
53 | 54 | class StreamProducer implements Producer {
|
54 | 55 |
|
| 56 | + private static final AtomicLong ID_SEQUENCE = new AtomicLong(0); |
| 57 | + |
55 | 58 | private static final Logger LOGGER = LoggerFactory.getLogger(StreamProducer.class);
|
56 | 59 | private static final ConfirmationHandler NO_OP_CONFIRMATION_HANDLER = confirmationStatus -> {};
|
| 60 | + private final long id; |
57 | 61 | private final MessageAccumulator accumulator;
|
58 | 62 | // FIXME investigate a more optimized data structure to handle pending messages
|
59 | 63 | private final ConcurrentMap<Long, AccumulatedEntity> unconfirmedMessages;
|
@@ -87,6 +91,7 @@ class StreamProducer implements Producer {
|
87 | 91 | Duration confirmTimeout,
|
88 | 92 | Duration enqueueTimeout,
|
89 | 93 | StreamEnvironment environment) {
|
| 94 | + this.id = ID_SEQUENCE.getAndIncrement(); |
90 | 95 | this.environment = environment;
|
91 | 96 | this.name = name;
|
92 | 97 | this.stream = stream;
|
@@ -479,4 +484,36 @@ interface ConfirmationCallback {
|
479 | 484 |
|
480 | 485 | int handle(boolean confirmed, short code);
|
481 | 486 | }
|
| 487 | + |
| 488 | + @Override |
| 489 | + public boolean equals(Object o) { |
| 490 | + if (this == o) { |
| 491 | + return true; |
| 492 | + } |
| 493 | + if (o == null || getClass() != o.getClass()) { |
| 494 | + return false; |
| 495 | + } |
| 496 | + StreamProducer that = (StreamProducer) o; |
| 497 | + return id == that.id && stream.equals(that.stream); |
| 498 | + } |
| 499 | + |
| 500 | + @Override |
| 501 | + public int hashCode() { |
| 502 | + return Objects.hash(id, stream); |
| 503 | + } |
| 504 | + |
| 505 | + @Override |
| 506 | + public String toString() { |
| 507 | + Client client = this.client; |
| 508 | + return "{ " |
| 509 | + + "\"id\" : " |
| 510 | + + id |
| 511 | + + "," |
| 512 | + + "\"stream\" : \"" |
| 513 | + + stream |
| 514 | + + "\"," |
| 515 | + + "\"publishing_client\" : " |
| 516 | + + (client == null ? "null" : ("\"" + client.connectionName() + "\"")) |
| 517 | + + "}"; |
| 518 | + } |
482 | 519 | }
|
0 commit comments