Module: Qwirk::Remote

Defined in:
lib/qwirk/remote.rb,
lib/qwirk/remote/client.rb,
lib/qwirk/remote/worker.rb

Defined Under Namespace

Classes: Client, Worker

Class Method Summary collapse

Class Method Details

.adapter_factoryObject



32
33
34
# File 'lib/qwirk/remote.rb', line 32

def self.adapter_factory
  @@adapter_factory
end

.default_nameObject



52
53
54
55
56
# File 'lib/qwirk/remote.rb', line 52

def self.default_name
  require 'socket'
  name = Socket.gethostname
  name.sub(/\..*/, '')
end

.nameObject



36
37
38
# File 'lib/qwirk/remote.rb', line 36

def self.name
  @@name
end

.queue_name(name) ⇒ Object



44
45
46
# File 'lib/qwirk/remote.rb', line 44

def self.queue_name(name)
  "Remote_#{name}"
end

.remote_name(worker_name) ⇒ Object



58
59
60
# File 'lib/qwirk/remote.rb', line 58

def self.remote_name(worker_name)
  worker_name.sub(/^[QT]Remote_/, '')
end

.root_beanObject



48
49
50
# File 'lib/qwirk/remote.rb', line 48

def self.root_bean
  @@root_bean
end

.setup(adapter_factory, options = {}) ⇒ Object

Setup the remote worker with a unique name with which to identify this particular process. This defaults to the simple hostname (minus the domain name) which can be used if their is only one qwirk_manager running on this host, otherwise it should be some combination of the hostname and process name or anything that would uniquely identify the process/host combination. Options:

name - overrides the default name for this process/host combination.
topic_name - name of the topic.  This should be the same for all process/host combinations and
             defaults to 'remote'


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qwirk/remote.rb', line 12

def self.setup(adapter_factory, options={})
  require 'qwirk/remote/client'
  require 'qwirk/remote/worker'

  options = options.dup
  @@adapter_factory = adapter_factory
  @@name            = options.delete(:name) || default_name
  @@topic_name      = options.delete(:topic_name) || 'remote'
  @@queue_name      = self.queue_name(@@name)
  @@root_bean_name  = options.delete(:root_bean_name) || @@topic_name
  default_options   = {:min_count => 1, :max_count => 1}
  Worker.define_configs(
      "TRemote_#{@@name}" => default_options.merge(:topic_name => @@topic_name).merge(options),
      "QRemote_#{@@name}" => default_options.merge(:queue_name => @@queue_name).merge(options)
  )
  client = Client.new(adapter_factory, options)
  @@root_bean = Rumx::Bean.add_root(@@root_bean_name, ::Rumx::Beans::Folder.new)
  @@root_bean.bean_add_child(:client, client)
end

.topic_nameObject



40
41
42
# File 'lib/qwirk/remote.rb', line 40

def self.topic_name
  @@topic_name
end