Class TimedSynchronousQueue<E>
java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractQueue<E>
java.util.concurrent.SynchronousQueue<E>
eu.cloudnetservice.driver.impl.network.scheduler.TimedSynchronousQueue<E>
- Type Parameters:
E- the type of elements held in this queue
- All Implemented Interfaces:
Serializable, Iterable<E>, Collection<E>, BlockingQueue<E>, Queue<E>
An implementation of a synchronous queue that always offers tasks to itself with a timeout instead of returning
instantly if that is not possible. The queue also makes some more assumptions when the parent executor service is
provided to achieve the maximum scaling of the parent thread pool.
- Since:
- 4.0
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTimedSynchronousQueue(@NonNull LongSupplier timeoutSupplier) Constructs a new instance of this queue using the given timeout supplier. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTries to offer the given element into this queue with a timeout provided by the owner of this queue.private booleanTries to offer the given element into this queue with the given timeout millis.voidparentExecutor(@NonNull ThreadPoolExecutor parentExecutor) Sets the parent thread pool executor that is associated with the queue unless another thread pool executor is already associated with it.Methods inherited from class SynchronousQueue
clear, contains, containsAll, drainTo, drainTo, isEmpty, iterator, offer, peek, poll, poll, put, remainingCapacity, remove, removeAll, retainAll, size, spliterator, take, toArray, toArray, toStringMethods inherited from class AbstractQueue
add, addAll, element, removeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface BlockingQueue
addMethods inherited from interface Collection
addAll, equals, hashCode, parallelStream, removeIf, stream, toArray
-
Field Details
-
timeoutSupplier
-
parentExecutor
-
-
Constructor Details
-
TimedSynchronousQueue
Constructs a new instance of this queue using the given timeout supplier.- Parameters:
timeoutSupplier- the supplier for timeouts used when actually needing to queue elements.- Throws:
NullPointerException- if the given timeout supplier is null.
-
-
Method Details
-
parentExecutor
Sets the parent thread pool executor that is associated with the queue unless another thread pool executor is already associated with it.- Parameters:
parentExecutor- the parent executor to use for this queue.- Throws:
NullPointerException- if the given parent executor is null.IllegalStateException- if a parent executor was already set.
-
offer
Tries to offer the given element into this queue with a timeout provided by the owner of this queue. If the queue has information about the associated thread pool this method makes some additional considerations to ensure scaling the thread pool to its maximum capacity first.- Specified by:
offerin interfaceBlockingQueue<E>- Specified by:
offerin interfaceQueue<E>- Overrides:
offerin classSynchronousQueue<E>- Parameters:
element- the element to add into this queue.- Returns:
- true if the element was added into this queue, false otherwise.
- Throws:
NullPointerException- if the given element is null.
-
offerSafe
Tries to offer the given element into this queue with the given timeout millis.- Parameters:
element- the element to offer into this queue.timeoutMillis- the timeout in milliseconds of the offer operation.- Returns:
- true if some other thread polled the element within the timeout millis, false otherwise.
- Throws:
NullPointerException- if the given element is null.
-