MessageQueue class
A queue for managing WebSocket messages with priority and retry support.
This queue provides reliable message delivery by storing messages when the connection is unavailable and processing them when the connection is restored. It supports priority-based ordering, message deduplication, and retry mechanisms.
Example:
final queue = MessageQueue(
maxSize: 1000,
enablePriority: true,
enableDeduplication: true,
);
final message = WebSocketMessage.text('Hello');
queue.enqueue(message);
Constructors
- MessageQueue({int maxSize = 1000, bool enablePriority = true, bool enableDeduplication = true})
- Creates a new MessageQueue.
-
MessageQueue.fromJson(Map<
String, dynamic> json) -
Creates a queue from JSON representation.
factory
Properties
- ackRequiredCount → int
-
Returns the number of messages that require acknowledgment.
no setter
-
ackRequiredMessages
→ List<
WebSocketMessage> -
Returns messages that require acknowledgment.
no setter
-
allMessages
→ List<
WebSocketMessage> -
Returns a copy of all messages in the queue.
no setter
- enableDeduplication → bool
-
Whether to enable message deduplication.
final
- enablePriority → bool
-
Whether to enable priority queuing.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- isEmpty → bool
-
Returns true if the queue is empty.
no setter
- isFull → bool
-
Returns true if the queue is full.
no setter
- maxSize → int
-
Maximum size of the queue.
final
- retryableCount → int
-
Returns the number of messages that can be retried.
no setter
-
retryableMessages
→ List<
WebSocketMessage> -
Returns messages that can be retried.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- size → int
-
Returns the current size of the queue.
no setter
Methods
-
clear(
) → void - Removes all messages from the queue.
-
dequeue(
) → WebSocketMessage? - Removes and returns the next message from the queue. Returns null if the queue is empty.
-
enqueue(
WebSocketMessage message) → bool - Adds a message to the queue. Returns true if the message was added successfully. Optimized for O(log n) insertion when priority is enabled.
-
getStatistics(
) → Map< String, dynamic> - Returns statistics about the queue.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
peek(
) → WebSocketMessage? - Returns the next message without removing it. Returns null if the queue is empty.
-
remove(
String messageId) → bool - Removes a specific message from the queue. Returns true if the message was found and removed.
-
toJson(
) → Map< String, dynamic> - Converts the queue to a JSON representation.
-
toString(
) → String -
A string representation of this object.
override
-
updateRetryCount(
String messageId) → bool - Updates the retry count for a message. Returns true if the message was found and updated.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited