Class: Sparrow::JMS::Connection::Client
- Inherits:
-
Object
- Object
- Sparrow::JMS::Connection::Client
- Defined in:
- lib/connection.rb
Overview
Cliente JMS que possibilita a conexao com o servidor de aplicacoes Java EE que prove o servico JMS.
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
- #enable_connection_factories(jndi_names = {}) ⇒ Object
- #enable_queues(jndi_names = {}) ⇒ Object
- #enable_topics(jndi_names = {}) ⇒ Object
-
#initialize(&configurator) ⇒ Client
constructor
A new instance of Client.
- #queue(queue_name) ⇒ Object
- #queue_connection_factory ⇒ Object
- #queue_enabled?(queue_name) ⇒ Boolean
- #queue_receiver(queue_name) ⇒ Object
- #queue_sender(queue_name) ⇒ Object
- #topic(topic_name) ⇒ Object
- #topic_connection_factory ⇒ Object
- #topic_enabled?(topic_name) ⇒ Boolean
- #topic_receiver(topic_name) ⇒ Object
- #topic_sender(topic_name) ⇒ Object
Constructor Details
#initialize(&configurator) ⇒ Client
Returns a new instance of Client.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/connection.rb', line 57 def initialize(&configurator) @properties = Properties.new begin configurator.call(@properties) @jndi_context = properties.build_jndi_context rescue => cause raise ClientInitializationError.new(@properties, cause) end # Conexoes, filas, topicos, senders e receivers que serao habilitados @connection_factories = {} @queues = {} @queue_senders = {} @queue_receivers = {} @topics = {} @topic_senders = {} @topic_receivers = {} end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
55 56 57 |
# File 'lib/connection.rb', line 55 def properties @properties end |
Instance Method Details
#enable_connection_factories(jndi_names = {}) ⇒ Object
78 79 80 81 82 |
# File 'lib/connection.rb', line 78 def enable_connection_factories(jndi_names={}) jndi_names.each_pair do |key, jndi_name| @connection_factories[key] = @jndi_context.lookup(jndi_name) end end |
#enable_queues(jndi_names = {}) ⇒ Object
92 93 94 95 96 |
# File 'lib/connection.rb', line 92 def enable_queues(jndi_names={}) jndi_names.each do |key, jndi_name| @queues[key] = @jndi_context.lookup(jndi_name) end end |
#enable_topics(jndi_names = {}) ⇒ Object
118 119 120 121 122 |
# File 'lib/connection.rb', line 118 def enable_topics(jndi_names={}) jndi_names.each do |key, jndi_name| @topics[key] = @jndi_context.lookup(jndi_name) end end |
#queue(queue_name) ⇒ Object
102 103 104 105 106 |
# File 'lib/connection.rb', line 102 def queue(queue_name) raise NameError, "Queue '#{queue_name}' does not exist." unless queue_enabled?(queue_name) @queues[queue_name] end |
#queue_connection_factory ⇒ Object
84 85 86 |
# File 'lib/connection.rb', line 84 def queue_connection_factory @connection_factories[:queue_connection_factory] end |
#queue_enabled?(queue_name) ⇒ Boolean
98 99 100 |
# File 'lib/connection.rb', line 98 def queue_enabled?(queue_name) @queues.include?(queue_name) end |
#queue_receiver(queue_name) ⇒ Object
113 114 115 116 |
# File 'lib/connection.rb', line 113 def queue_receiver(queue_name) @queue_receivers[queue_name] ||= Messaging::Receiver.new(queue_connection_factory, queue(queue_name)) end |
#queue_sender(queue_name) ⇒ Object
108 109 110 111 |
# File 'lib/connection.rb', line 108 def queue_sender(queue_name) @queue_senders[queue_name] ||= Messaging::Sender.new(queue_connection_factory, queue(queue_name)) end |
#topic(topic_name) ⇒ Object
128 129 130 131 132 |
# File 'lib/connection.rb', line 128 def topic(topic_name) raise NameError, "Topic '#{topic_name}' does not exist." unless topic_enabled?(topic_name) @topics[topic_name] end |
#topic_connection_factory ⇒ Object
88 89 90 |
# File 'lib/connection.rb', line 88 def topic_connection_factory @connection_factories[:topic_connection_factory] end |
#topic_enabled?(topic_name) ⇒ Boolean
124 125 126 |
# File 'lib/connection.rb', line 124 def topic_enabled?(topic_name) @topics.include?(topic_name) end |