def fetch_instance(impl, attachment_method = nil)
if impl.instance_variable_defined?(:@proton_wrapper)
return impl.instance_variable_get(:@proton_wrapper)
end
unless attachment_method.nil?
record = Cproton.__send__(attachment_method, impl)
rbkey = Cproton.pni_void2rbkey(Cproton.pn_record_get(record, RBCTX))
return nil if rbkey.nil?
registry_key = Cproton.Pn_rbkey_get_key_value(rbkey)
else
registry_key = get_key(impl)
end
return nil unless Qpid::Proton::Util::Wrapper.registry.has_key?(registry_key)
result = Qpid::Proton::Util::Wrapper.registry[registry_key]
if result.nil?
raise Qpid::Proton::ProtonError.new("missing object for key=#{registry_key}")
else
result.impl = impl
end
return result
end