Class: JSparrow::Connection::Base
- Inherits:
-
Object
- Object
- JSparrow::Connection::Base
- Defined in:
- lib/connection.rb
Overview
Classe base para estabelecer conexao com o provedor JMS via 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) ⇒ Base
constructor
A new instance of Base.
- #is_closed? ⇒ Boolean
- #is_opened? ⇒ Boolean
- #lookup_resource(jndi_name) ⇒ Object
- #lookup_resources(resources = {}) ⇒ Object
- #open ⇒ Object
Constructor Details
#initialize(configuration, jndi_context_builder) ⇒ Base
Returns a new instance of Base.
52 53 54 55 56 57 58 |
# File 'lib/connection.rb', line 52 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.
50 51 52 |
# File 'lib/connection.rb', line 50 def configuration @configuration end |
Instance Method Details
#close ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/connection.rb', line 80 def close raise InvalidStateError.new('closed', 'close') if is_closed? @jndi_context.close @opened = false end |
#is_closed? ⇒ Boolean
76 77 78 |
# File 'lib/connection.rb', line 76 def is_closed? not @opened end |
#is_opened? ⇒ Boolean
60 61 62 |
# File 'lib/connection.rb', line 60 def is_opened? @opened end |
#lookup_resource(jndi_name) ⇒ Object
100 101 102 |
# File 'lib/connection.rb', line 100 def lookup_resource(jndi_name) @jndi_context.lookup(jndi_name) end |
#lookup_resources(resources = {}) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/connection.rb', line 88 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
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/connection.rb', line 64 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 |