Class: JSparrow::Connection::Client
- Inherits:
-
Object
- Object
- JSparrow::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 Method Summary collapse
- #enable_queues(jndi_names = {}) ⇒ Object
- #enable_topics(jndi_names = {}) ⇒ Object
-
#initialize(connection_properties, jndi_context_builder) ⇒ Client
constructor
A new instance of Client.
- #is_started? ⇒ Boolean
- #is_stoped? ⇒ Boolean
- #queue(queue_name) ⇒ Object
- #queue_connection_factory ⇒ Object
- #queue_connection_factory_enabled? ⇒ Boolean
- #queue_enabled?(queue_name) ⇒ Boolean
- #queue_receiver(queue_name) ⇒ Object
- #queue_sender(queue_name) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #topic(topic_name) ⇒ Object
- #topic_connection_factory ⇒ Object
- #topic_connection_factory_enabled? ⇒ Boolean
- #topic_enabled?(topic_name) ⇒ Boolean
- #topic_receiver(topic_name) ⇒ Object
- #topic_sender(topic_name) ⇒ Object
Constructor Details
#initialize(connection_properties, jndi_context_builder) ⇒ Client
Returns a new instance of Client.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/connection.rb', line 67 def initialize(connection_properties, jndi_context_builder) @connection_properties = connection_properties @jndi_context_builder = jndi_context_builder @jndi_name_of_enabled_connection_factories = @connection_properties.enabled_connection_factories @jndi_name_of_enabled_queues = {} @jndi_name_of_enabled_topics = {} # Conexoes, filas, topicos, senders e receivers que serao habilitados @connection_factories = {} @queues = {} @queue_senders = {} @queue_receivers = {} @topics = {} @topic_senders = {} @topic_receivers = {} # Foi startado? @started = false end |
Instance Method Details
#enable_queues(jndi_names = {}) ⇒ Object
136 137 138 139 140 |
# File 'lib/connection.rb', line 136 def enable_queues(jndi_names = {}) raise InvalidClientStateError.new('started', 'enable_queues') if is_started? @jndi_name_of_enabled_queues = jndi_names end |
#enable_topics(jndi_names = {}) ⇒ Object
162 163 164 165 166 |
# File 'lib/connection.rb', line 162 def enable_topics(jndi_names = {}) raise InvalidClientStateError.new('started', 'enable_topics') if is_started? @jndi_name_of_enabled_topics = jndi_names end |
#is_started? ⇒ Boolean
88 89 90 |
# File 'lib/connection.rb', line 88 def is_started? @started end |
#is_stoped? ⇒ Boolean
108 109 110 |
# File 'lib/connection.rb', line 108 def is_stoped? !@started end |
#queue(queue_name) ⇒ Object
146 147 148 149 150 |
# File 'lib/connection.rb', line 146 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
124 125 126 |
# File 'lib/connection.rb', line 124 def queue_connection_factory @connection_factories[:queue_connection_factory] end |
#queue_connection_factory_enabled? ⇒ Boolean
120 121 122 |
# File 'lib/connection.rb', line 120 def queue_connection_factory_enabled? @jndi_name_of_enabled_connection_factories.include?(:queue_connection_factory) end |
#queue_enabled?(queue_name) ⇒ Boolean
142 143 144 |
# File 'lib/connection.rb', line 142 def queue_enabled?(queue_name) @jndi_name_of_enabled_queues.include?(queue_name) end |
#queue_receiver(queue_name) ⇒ Object
157 158 159 160 |
# File 'lib/connection.rb', line 157 def queue_receiver(queue_name) @queue_receivers[queue_name] ||= Messaging::Receiver.new(queue_connection_factory, queue(queue_name)) end |
#queue_sender(queue_name) ⇒ Object
152 153 154 155 |
# File 'lib/connection.rb', line 152 def queue_sender(queue_name) @queue_senders[queue_name] ||= Messaging::Sender.new(queue_connection_factory, queue(queue_name)) end |
#start ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/connection.rb', line 92 def start raise InvalidClientStateError.new('started', 'start') if is_started? begin @jndi_context = @jndi_context_builder.build rescue => cause raise ClientInitializationError.new(@connection_properties, cause) end @connection_factories = lookup_resource(@jndi_name_of_enabled_connection_factories) @queues = lookup_resource(@jndi_name_of_enabled_queues) @topics = lookup_resource(@jndi_name_of_enabled_topics) @started = true end |
#stop ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/connection.rb', line 112 def stop raise InvalidClientStateError.new('stoped', 'stop') if is_stoped? @jndi_context.close @started = false end |
#topic(topic_name) ⇒ Object
172 173 174 175 176 |
# File 'lib/connection.rb', line 172 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
132 133 134 |
# File 'lib/connection.rb', line 132 def topic_connection_factory @connection_factories[:topic_connection_factory] end |
#topic_connection_factory_enabled? ⇒ Boolean
128 129 130 |
# File 'lib/connection.rb', line 128 def topic_connection_factory_enabled? @jndi_name_of_enabled_connection_factories.include?(:topic_connection_factory) end |
#topic_enabled?(topic_name) ⇒ Boolean
168 169 170 |
# File 'lib/connection.rb', line 168 def topic_enabled?(topic_name) @jndi_name_of_enabled_topics.include?(topic_name) end |