Module: Gilmour::Base

Defined in:
lib/gilmour/base.rb

Overview

This is the base module that should be included into the container class

Defined Under Namespace

Modules: Registrar

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Class Attribute Details

.backendObject

Returns the value of attribute backend.



134
135
136
# File 'lib/gilmour/base.rb', line 134

def backend
  @backend
end

Instance Attribute Details

#backendsObject (readonly)

Returns the value of attribute backends.



136
137
138
# File 'lib/gilmour/base.rb', line 136

def backends
  @backends
end

Class Method Details

.included(base) ⇒ Object



33
34
35
# File 'lib/gilmour/base.rb', line 33

def self.included(base)
  base.extend(Registrar)
end

Instance Method Details

#enable_backend(name, opts = {}) ⇒ Object Also known as: get_backend

Enable and return the given backend Params

name

the backend name (currently only ‘redis’ is supported)

opts

backend specific options. Options for redis are

host

the redis server hostname

port

the redis server port

braodcast_errors

whether error reorting should be turned on

health_check

whether health_check hartbeats should be enabled



146
147
148
149
150
# File 'lib/gilmour/base.rb', line 146

def enable_backend(name, opts = {})
  Gilmour::Backend.load_backend(name)
  @backends ||= {}
  @backends[name] ||= Gilmour::Backend.get(name).new(opts)
end

#registered_subscribersObject

:nodoc:



128
129
130
# File 'lib/gilmour/base.rb', line 128

def registered_subscribers #:nodoc:
  self.class.registered_subscribers
end

#start(startloop = false) ⇒ Object

Starts all the listeners If startloop is true, this method will start it’s own event loop and not return till Eventmachine reactor is stopped Params:

startloop

If true this call with join the eventmachine thred and

block till it is done.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/gilmour/base.rb', line 170

def start(startloop = false)
  subs_by_backend = subs_grouped_by_backend
  subs_by_backend.each do |b, subs|
    backend = get_backend(b)
    subs.each do |topic, handlers|
      handlers.each do |handler|
        if handler[:type] == :slot
          backend.slot(topic, handler)
        elsif handler[:type] == :reply
          backend.reply_to(topic, handler)
        else
          backend.add_listener(topic, handler)
        end
      end
    end
    if backend.report_health?
      backend.register_health_check
    end
  end
  if startloop #Move into redis backend
    GLogger.debug 'Joining EM event loop'
    EM.reactor_thread.join
  end
end

#tear_down!Object

Cleanup the susbcribers and health checks



154
155
156
157
158
159
160
161
162
# File 'lib/gilmour/base.rb', line 154

def tear_down!
  subs_by_backend = subs_grouped_by_backend
  subs_by_backend.each do |b, subs|
    backend = get_backend(b)
    if backend.report_health?
      backend.unregister_health_check
    end
  end
end