Class: Qwirk::AdapterFactory

Inherits:
Object
  • Object
show all
Includes:
Rumx::Bean
Defined in:
lib/qwirk/adapter_factory.rb

Overview

Defines the queuing adapter. Currently, only JMS and InMemory.

Constant Summary collapse

@@adapter_hash =
{}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, config) ⇒ AdapterFactory

Returns a new instance of AdapterFactory.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/qwirk/adapter_factory.rb', line 18

def initialize(key, config)
  @key       = key
  @config    = config.dup
  @log_times = config.delete(:log_times)

  key = config.delete(:adapter)
  raise "No adapter definition config=#{config.inspect}" unless key
  key = key.to_sym
  @publisher_class, @worker_config_class, block = @@adapter_hash[key]
  raise "No adapter matching #{key}" unless @publisher_class
  self.remote = config.delete(:remote)
  @adapter_info = block.call(config) if block
end

Instance Attribute Details

#adapter_infoObject (readonly)

Returns the value of attribute adapter_info.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def adapter_info
  @adapter_info
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def config
  @config
end

#keyObject (readonly)

Returns the value of attribute key.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def key
  @key
end

#log_timesObject (readonly)

Returns the value of attribute log_times.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def log_times
  @log_times
end

#managerObject (readonly)

Returns the value of attribute manager.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def manager
  @manager
end

#worker_config_classObject (readonly)

Returns the value of attribute worker_config_class.



7
8
9
# File 'lib/qwirk/adapter_factory.rb', line 7

def worker_config_class
  @worker_config_class
end

Class Method Details

.register(key, publisher_class, worker_config_class, &block) ⇒ Object

Register an adapter by passing in a publisher_class, a worker_config_class and optionally a code block. The code block will expect a config object as it’s argument and will return connection information or any other client_information required for this adapter.



14
15
16
# File 'lib/qwirk/adapter_factory.rb', line 14

def self.register(key, publisher_class, worker_config_class, &block)
  @@adapter_hash[key] = [publisher_class, worker_config_class, block]
end

Instance Method Details

#create_manager(options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/qwirk/adapter_factory.rb', line 39

def create_manager(options={})
  @manager = Manager.new(self, @config.merge(options))
  bean_add_child(:Workers, @manager)
  return @manager
end

#create_publisher(options = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/qwirk/adapter_factory.rb', line 32

def create_publisher(options={})
  @publisher_parent ||= ::Rumx::Beans::Folder.new
  publisher = Publisher.new(self, @config.merge(options))
  @publisher_parent.bean_add_child(publisher.to_s, publisher)
  return publisher
end

#create_publisher_impl(queue_name, topic_name, options, response_options) ⇒ Object



45
46
47
# File 'lib/qwirk/adapter_factory.rb', line 45

def create_publisher_impl(queue_name, topic_name, options, response_options)
  @publisher_class.new(self, queue_name, topic_name, options, response_options)
end

#in_process?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/qwirk/adapter_factory.rb', line 49

def in_process?
  @worker_config_class.in_process?(@config)
end

#remote=(remote_options) ⇒ Object



53
54
55
56
57
# File 'lib/qwirk/adapter_factory.rb', line 53

def remote=(remote_options)
  # If remote was just set to true, then create an empty options hash for it
  remote_options = {} if remote_options == true
  Remote.setup(self, remote_options) if remote_options
end