Class: ZSS::Service
- Inherits:
-
Object
- Object
- ZSS::Service
- Includes:
- LoggerFacade::Loggable
- Defined in:
- lib/zss/service.rb
Instance Attribute Summary collapse
-
#backend ⇒ Object
readonly
Returns the value of attribute backend.
-
#heartbeat ⇒ Object
readonly
Returns the value of attribute heartbeat.
-
#identity ⇒ Object
readonly
Returns the value of attribute identity.
-
#sid ⇒ Object
readonly
Returns the value of attribute sid.
Instance Method Summary collapse
- #add_route(context, route, handler = nil) ⇒ Object
-
#initialize(sid, config = {}) ⇒ Service
constructor
A new instance of Service.
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(sid, config = {}) ⇒ Service
Returns a new instance of Service.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/zss/service.rb', line 13 def initialize(sid, config = {}) fail Error[500] if sid.blank? @sid = sid.to_s.upcase @heartbeat = config.try(:heartbeat) || 1000 @backend = config.try(:backend) || Configuration.default.backend @router = ZSS::Router.new @identity = "#{sid}##{SecureRandom.uuid}" end |
Instance Attribute Details
#backend ⇒ Object (readonly)
Returns the value of attribute backend.
11 12 13 |
# File 'lib/zss/service.rb', line 11 def backend @backend end |
#heartbeat ⇒ Object (readonly)
Returns the value of attribute heartbeat.
11 12 13 |
# File 'lib/zss/service.rb', line 11 def heartbeat @heartbeat end |
#identity ⇒ Object (readonly)
Returns the value of attribute identity.
11 12 13 |
# File 'lib/zss/service.rb', line 11 def identity @identity end |
#sid ⇒ Object (readonly)
Returns the value of attribute sid.
11 12 13 |
# File 'lib/zss/service.rb', line 11 def sid @sid end |
Instance Method Details
#add_route(context, route, handler = nil) ⇒ Object
34 35 36 |
# File 'lib/zss/service.rb', line 34 def add_route(context, route, handler = nil) router.add(context, route, handler) end |
#run ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/zss/service.rb', line 24 def run Thread.abort_on_exception = true context = EM::ZeroMQ::Context.new(1) fail RuntimeError, 'failed to create create_context' unless context log.info("Starting SID: '#{sid}' ID: '#{identity}' Env: '#{ZSS::Environment.env}' Broker: '#{backend}'") event_machine_start(context) end |