LinkedBlockingQueue

open class LinkedBlockingQueue<E>(capacity: Int = Int.MAX_VALUE) : AbstractQueue<E> , BlockingQueue<E>

Constructors

Link copied to clipboard
constructor(capacity: Int = Int.MAX_VALUE)
constructor(c: MutableCollection<E>)

Creates a LinkedBlockingQueue with a capacity of Integer.MAX_VALUE, initially containing the elements of the given collection, added in traversal order of the collection's iterator.

Types

Link copied to clipboard
class Node<E>(var item: E?)

Linked list node class.

Properties

Link copied to clipboard

Head of linked list. Invariant: head.item == null

Link copied to clipboard
Link copied to clipboard
open override val size: Int

Returns the number of elements in this queue.

Functions

Link copied to clipboard
open override fun add(e: E): Boolean

Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Link copied to clipboard
open override fun addAll(c: Collection<E>): Boolean

Adds all of the elements in the specified collection to this queue. Attempts to addAll of a queue to itself result in IllegalArgumentException. Further, the behavior of this operation is undefined if the specified collection is modified while the operation is in progress.

Link copied to clipboard
open override fun clear()

Atomically removes all of the elements from this queue. The queue will be empty after this call returns.

Link copied to clipboard
open operator override fun contains(o: E): Boolean

Returns true if this queue contains the specified element. More formally, returns true if and only if this queue contains at least one element e such that o.equals(e).

Link copied to clipboard
open override fun containsAll(elements: Collection<E>): Boolean
Link copied to clipboard
open override fun drainTo(c: MutableCollection<E>): Int
open override fun drainTo(c: MutableCollection<E>, maxElements: Int): Int
Link copied to clipboard
open override fun element(): E

Retrieves, but does not remove, the head of this queue. This method differs from .peek only in that it throws an exception if this queue is empty.

Link copied to clipboard

Returns the predecessor of live node p, given a node that was once a live ancestor of p (or head); allows unlinking of p.

Link copied to clipboard
fun forEach(action: (E) -> Unit)
Link copied to clipboard
fun forEachFrom(action: (E) -> Unit, p: LinkedBlockingQueue.Node<E>?)

Runs action on each element found during a traversal starting at p. If p is null, traversal starts at head.

Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): MutableIterator<E>

Returns an iterator over the elements in this queue in proper sequence. The elements will be returned in order from first (head) to last (tail).

Link copied to clipboard
open override fun offer(e: E): Boolean

Inserts the specified element at the tail of this queue if it is possible to do so immediately without exceeding the queue's capacity, returning true upon success and false if this queue is full. When using a capacity-restricted queue, this method is generally preferable to method add, which can fail to insert an element only by throwing an exception.

open suspend override fun offer(e: E, timeout: Long, unit: TimeUnit): Boolean

Inserts the specified element at the tail of this queue, waiting if necessary up to the specified wait time for space to become available.

Link copied to clipboard
open override fun peek(): E?

Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.

Link copied to clipboard
open override fun poll(): E?

Retrieves and removes the head of this queue, or returns null if this queue is empty.

open suspend override fun poll(timeout: Long, unit: TimeUnit): E?

Retrieves and removes the head of this queue, waiting up to the specified wait time if necessary for an element to become available.

Link copied to clipboard
open suspend override fun put(e: E)

Inserts the specified element at the tail of this queue, waiting if necessary for space to become available.

Link copied to clipboard
open override fun remainingCapacity(): Int

Returns the number of additional elements that this queue can ideally (in the absence of memory or resource constraints) accept without blocking. This is always equal to the initial capacity of this queue less the current size of this queue.

Link copied to clipboard
open override fun remove(): E

Retrieves and removes the head of this queue. This method differs from .poll only in that it throws an exception if this queue is empty.

open override fun remove(o: E): Boolean

Removes a single instance of the specified element from this queue, if it is present. More formally, removes an element e such that o.equals(e), if this queue contains one or more such elements. Returns true if this queue contained the specified element (or equivalently, if this queue changed as a result of the call).

Link copied to clipboard
open override fun removeAll(c: Collection<E>): Boolean
Link copied to clipboard
Link copied to clipboard
suspend fun removeIf(filter: (E?) -> Boolean): Boolean
Link copied to clipboard
open override fun retainAll(c: Collection<E>): Boolean
Link copied to clipboard
Link copied to clipboard

Returns a Spliterator over the elements in this queue.

Link copied to clipboard

Used for any element traversal that is not entirely under lock. Such traversals must handle both:

Link copied to clipboard
open suspend override fun take(): E

Retrieves and removes the head of this queue, waiting if necessary until an element becomes available.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Unlinks interior Node p with predecessor pred.