Sha256: 8866d00d990589a2096ee072834bbfd62ff75953aaa24cf572325c24326ea0ea

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

require 'concurrent-ruby'

module Legion
  module Transport
    module Connection
      class << self
        def connector
          Legion::Transport::CONNECTOR
        end

        def setup # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
          if @session.respond_to?(:value) && session.respond_to?(:closed?) && session.closed?
            @channel_thread = Concurrent::ThreadLocalVar.new
          elsif @session.respond_to?(:value) && session.respond_to?(:closed?) && session.open?
            return nil
          else
            @session ||= Concurrent::Atom.new(
              connector.new(
                Legion::Settings[:transport][:connection],
                logger: Legion::Logging::Logger.new(level: 'warn'),
                log_level: :info
              )
            )
            @channel_thread = Concurrent::ThreadLocalVar.new
          end

          session.start
          session.create_channel.basic_qos(1, true)
        end

        def channel
          return @channel_thread.value if !@channel_thread.value.nil? && @channel_thread.value.open?

          @channel_thread.value = session.create_channel
          @channel_thread.value.prefetch(Legion::Settings[:transport][:prefetch])
          @channel_thread.value
        end

        def session
          nil if @session.nil?
          @session.value
        end

        def channel_thread
          channel
        end

        def channel_open?
          channel.open?
        end

        def session_open?
          session.open?
        end

        def shutdown
          session.close
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
legion-transport-java-1.1.3 lib/legion/transport/connection.rb
legion-transport-1.1.3 lib/legion/transport/connection.rb
legion-transport-1.1.2 lib/legion/transport/connection.rb
legion-transport-1.1.1 lib/legion/transport/connection.rb
legion-transport-1.1.0 lib/legion/transport/connection.rb