Class: Ably::Realtime::Channel::ChannelManager Private
- Inherits:
-
Object
- Object
- Ably::Realtime::Channel::ChannelManager
- Extended by:
- Forwardable
- Defined in:
- lib/ably/realtime/channel/channel_manager.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
ChannelManager is responsible for all actions relating to channel state: attaching, detaching or failure Channel state changes are performed by this class and executed from ChannelStateMachine
This is a private class and should never be used directly by developers as the API is likely to change in future.
Instance Method Summary collapse
-
#attach ⇒ Object
private
Commence attachment.
-
#attached(attached_protocol_message) ⇒ Object
private
Channel is attached, notify presence if sync is expected.
-
#detach(error = nil) ⇒ Object
private
Commence attachment.
- #drop_pending_queue_from_ack(ack_protocol_message) ⇒ Object private
-
#emit_error(error) ⇒ Object
private
An error has occurred on the channel.
-
#fail_messages_awaiting_ack(error) ⇒ Object
private
When a channel is no longer attached or has failed, all messages awaiting an ACK response should fail immediately.
- #fail_messages_in_queue(queue, error) ⇒ Object private
-
#initialize(channel, connection) ⇒ ChannelManager
constructor
private
A new instance of ChannelManager.
- #nack_messages(protocol_message, error) ⇒ Object private
-
#suspend(error) ⇒ Object
private
Detach a channel as a result of an error.
Constructor Details
#initialize(channel, connection) ⇒ ChannelManager
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of ChannelManager.
12 13 14 15 16 17 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 12 def initialize(channel, connection) @channel = channel @connection = connection setup_connection_event_handlers end |
Instance Method Details
#attach ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Commence attachment
20 21 22 23 24 25 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 20 def attach if can_transition_to?(:attached) connect_if_connection_initialized end end |
#attached(attached_protocol_message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Channel is attached, notify presence if sync is expected
37 38 39 40 41 42 43 44 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 37 def attached() if .has_presence_flag? channel.presence.manager.sync_expected else channel.presence.manager.sync_not_expected end channel.set_attached_serial .channel_serial end |
#detach(error = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Commence attachment
28 29 30 31 32 33 34 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 28 def detach(error = nil) if connection.closed? || connection.connecting? || connection.suspended? channel.transition_state_machine :detached, reason: error elsif can_transition_to?(:detached) end end |
#drop_pending_queue_from_ack(ack_protocol_message) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 93 94 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 86 def drop_pending_queue_from_ack() = . + .count - 1 connection..drop_while do || if . <= yield true end end end |
#emit_error(error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
An error has occurred on the channel
47 48 49 50 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 47 def emit_error(error) logger.error "ChannelManager: Channel '#{channel.name}' error: #{error}" channel.emit :error, error end |
#fail_messages_awaiting_ack(error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
When a channel is no longer attached or has failed, all messages awaiting an ACK response should fail immediately
59 60 61 62 63 64 65 66 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 59 def (error) # Allow a short time for other queued operations to complete before failing all messages EventMachine.add_timer(0.1) do error = Ably::Exceptions::MessageDeliveryFailed.new("Channel cannot publish messages whilst state is '#{channel.state}'") unless error connection., error connection., error end end |
#fail_messages_in_queue(queue, error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
68 69 70 71 72 73 74 75 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 68 def (queue, error) queue.delete_if do || if .channel == channel.name , error true end end end |
#nack_messages(protocol_message, error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
77 78 79 80 81 82 83 84 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 77 def (, error) (. + .presence).each do || logger.debug "Calling NACK failure callbacks for #{.class.name} - #{.to_json}, protocol message: #{}" .fail error end logger.debug "Calling NACK failure callbacks for #{.class.name} - #{.to_json}" .fail error end |
#suspend(error) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Detach a channel as a result of an error
53 54 55 |
# File 'lib/ably/realtime/channel/channel_manager.rb', line 53 def suspend(error) channel.transition_state_machine! :detaching, reason: error end |