Package org.apache.lucene.store
Class ByteBufferGuard
- java.lang.Object
-
- org.apache.lucene.store.ByteBufferGuard
-
final class ByteBufferGuard extends java.lang.Object
A guard that is created for everyByteBufferIndexInput
that tries on best effort to reject any access to theByteBuffer
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 throwAlreadyClosedException
, triggered by aNullPointerException
.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...
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interface
ByteBufferGuard.BufferCleaner
Pass in an implementation of this interface to cleanup ByteBuffers.
-
Field Summary
Fields Modifier and Type Field 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 Summary
Constructors Constructor Description ByteBufferGuard(java.lang.String resourceDescription, ByteBufferGuard.BufferCleaner cleaner)
Creates an instance to be used for a singleByteBufferIndexInput
which must be shared by all of its clones.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method 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)
void
getLongs(java.nio.LongBuffer receiver, long[] dst, int offset, int length)
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).
-
-
-
Field Detail
-
resourceDescription
private final java.lang.String resourceDescription
-
cleaner
private final ByteBufferGuard.BufferCleaner cleaner
-
invalidated
private boolean invalidated
Not volatile; see comments on visibility below!
-
barrier
private final java.util.concurrent.atomic.AtomicInteger barrier
Used as a store-store barrier; see comments below!
-
-
Constructor Detail
-
ByteBufferGuard
public ByteBufferGuard(java.lang.String resourceDescription, ByteBufferGuard.BufferCleaner cleaner)
Creates an instance to be used for a singleByteBufferIndexInput
which must be shared by all of its clones.
-
-
Method Detail
-
invalidateAndUnmap
public void invalidateAndUnmap(java.nio.ByteBuffer... bufs) throws java.io.IOException
Invalidates this guard and unmaps (if supported).- Throws:
java.io.IOException
-
ensureValid
private void ensureValid()
-
getBytes
public void getBytes(java.nio.ByteBuffer receiver, byte[] dst, int offset, int length)
-
getByte
public byte getByte(java.nio.ByteBuffer receiver)
-
getShort
public short getShort(java.nio.ByteBuffer receiver)
-
getInt
public int getInt(java.nio.ByteBuffer receiver)
-
getLong
public long getLong(java.nio.ByteBuffer receiver)
-
getByte
public byte getByte(java.nio.ByteBuffer receiver, int pos)
-
getShort
public short getShort(java.nio.ByteBuffer receiver, int pos)
-
getInt
public int getInt(java.nio.ByteBuffer receiver, int pos)
-
getLong
public long getLong(java.nio.ByteBuffer receiver, int pos)
-
getLongs
public void getLongs(java.nio.LongBuffer receiver, long[] dst, int offset, int length)
-
-