the number of threads to use to write items.
Wraps a Writer[A] in the context of an AsyncWriterPool to provide asynchronous operations.
Wraps a Writer[A] in the context of an AsyncWriterPool to provide asynchronous operations. Calls to write() and related methods place items into the queue, and if necessary, schedule the queue for draining using the executor in the enclosing AsyncWriterPool.
Closes the pool and all writers currently within the pool.
Closes the pool and all writers currently within the pool. If any writer throws an exception during close() then an exception will be thrown from this method. Only the first encountered exception is thrown.
Takes a Writer and wraps it into a PooledWriter.
Takes a Writer and wraps it into a PooledWriter. The input Writer should not be accessed directly after this call. The returned PooledWriter can be written to in a manner identical to the original writer.
PooledWriters can used either an unbounded queue for storing to-be-written items (with queueSize=None
)
or a fixed queue of a given size (with queueSize=Some(n)
). If a fixed size queue is written it is
possible for write methods on PooledWriter to block if the queue is full, until some items are removed
and written.
the type of items written to the writer
the writer to be wrapped and made asynchronous
an optional queue size for the writer
a pooled writer that will perform writing asynchronously
A shared thread pool for making asynchronous Writers without allocating a thread per writer. The pool is created with a fixed number of threads which are used to handle write operations for all writers associated to the pool.
Writers are added to the pool using the pool() method, which returns a PooledWriter that can be written to in place of the original Writer. Writers of different types can be mixed within the same pool, and each writer can specify either an unbounded queue or a fixed queue of independent size when being pooled.
Writer can be added to the pool at any time (except aftering calling close() on the pool. Writers can be closed individually (and removed from the pool) using either their PooledWriter.close() method which runs synchronously on the calling thread, or by using PooledWriter.closeAsync() which will execute the close asynchronously and return a Future upon which
get()
must be called to re-throw any exceptions that were thrown during the close operation.The entire pool can be closed be calling close() on the pool. This will asynchronously close all open writers, shutdown the internal thread pool, and rethrow the first exception (if any) encountered when closing writers.