Module: XKoon::Processor::ClassMethods
- Defined in:
- lib/xkoon/processor.rb
Overview
Class Methods: These are injected into the user’s processor implementation when this module is included.
Instance Method Summary collapse
-
#error_wrapper(p, h, m) ⇒ Array
Wrap in Error: Yields the given block, rescuing exceptions and throwing them back to the peer.
-
#handle_response(p, h, m) ⇒ Object
Handle Response: Called whenever a response is sent back from the remote peer.
-
#send_error(p, h, req, error) ⇒ Object
Respond with Error: Sends an error message to the Peer.
-
#send_request(p, h, r, m) ⇒ Object
Send Request: Sends a request to the Peer.
-
#send_response(p, h, req, res = {}, success = true) ⇒ Object
Send Generic Response Message: Sends a response message to the Peer.
Instance Method Details
#error_wrapper(p, h, m) ⇒ Array
Wrap in Error: Yields the given block, rescuing exceptions and throwing them back to the peer.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xkoon/processor.rb', line 50 def error_wrapper p, h, m failed = false out = nil begin out = yield rescue Exception => e send_error p, h, m, e failed = true end [failed, out] end |
#handle_response(p, h, m) ⇒ Object
Handle Response: Called whenever a response is sent back from the remote peer.
40 41 42 |
# File 'lib/xkoon/processor.rb', line 40 def handle_response p, h, m # NoOp - Provide your implementation end |
#send_error(p, h, req, error) ⇒ Object
Respond with Error: Sends an error message to the Peer.
69 70 71 |
# File 'lib/xkoon/processor.rb', line 69 def send_error p, h, req, error send_response p, h, req, { error: error }, false end |
#send_request(p, h, r, m) ⇒ Object
Send Request: Sends a request to the Peer.
31 32 33 |
# File 'lib/xkoon/processor.rb', line 31 def send_request p, h, r, m h.send_request p, r, m end |
#send_response(p, h, req, res = {}, success = true) ⇒ Object
Send Generic Response Message: Sends a response message to the Peer.
80 81 82 |
# File 'lib/xkoon/processor.rb', line 80 def send_response p, h, req, res = {}, success = true h.send_msg p, { success: success, req: req, res: res, sent: Time.now.to_i }.to_json end |