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.
109 110 111 112 113 114 115 |
# File 'lib/connection.rb', line 109 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.
107 108 109 |
# File 'lib/connection.rb', line 107 def configuration @configuration end |
Instance Method Details
#close ⇒ Object
137 138 139 140 141 142 143 |
# File 'lib/connection.rb', line 137 def close raise InvalidStateError.new('closed', 'close') if is_closed? @jndi_context.close @opened = false end |
#is_closed? ⇒ Boolean
133 134 135 |
# File 'lib/connection.rb', line 133 def is_closed? not @opened end |
#is_opened? ⇒ Boolean
117 118 119 |
# File 'lib/connection.rb', line 117 def is_opened? @opened end |
#lookup_resource(jndi_name) ⇒ Object
157 158 159 |
# File 'lib/connection.rb', line 157 def lookup_resource(jndi_name) @jndi_context.lookup(jndi_name) end |
#lookup_resources(resources = {}) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/connection.rb', line 145 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
121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/connection.rb', line 121 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 |