Class: FSR::Listener::Outbound
- Inherits:
-
EventMachine::Protocols::HeaderAndContentProtocol
- Object
- EventMachine::Protocols::HeaderAndContentProtocol
- FSR::Listener::Outbound
- Includes:
- App
- Defined in:
- lib/fsr/listener/outbound.rb
Constant Summary collapse
- SENDMSG_METHOD_DEFINITION =
Redefine the FSR::App methods to wrap sendmsg around them
[ "def %s(*args, &block)", " sendmsg super", " @queue.unshift(block_given? ? block : lambda {})", "end" ].join("\n")
Constants included from App
App::APPLICATIONS, App::LOAD_PATH, App::REGISTER_CODE
Instance Attribute Summary collapse
-
#session ⇒ Object
readonly
Returns the value of attribute session.
Instance Method Summary collapse
-
#api(command, &block) ⇒ Object
API.
- #next_step ⇒ Object
-
#receive_reply(reply) ⇒ Object
receive_reply is called when a response is received.
-
#sched_hangup(secs, &block) ⇒ Object
Scheduel Hangup.
-
#sendmsg(message) ⇒ Object
sendmsg sends data to the EM app socket via #send_data, or returns the string it would send if #send_data is not defined.
-
#session_initiated ⇒ Object
session_initiated is called when a @session is first created.
-
#update_session(&block) ⇒ Object
Update_session.
Methods included from App
#applications, list, load_all, load_application, register
Instance Attribute Details
#session ⇒ Object (readonly)
Returns the value of attribute session.
10 11 12 |
# File 'lib/fsr/listener/outbound.rb', line 10 def session @session end |
Instance Method Details
#api(command, &block) ⇒ Object
API
61 62 63 64 |
# File 'lib/fsr/listener/outbound.rb', line 61 def api(command, &block) send_data("api #{command}\r\n\r\n") @queue.unshift block if block_given? end |
#next_step ⇒ Object
80 81 82 83 |
# File 'lib/fsr/listener/outbound.rb', line 80 def next_step @step += 1 receive_reply(@session) end |
#receive_reply(reply) ⇒ Object
receive_reply is called when a response is received. Overwrite this in your worker class with the call/channel handling logic you desire, taking @step into account for state management between commands
45 46 47 |
# File 'lib/fsr/listener/outbound.rb', line 45 def receive_reply(reply) FSR::Log.debug reply.inspect end |
#sched_hangup(secs, &block) ⇒ Object
Scheduel Hangup
75 76 77 78 |
# File 'lib/fsr/listener/outbound.rb', line 75 def sched_hangup(secs, &block) send_data("api sched_hangup +#{secs} #{@session.headers[:unique_id]} alotted_timeout\n\n") @queue.unshift block if block_given? end |
#sendmsg(message) ⇒ Object
sendmsg sends data to the EM app socket via #send_data, or returns the string it would send if #send_data is not defined. It expects an object which responds to either #sendmsg or #to_s, which should return a EM Outbound Event Socket formatted instruction
54 55 56 57 58 |
# File 'lib/fsr/listener/outbound.rb', line 54 def sendmsg() text = .respond_to?(:sendmsg) ? .sendmsg : .to_s = "sendmsg\n%s\n" % text self.respond_to?(:send_data) ? send_data() : end |
#session_initiated ⇒ Object
session_initiated is called when a @session is first created. Overwrite this in your worker class with the call/channel handling logic you desire
34 35 36 37 |
# File 'lib/fsr/listener/outbound.rb', line 34 def session_initiated FSR::Log.warn "#{self.class.name}#session_initiated not overwritten" FSR::Log.debug session_data.inspect end |
#update_session(&block) ⇒ Object
Update_session
68 69 70 71 |
# File 'lib/fsr/listener/outbound.rb', line 68 def update_session(&block) send_data("api uuid_dump #{@session.headers[:unique_id]}\n\n") @queue.unshift block if block_given? end |