123456789_123456789_123456789_123456789_123456789_

Class: Concurrent::Channel::Buffer::Sliding

Overview

A non-blocking, buffered buffer of fixed maximum capacity. When the maximum capacity is reached subsequent #put and #offer operations will complete and the item will be #put, but the oldest elements in the buffer will be discarded (not transferred).

Class Method Summary

Base - Inherited

Instance Attribute Summary

Buffered - Inherited

#ns_empty?

Predicate indicating if the buffer is empty.

#ns_full?

Predicate indicating if the buffer is full.

Base - Inherited

#blocking?

Predicate indicating if this buffer will block #put operations once it reaches its maximum capacity.

#capacity

The maximum number of values which can be #put onto the buffer it becomes full.

#closed?

Predicate indicating is this buffer closed.

#empty?

Predicate indicating if the buffer is empty.

#full?

Predicate indicating if the buffer is full.

#size

The number of items currently in the buffer.

#buffer, #buffer=, #capacity=, #closed=,
#ns_closed?

Predicate indicating is this buffer closed.

#ns_empty?

Predicate indicating if the buffer is empty.

#ns_full?

Predicate indicating if the buffer is full.

#size=

Instance Method Summary

Buffered - Inherited

#next

Take the next “item” from the buffer and also return a boolean indicating if “more” items can be taken.

#offer

Put an item onto the buffer if possible.

#poll

Take the next item from the buffer if one is available else return immediately.

#put

Put an item onto the buffer if possible.

#take

Take an item from the buffer if one is available.

#ns_initialize

Creates a new buffer.

#ns_put_onto_buffer

Put an item onto the buffer if possible.

#ns_size

The number of items currently in the buffer.

Base - Inherited

#close

Close the buffer, preventing new items from being added.

#next

Take the next “item” from the buffer and also return a boolean indicating if “more” items can be taken.

#offer

Put an item onto the buffer if possible.

#poll

Take the next item from the buffer if one is available else return immediately.

#put

Put an item onto the buffer if possible.

#take

Take an item from the buffer if one is available.

#ns_initialize,
#ns_size

The number of items currently in the buffer.

Synchronization::LockableObject - Inherited

Constructor Details

This class inherits a constructor from Concurrent::Channel::Buffer::Base

Instance Attribute Details

#blocking?Boolean (readonly)

Predicate indicating if this buffer will block #put operations once it reaches its maximum capacity.

Always returns false.

Returns:

  • (Boolean)

    true if this buffer blocks else false

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 36

def blocking?
  false
end

#ns_full?Boolean (readonly, private)

Predicate indicating if the buffer is full.

Returns:

  • (Boolean)

    true if this buffer is full else false

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 43

def ns_full?
  false
end

Instance Method Details

#full?Boolean

Predicate indicating if the buffer is full.

Always returns false.

Returns:

  • (Boolean)

    true if this buffer is full else false

[ GitHub ]

#ns_put_onto_buffer(item) ⇒ Boolean (private)

Put an item onto the buffer if possible. If the buffer is open but not able to accept the item the calling thread will block until the item can be put onto the buffer.

Parameters:

  • item (Object)

    the item/value to put onto the buffer.

Returns:

  • (Boolean)

    true if the item was added to the buffer else false (always false when closed).

[ GitHub ]

  
# File 'lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb', line 48

def ns_put_onto_buffer(item)
  buffer.shift if buffer.size == capacity
  buffer.push(item)
end

#offer(item) ⇒ Boolean

Put an item onto the buffer if possible. If the buffer is open but unable to add an item, probably due to being full, the method will return immediately. Similarly, the method will return immediately when the buffer is closed. A return value of false does not necessarily indicate that the buffer is closed, just that the item could not be added.

When the buffer is full, this method will return true immediately and the item will be inserted, but the oldest elements in the buffer will be discarded (not transferred).

Parameters:

  • item (Object)

    the item/value to put onto the buffer.

Returns:

  • (Boolean)

    true if the item was added to the buffer else false (always false when closed).

[ GitHub ]

#put(item) ⇒ Boolean

Put an item onto the buffer if possible. If the buffer is open but not able to accept the item the calling thread will block until the item can be put onto the buffer.

When the buffer is full, this method will return true immediately and the item will be inserted, but the oldest elements in the buffer will be discarded (not transferred).

Parameters:

  • item (Object)

    the item/value to put onto the buffer.

Returns:

  • (Boolean)

    true if the item was added to the buffer else false (always false when closed).

[ GitHub ]