public class NonBlockingStreamWriter extends Object implements Runnable
addDataToWrite(OutputStream, byte[], Supplier) to the specified
stream, only if there is available space. If no space available, it saves a task to try later. When it tried to execute all the
pending writes, and it couldn't, then it sleeps a certain period passed via constructor (default is
DEFAULT_TIME_TO_SLEEP_WHEN_COULD_NOT_WRITE_MILLIS). This is done to avoid an unnecessarily high CPU consumption.| Constructor and Description |
|---|
NonBlockingStreamWriter() |
NonBlockingStreamWriter(int timeToSleepWhenCouldNotWriteMillis,
boolean isEnabled) |
| Modifier and Type | Method and Description |
|---|---|
CompletableFuture<Void> |
addDataToWrite(OutputStream destinationStream,
byte[] dataToWrite,
Supplier<Integer> availableSpace)
Tries to write from
dataToWrite to destinationStream, as many bytes as the
availableSpace supplier says it's possible to write. |
boolean |
isEnabled() |
void |
notifyAvailableSpace()
Wake up the writer thread to avoid sleeping too much and cause degradations.
|
void |
run() |
void |
stop()
Signals the writer to stop writing.
|
public NonBlockingStreamWriter(int timeToSleepWhenCouldNotWriteMillis,
boolean isEnabled)
public NonBlockingStreamWriter()
public boolean isEnabled()
public CompletableFuture<Void> addDataToWrite(OutputStream destinationStream, byte[] dataToWrite, Supplier<Integer> availableSpace)
dataToWrite to destinationStream, as many bytes as the
availableSpace supplier says it's possible to write. If the supplier returns 0, it schedules a task
to try later.destinationStream - where the data has to be written.dataToWrite - the data to write.availableSpace - a supplier that says how many bytes can be written to the stream without blocking.CompletableFuture that will be completed when all the data was written, or when an exception occurs.public void notifyAvailableSpace()
public void stop()
Copyright © 2003–2025 MuleSoft, Inc.. All rights reserved.