Class: Rdkafka::Callbacks::BackgroundEventCallback

Inherits:
Object
  • Object
show all
Defined in:
lib/rdkafka/callbacks.rb

Overview

Dispatches librdkafka admin background events to the matching handler.

The actual per-operation handling lives in the Rdkafka::Callbacks::*Handler classes (see lib/rdkafka/callbacks/); this class only maps the event type to its handler and guarantees the event is destroyed afterwards.

Class Method Summary collapse

Class Method Details

.call(_client_ptr, event_ptr, _opaque_ptr) ⇒ Object

Handles background events from librdkafka

Parameters:

  • _client_ptr (FFI::Pointer)

    unused client pointer

  • event_ptr (FFI::Pointer)

    pointer to the event

  • _opaque_ptr (FFI::Pointer)

    unused opaque pointer



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/rdkafka/callbacks.rb', line 216

def self.call(_client_ptr, event_ptr, _opaque_ptr)
  handler = case Rdkafka::Bindings.rd_kafka_event_type(event_ptr)
  when Rdkafka::Bindings::RD_KAFKA_EVENT_CREATETOPICS_RESULT then CreateTopicHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_DELETETOPICS_RESULT then DeleteTopicHandler
  when Rdkafka::Bindings::RD_KAFKA_ADMIN_OP_CREATEPARTITIONS_RESULT then CreatePartitionsHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_DELETEGROUPS_RESULT then DeleteGroupsHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_CREATEACLS_RESULT then CreateAclHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_DELETEACLS_RESULT then DeleteAclHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_DESCRIBEACLS_RESULT then DescribeAclHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_DESCRIBECONFIGS_RESULT then DescribeConfigsHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_INCREMENTALALTERCONFIGS_RESULT then IncrementalAlterConfigsHandler
  when Rdkafka::Bindings::RD_KAFKA_EVENT_LISTOFFSETS_RESULT then ListOffsetsHandler
  end

  handler&.call(event_ptr)
ensure
  # Background queue events are owned by the application and must be destroyed once
  # served (see rd_kafka_conf_set_background_event_cb). All event-owned memory (result
  # arrays, strings) has to be copied into Ruby objects by the handlers above before this
  # runs - nothing may retain pointers into the event past this point.
  Rdkafka::Bindings.rd_kafka_event_destroy(event_ptr)
end