Sha256: 553304c501baf88e83cdc6e57ff161fdabf07cd44468783ab5ca6c029343f5b4

Contents?: true

Size: 1.12 KB

Versions: 20

Compression:

Stored size: 1.12 KB

Contents

module SplitIoClient
  module Cache
    module Adapters
      module MemoryAdapters
        # Memory adapter implementation, which stores everything inside queue
        class QueueAdapter
          def initialize(max_size)
            @max_size = max_size
            @queue = Queue.new
            @current_size = Concurrent::AtomicFixnum.new(0)
          end

          def clear(_ = nil)
            @queue = Queue.new
            @current_size.value = 0
          end

          # Adds data to queue in non-blocking mode
          def add_to_queue(data)
            fail ThreadError if @current_size.value >= @max_size

            @queue.push(data)

            @current_size.increment
          end

          def clear
            get_batch(@current_size.value)
          end

          def get_batch(size)
            items = []
            size.times do
              items << @queue.pop(true)
              @current_size.decrement
            end
            items
            rescue ThreadError
            items
          end

          def length
            @current_size.value
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
splitclient-rb-7.0.0-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc3-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc3 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc2-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc2 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc1-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-7.0.0.pre.rc1 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc3-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc3 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc2-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc2 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc1-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.1.pre.rc1 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.0-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.0 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.0.pre.rc1-java lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb
splitclient-rb-6.4.0.pre.rc1 lib/splitclient-rb/cache/adapters/memory_adapters/queue_adapter.rb