<commit_before>module MaZMQ
  class Proxy
    include MaZMQ::Proxy::Backend

    #@@id = 0

    def initialize(use_em=true)
      @balancer = MaZMQ::Proxy::Balancer.new

      # @max_timeouts = 5 # TODO
      # @max_timeouted = 1
      # @max_retries

      super(use_em)
    end

    def send_string(msg)
      @current = current_socket
      return false if @current.is_a? NilClass
      case @current.state
        when :idle
          @current.send_string(msg)
        else
          return false
      end
      @balancer.next
    end

    def connect(protocol, address, port)
      return false if addresses.include? "#{protocol}://#{address}:#{port.to_s}"
      index = super(protocol, address, port)
      @balancer.add(index)
    end

    def disconnect(index)
      @balancer.remove(index)
      super(index)
    end

    def addresses
      @sockets.collect{|s| s.addresses}.flatten
    end

    def current_socket<commit_msg>Proxy connect returns socket index<commit_after>module MaZMQ
  class Proxy
    include MaZMQ::Proxy::Backend

    #@@id = 0

    def initialize(use_em=true)
      @balancer = MaZMQ::Proxy::Balancer.new

      # @max_timeouts = 5 # TODO
      # @max_timeouted = 1
      # @max_retries

      super(use_em)
    end

    def send_string(msg)
      @current = current_socket
      return false if @current.is_a? NilClass
      case @current.state
        when :idle
          @current.send_string(msg)
        else
          return false
      end
      @balancer.next
    end

    def connect(protocol, address, port)
      return false if addresses.include? "#{protocol}://#{address}:#{port.to_s}"
      index = super(protocol, address, port)
      @balancer.add(index)
      index
    end

    def disconnect(index)
      @balancer.remove(index)
      super(index)
    end

    def addresses
      @sockets.collect{|s| s.addresses}.flatten
    end

    def current_socket
{'fraction_non_alphanumeric': 0.09963293130571578, 'fraction_numerical': 0.003146303093864709, 'mean_word_length': 2.2783505154639174, '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': '4781161', 'n_tokens_mistral': 628, 'n_tokens_neox': 599, 'n_words': 138}