Package org.apache.lucene.store
Class ByteBufferGuard
- java.lang.Object
-
- org.apache.lucene.store.ByteBufferGuard
-
final class ByteBufferGuard extends java.lang.ObjectA guard that is created for everyByteBufferIndexInputthat tries on best effort to reject any access to theByteBufferbehind, 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 interfaceByteBufferGuard.BufferCleanerPass in an implementation of this interface to cleanup ByteBuffers.
-
Field Summary
Fields Modifier and Type Field Description private java.util.concurrent.atomic.AtomicIntegerbarrierUsed as a store-store barrier; see comments below!private ByteBufferGuard.BufferCleanercleanerprivate booleaninvalidatedNot volatile; see comments on visibility below!private java.lang.StringresourceDescription
-
Constructor Summary
Constructors Constructor Description ByteBufferGuard(java.lang.String resourceDescription, ByteBufferGuard.BufferCleaner cleaner)Creates an instance to be used for a singleByteBufferIndexInputwhich must be shared by all of its clones.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidensureValid()bytegetByte(java.nio.ByteBuffer receiver)bytegetByte(java.nio.ByteBuffer receiver, int pos)voidgetBytes(java.nio.ByteBuffer receiver, byte[] dst, int offset, int length)intgetInt(java.nio.ByteBuffer receiver)intgetInt(java.nio.ByteBuffer receiver, int pos)longgetLong(java.nio.ByteBuffer receiver)longgetLong(java.nio.ByteBuffer receiver, int pos)voidgetLongs(java.nio.LongBuffer receiver, long[] dst, int offset, int length)shortgetShort(java.nio.ByteBuffer receiver)shortgetShort(java.nio.ByteBuffer receiver, int pos)voidinvalidateAndUnmap(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 singleByteBufferIndexInputwhich must be shared by all of its clones.
-
-
Method Detail
-
invalidateAndUnmap
public void invalidateAndUnmap(java.nio.ByteBuffer... bufs) throws java.io.IOExceptionInvalidates 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)
-
-