final class ByteBufferGuard
extends java.lang.Object
ByteBufferIndexInput
that tries on best effort
to reject any access to the ByteBuffer
behind, once it is unmapped. A single instance
of this is used for the original and all clones, so once the original is closed and unmapped
all clones also throw AlreadyClosedException
, triggered by a NullPointerException
.
This code tries to hopefully flush any CPU caches using a store-store barrier. It also yields the current thread to give other threads a chance to finish in-flight requests...
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
ByteBufferGuard.BufferCleaner
Pass in an implementation of this interface to cleanup ByteBuffers.
|
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.atomic.AtomicInteger |
barrier
Used as a store-store barrier; see comments below!
|
private ByteBufferGuard.BufferCleaner |
cleaner |
private boolean |
invalidated
Not volatile; see comments on visibility below!
|
private java.lang.String |
resourceDescription |
Constructor and Description |
---|
ByteBufferGuard(java.lang.String resourceDescription,
ByteBufferGuard.BufferCleaner cleaner)
Creates an instance to be used for a single
ByteBufferIndexInput which
must be shared by all of its clones. |
Modifier and Type | Method and Description |
---|---|
private void |
ensureValid() |
byte |
getByte(java.nio.ByteBuffer receiver) |
byte |
getByte(java.nio.ByteBuffer receiver,
int pos) |
void |
getBytes(java.nio.ByteBuffer receiver,
byte[] dst,
int offset,
int length) |
int |
getInt(java.nio.ByteBuffer receiver) |
int |
getInt(java.nio.ByteBuffer receiver,
int pos) |
long |
getLong(java.nio.ByteBuffer receiver) |
long |
getLong(java.nio.ByteBuffer receiver,
int pos) |
short |
getShort(java.nio.ByteBuffer receiver) |
short |
getShort(java.nio.ByteBuffer receiver,
int pos) |
void |
invalidateAndUnmap(java.nio.ByteBuffer... bufs)
Invalidates this guard and unmaps (if supported).
|
private final java.lang.String resourceDescription
private final ByteBufferGuard.BufferCleaner cleaner
private boolean invalidated
private final java.util.concurrent.atomic.AtomicInteger barrier
public ByteBufferGuard(java.lang.String resourceDescription, ByteBufferGuard.BufferCleaner cleaner)
ByteBufferIndexInput
which
must be shared by all of its clones.public void invalidateAndUnmap(java.nio.ByteBuffer... bufs) throws java.io.IOException
java.io.IOException
private void ensureValid()
public void getBytes(java.nio.ByteBuffer receiver, byte[] dst, int offset, int length)
public byte getByte(java.nio.ByteBuffer receiver)
public short getShort(java.nio.ByteBuffer receiver)
public int getInt(java.nio.ByteBuffer receiver)
public long getLong(java.nio.ByteBuffer receiver)
public byte getByte(java.nio.ByteBuffer receiver, int pos)
public short getShort(java.nio.ByteBuffer receiver, int pos)
public int getInt(java.nio.ByteBuffer receiver, int pos)
public long getLong(java.nio.ByteBuffer receiver, int pos)