Module: Nutella::Net
- Defined in:
- lib/nutella_lib/net.rb
Overview
This module implements the pub/sub and request/response APIs at the run level
Class Method Summary collapse
-
.async_request(channel, message = nil, callback) ⇒ Object
Performs an asynchronous request.
-
.callbacks ⇒ Object
Provides access to callbacks.
-
.handle_requests(channel, callback) ⇒ Object
Handles requests on a certain channel.
-
.listen ⇒ Object
Listens for incoming messages.
-
.publish(channel, message = nil) ⇒ Object
Publishes a message to a channel.
-
.start_pinging ⇒ Object
Sends a ping every 5 seconds to pings channel of the proper level.
-
.subscribe(channel, callback) ⇒ Object
Subscribes to a channel or to a set of channels.
-
.subscriptions ⇒ Object
Provides access to the subscriptions.
-
.sync_request(channel, message = nil) ⇒ Object
Performs a synchronous request.
-
.unsubscribe(channel) ⇒ Object
Un-subscribes from a channel.
Class Method Details
.async_request(channel, message = nil, callback) ⇒ Object
Performs an asynchronous request
64 65 66 |
# File 'lib/nutella_lib/net.rb', line 64 def self.async_request( channel, =nil, callback ) async_request_to(channel, , callback, Nutella.app_id, Nutella.run_id) end |
.callbacks ⇒ Object
Provides access to callbacks
14 |
# File 'lib/nutella_lib/net.rb', line 14 def self.callbacks; @callbacks end |
.handle_requests(channel, callback) ⇒ Object
Handles requests on a certain channel
78 79 80 |
# File 'lib/nutella_lib/net.rb', line 78 def self.handle_requests( channel, callback ) handle_requests_on(channel, callback, Nutella.app_id, Nutella.run_id) end |
.listen ⇒ Object
Listens for incoming messages. All this function does is to put the thread to sleep and wait for something to happen over the network to wake up.
99 100 101 102 103 104 105 |
# File 'lib/nutella_lib/net.rb', line 99 def self.listen begin sleep rescue Interrupt # Simply returns once interrupted end end |
.publish(channel, message = nil) ⇒ Object
Publishes a message to a channel
43 44 45 |
# File 'lib/nutella_lib/net.rb', line 43 def self.publish( channel, =nil ) publish_to( channel, , Nutella.app_id, Nutella.run_id) end |
.start_pinging ⇒ Object
Sends a ping every 5 seconds to pings channel of the proper level
86 87 88 89 90 91 92 93 |
# File 'lib/nutella_lib/net.rb', line 86 def self.start_pinging Nutella.ping_thread = Thread.new do loop do publish_to('pings', 'ping', Nutella.app_id, Nutella.run_id) sleep(5) end end end |
.subscribe(channel, callback) ⇒ Object
Subscribes to a channel or to a set of channels.
25 26 27 |
# File 'lib/nutella_lib/net.rb', line 25 def self.subscribe( channel, callback ) subscribe_to( channel, callback, Nutella.app_id, Nutella.run_id) end |
.subscriptions ⇒ Object
Provides access to the subscriptions
11 |
# File 'lib/nutella_lib/net.rb', line 11 def self.subscriptions; @subscriptions end |
.sync_request(channel, message = nil) ⇒ Object
Performs a synchronous request.
53 54 55 |
# File 'lib/nutella_lib/net.rb', line 53 def self.sync_request( channel, =nil ) sync_request_to(channel, , Nutella.app_id, Nutella.run_id) end |
.unsubscribe(channel) ⇒ Object
Un-subscribes from a channel
33 34 35 |
# File 'lib/nutella_lib/net.rb', line 33 def self.unsubscribe( channel ) unsubscribe_to( channel, Nutella.app_id, Nutella.run_id) end |