Class: JSparrow::Connection::Provider
- Inherits:
-
Object
- Object
- JSparrow::Connection::Provider
- Defined in:
- lib/connection/provider.rb
Overview
Class for establish connection with JMS provider throught JNDI.
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(configuration, jndi_context_builder) ⇒ Provider
constructor
A new instance of Provider.
- #is_closed? ⇒ Boolean
- #is_opened? ⇒ Boolean
- #lookup_resource(jndi_name) ⇒ Object
- #lookup_resources(resources = {}) ⇒ Object
- #open ⇒ Object
Constructor Details
#initialize(configuration, jndi_context_builder) ⇒ Provider
Returns a new instance of Provider.
10 11 12 13 14 15 16 |
# File 'lib/connection/provider.rb', line 10 def initialize(configuration, jndi_context_builder) @configuration = configuration @jndi_context_builder = jndi_context_builder # Foi estabelecida? @opened = false end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
8 9 10 |
# File 'lib/connection/provider.rb', line 8 def configuration @configuration end |
Instance Method Details
#close ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/connection/provider.rb', line 38 def close raise InvalidStateError.new('closed', 'close') if is_closed? @jndi_context.close @opened = false end |
#is_closed? ⇒ Boolean
34 35 36 |
# File 'lib/connection/provider.rb', line 34 def is_closed? not @opened end |
#is_opened? ⇒ Boolean
18 19 20 |
# File 'lib/connection/provider.rb', line 18 def is_opened? @opened end |
#lookup_resource(jndi_name) ⇒ Object
58 59 60 |
# File 'lib/connection/provider.rb', line 58 def lookup_resource(jndi_name) @jndi_context.lookup(jndi_name) end |
#lookup_resources(resources = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/connection/provider.rb', line 46 def lookup_resources(resources = {}) lookuped_resource = {} return lookuped_resource unless resources resources.each do |name, jndi_name| lookuped_resource[name] = lookup_resource(jndi_name) end lookuped_resource end |
#open ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/connection/provider.rb', line 22 def open raise InvalidStateError.new('opened', 'open') if is_opened? begin @jndi_context = @jndi_context_builder.build rescue => cause raise InitializationError.new(@configuration, cause) end @opened = true end |