-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement BufferLease using Phaser for #61 --------- Co-authored-by: Mikko Kortelainen <1@teragrep.com>
- Loading branch information
Showing
12 changed files
with
155 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/main/java/com/teragrep/rlp_03/context/buffer/BufferContainer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.teragrep.rlp_03.context.buffer; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Interface for a buffer container object. | ||
*/ | ||
public interface BufferContainer { | ||
long id(); | ||
ByteBuffer buffer(); | ||
boolean isStub(); | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/com/teragrep/rlp_03/context/buffer/BufferContainerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.teragrep.rlp_03.context.buffer; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Implementation of the BufferContainer interface. Contains the buffer with a synchronized (lock-free) | ||
* way of accessing it. | ||
*/ | ||
public class BufferContainerImpl implements BufferContainer { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(BufferContainerImpl.class); | ||
private final long id; | ||
private final ByteBuffer buffer; | ||
|
||
public BufferContainerImpl(long id, ByteBuffer buffer) { | ||
this.id = id; | ||
this.buffer = buffer; | ||
} | ||
|
||
@Override | ||
public long id() { | ||
return id; | ||
} | ||
|
||
@Override | ||
public synchronized ByteBuffer buffer() { | ||
return buffer; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "BufferContainer{" + | ||
"buffer=" + buffer + | ||
", id=" + id + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean isStub() { | ||
LOGGER.debug("id <{}>", id); | ||
return false; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/teragrep/rlp_03/context/buffer/BufferContainerStub.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.teragrep.rlp_03.context.buffer; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* Buffer container stub object. Use isStub() to check. | ||
* Other methods will result in an IllegalStateException. | ||
*/ | ||
public class BufferContainerStub implements BufferContainer { | ||
@Override | ||
public long id() { | ||
throw new IllegalStateException("BufferContainerStub does not have an id!"); | ||
} | ||
|
||
@Override | ||
public ByteBuffer buffer() { | ||
throw new IllegalStateException("BufferContainerStub does not allow access to the buffer!"); | ||
} | ||
|
||
@Override | ||
public boolean isStub() { | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.