<commit_before>require 'bunny'

module Lapine
  class Exchange
    attr_reader :conn, :name, :props, :connection_name, :exchange_type

    def initialize(name, properties)
      @name = name
      @props = properties.dup
      @connection_name = props.delete(:connection)
      @exchange_type = props.delete(:type)
      ObjectSpace.define_finalizer(self, proc { |id| Lapine.config.cleanup_exchange(id) })
    end

    def connected?
      @exchange.channel.connection.connected? &&
        @exchange.channel.open?
    end

    def exchange
      @exchange ||= begin
        conn = Lapine.config.active_connection(connection_name)
        conn.logger.info "Creating channel for #{self.object_id}, thread: #{Thread.current.object_id}"
        channel = conn.create_channel<commit_msg>More checking of state to tell if exchange is connected<commit_after>require 'bunny'

module Lapine
  class Exchange
    attr_reader :conn, :name, :props, :connection_name, :exchange_type

    def initialize(name, properties)
      @name = name
      @props = properties.dup
      @connection_name = props.delete(:connection)
      @exchange_type = props.delete(:type)
      ObjectSpace.define_finalizer(self, proc { |id| Lapine.config.cleanup_exchange(id) })
    end

    def connected?
      @exchange &&
        @exchange.channel &&
        @exchange.channel.connection &&
        @exchange.channel.connection.connected? &&
        @exchange.channel.open?
    end

    def exchange
      @exchange ||= begin
        conn = Lapine.config.active_connection(connection_name)
        conn.logger.info "Creating channel for #{self.object_id}, thread: #{Thread.current.object_id}"
        channel = conn.create_channel
{'fraction_non_alphanumeric': 0.10600706713780919, 'fraction_numerical': 0.0, 'mean_word_length': 3.2158808933002483, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5249342', 'n_tokens_mistral': 498, 'n_tokens_neox': 472, 'n_words': 107}