Class: MarchHare::Exceptions

Inherits:
Object
  • Object
show all
Defined in:
lib/march_hare/exceptions.rb

Overview

Converts RabbitMQ Java client exceptions

Class Method Summary collapse

Class Method Details

.convert(e, unwrap_io_exception = true) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/march_hare/exceptions.rb', line 105

def self.convert(e, unwrap_io_exception = true)
  case e
  when java.net.SocketException then
    IOError.new(e.message)
  when java.io.IOException then
    c = e.cause

    if c && unwrap_io_exception
      convert(c, false)
    else
      IOError.new(e.message)
    end
  when com.rabbitmq.client.AlreadyClosedException then
    ChannelAlreadyClosed.new(e.reason)
  when com.rabbitmq.client.ShutdownSignalException then
    exception_for_protocol_method(e.reason)
  else
    e
  end
end

.convert_and_reraise(e) ⇒ Object



126
127
128
# File 'lib/march_hare/exceptions.rb', line 126

def self.convert_and_reraise(e)
  raise convert(e)
end

.exception_for_channel_close(m) ⇒ Object



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/march_hare/exceptions.rb', line 164

def self.exception_for_channel_close(m)
  klass = case m.reply_code
          when 403 then
            AccessRefused
          when 404 then
            NotFound
          when 405 then
            ResourceLocked
          when 406 then
            PreconditionFailed
          else
            ChannelLevelException
          end

  klass.new(m.reply_text, m)
end

.exception_for_connection_close(m) ⇒ Object



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/march_hare/exceptions.rb', line 145

def self.exception_for_connection_close(m)
  klass = case m.reply_code
          when 320 then
            ConnectionForced
          when 501 then
            FrameError
          when 503 then
            InvalidCommand
          when 504 then
            ChannelError
          when 505 then
            UnexpectedFrame
          else
            raise "Unknown reply code: #{m.reply_code}, text: #{m.reply_text}"
          end

  klass.new("Connection-level error: #{m.reply_text}", m)
end

.exception_for_protocol_method(m) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/march_hare/exceptions.rb', line 130

def self.exception_for_protocol_method(m)
  case m
  # com.rabbitmq.client.AMQP.Connection.Close does not resolve the inner
  # class correctly. Looks like a JRuby bug we work around by using Rubyesque
  # class name. MK.
  when Java::ComRabbitmqClient::AMQP::Connection::Close then
    exception_for_connection_close(m)
  when Java::ComRabbitmqClient::AMQP::Channel::Close then
    exception_for_channel_close(m)
  else
    NotImplementedError.new("Exception convertion for protocol method #{m.inspect} is not implemented!")
  end
end