Class: TorqueBox::Messaging::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/torquebox/messaging/dispatcher.rb

Overview

A service that may be configured with mappings of message consumers to destinations

Instance Method Summary collapse

Constructor Details

#initialize(options = {}, &block) ⇒ Dispatcher

Returns a new instance of Dispatcher.



30
31
32
33
# File 'lib/torquebox/messaging/dispatcher.rb', line 30

def initialize(options = {}, &block)
  @options = options
  instance_eval &block if block_given?
end

Instance Method Details

#map(consumer, destination, options = {}) ⇒ Object

Option keys are :filter and :config, either as symbol or string



36
37
38
39
40
41
# File 'lib/torquebox/messaging/dispatcher.rb', line 36

def map consumer, destination, options = {}
  options = options.inject({}) {|h,(k,v)| h[k.to_s]=v; h} # jruby won't convert symbols to strings
  processor = org.torquebox.messaging.deployers::MessagingYamlParsingDeployer::Parser.subscribe(consumer.to_s, destination.to_s, options)
  processor.ruby_require_path = nil if consumer.is_a? Class
  processors << processor
end

#processorsObject



63
64
65
# File 'lib/torquebox/messaging/dispatcher.rb', line 63

def processors
  @processors ||= []
end

#startObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/torquebox/messaging/dispatcher.rb', line 43

def start
  container.start
  @deployment = container.deploy( object_id.to_s )
  unit = container.deployment_unit( @deployment.name )
  processors.each do |processor|
    org.torquebox.mc::AttachmentUtils.multipleAttach( unit, processor, processor.name )
  end
  app_meta = org.torquebox.base.::RubyApplicationMetaData.new
  app_meta.setApplicationName( "none" )
  app_meta.setEnvironmentName( ENV['TORQUEBOX_ENV'] || 'development' )
  app_meta.setRoot( org.jboss.vfs::VFS.getChild( Dir.pwd ) )
  unit.addAttachment( org.torquebox.base.::RubyApplicationMetaData.java_class, app_meta )
  container.process_deployments(true)
end

#stopObject



58
59
60
61
# File 'lib/torquebox/messaging/dispatcher.rb', line 58

def stop
  container.undeploy( @deployment )
  container.stop
end