Class: Fabriq::SkypeProxy
- Inherits:
-
Object
- Object
- Fabriq::SkypeProxy
- Defined in:
- lib/fabriq/skype_proxy.rb
Instance Attribute Summary collapse
-
#adapter ⇒ Object
Returns the value of attribute adapter.
-
#outgoing_messages ⇒ Object
Returns the value of attribute outgoing_messages.
Instance Method Summary collapse
- #handle_incoming_messages_synchronized ⇒ Object
- #handle_outgoing_messages_synchronized ⇒ Object
-
#initialize(adapter) ⇒ SkypeProxy
constructor
A new instance of SkypeProxy.
- #invoke_incoming_message_subscribers(message) ⇒ Object
- #on_incoming_message(&callback) ⇒ Object
- #start ⇒ Object
- #start_incoming_queue_worker ⇒ Object
- #start_outgoing_queue_worker ⇒ Object
- #start_queue_worker_threads ⇒ Object
- #subscribe_adapter_message_received ⇒ Object
Constructor Details
#initialize(adapter) ⇒ SkypeProxy
Returns a new instance of SkypeProxy.
6 7 8 9 10 11 12 |
# File 'lib/fabriq/skype_proxy.rb', line 6 def initialize(adapter) @adapter = adapter @incoming_mutex = Mutex.new @outgoing_mutex = Mutex.new @incoming_message_callbacks = [] @outgoing_messages = [] end |
Instance Attribute Details
#adapter ⇒ Object
Returns the value of attribute adapter.
4 5 6 |
# File 'lib/fabriq/skype_proxy.rb', line 4 def adapter @adapter end |
#outgoing_messages ⇒ Object
Returns the value of attribute outgoing_messages.
4 5 6 |
# File 'lib/fabriq/skype_proxy.rb', line 4 def @outgoing_messages end |
Instance Method Details
#handle_incoming_messages_synchronized ⇒ Object
47 48 49 50 51 |
# File 'lib/fabriq/skype_proxy.rb', line 47 def @incoming_mutex.synchronize do (@received_messages.shift) end end |
#handle_outgoing_messages_synchronized ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/fabriq/skype_proxy.rb', line 53 def @outgoing_mutex.synchronize do if @outgoing_messages.count > 0 = @outgoing_messages.shift @adapter.() end end end |
#invoke_incoming_message_subscribers(message) ⇒ Object
62 63 64 65 66 |
# File 'lib/fabriq/skype_proxy.rb', line 62 def () @incoming_message_callbacks.each do |callback| run_in_thread { callback.call() } end end |
#on_incoming_message(&callback) ⇒ Object
14 15 16 |
# File 'lib/fabriq/skype_proxy.rb', line 14 def (&callback) @incoming_message_callbacks << callback end |
#start ⇒ Object
25 26 27 28 |
# File 'lib/fabriq/skype_proxy.rb', line 25 def start start_queue_worker_threads end |
#start_incoming_queue_worker ⇒ Object
35 36 37 38 39 |
# File 'lib/fabriq/skype_proxy.rb', line 35 def start_incoming_queue_worker run_in_throttled_loop do end end |
#start_outgoing_queue_worker ⇒ Object
41 42 43 44 45 |
# File 'lib/fabriq/skype_proxy.rb', line 41 def start_outgoing_queue_worker run_in_throttled_loop do end end |
#start_queue_worker_threads ⇒ Object
30 31 32 33 |
# File 'lib/fabriq/skype_proxy.rb', line 30 def start_queue_worker_threads run_in_thread { start_incoming_queue_worker } run_in_thread { start_outgoing_queue_worker } end |
#subscribe_adapter_message_received ⇒ Object
18 19 20 21 22 23 |
# File 'lib/fabriq/skype_proxy.rb', line 18 def @received_messages = [] @adapter. do || @received_messages << end end |