Skip to content

Commit

Permalink
move shared lease management responsibility out from clocks responsib…
Browse files Browse the repository at this point in the history
…ility (#14)
  • Loading branch information
kortemik authored Oct 17, 2024
1 parent 5f0e4aa commit 26fc879
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/teragrep/net_01/channel/context/Clock.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
public interface Clock extends AutoCloseable {

/**
* @param bufferLease to be consumed by the Clock. IMPORTANT: current tls implementation will not work properly if
* {@link BufferLease} is not fully consumed.
* @param bufferLease to be consumed by the Clock. Clock or it's subsequent actions must close all BufferLease's it
* receives otherwise encapsulated buffers are not reusable and memory allocator consumes time.
*/
void advance(BufferLease bufferLease);
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public void run() {

boolean continueReading = true;
while (!activeBuffers.isEmpty()) {
// IMPORTANT: current tls implementation will skip bytes if BufferLeases are not fully consumed.
BufferLease bufferLease = activeBuffers.removeFirst();
bufferLease.addRef();
LOGGER
Expand All @@ -119,6 +120,12 @@ public void run() {
if (!interestedClocks.isEmpty()) {
for (Clock clock : interestedClocks) {
clock.advance(bufferLease);

if (bufferLease.buffer().hasRemaining()) {
// shared buffer between clocks, ready for another
bufferLease.addRef();
}

}
}

Expand Down

0 comments on commit 26fc879

Please sign in to comment.