Sha256: a70446b82d4d2ad11d7faf2bc4d82a76f05ec53c5f1b54063688dd9b0048e010

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'concurrent-ruby'

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

        def setup
          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

1 entries across 1 versions & 1 rubygems

Version Path
legion-transport-1.0.0 lib/legion/transport/connection.rb