Class ByteBufferGuard


  • final class ByteBufferGuard
    extends java.lang.Object
    A guard that is created for every 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...

    • 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.
    • 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)  
      void getFloats​(java.nio.FloatBuffer receiver, float[] dst, int offset, int length)  
      int getInt​(java.nio.ByteBuffer receiver)  
      int getInt​(java.nio.ByteBuffer receiver, int pos)  
      void getInts​(java.nio.IntBuffer receiver, int[] dst, int offset, int length)  
      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).
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • resourceDescription

        private final java.lang.String resourceDescription
      • 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!
    • 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)
      • getInts

        public void getInts​(java.nio.IntBuffer receiver,
                            int[] dst,
                            int offset,
                            int length)
      • getFloats

        public void getFloats​(java.nio.FloatBuffer receiver,
                              float[] dst,
                              int offset,
                              int length)