Example usage for java.nio MappedByteBuffer getClass

List of usage examples for java.nio MappedByteBuffer getClass

Introduction

In this page you can find the example usage for java.nio MappedByteBuffer getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.reactive.hzdfs.io.MemoryMappedChunkHandler.java

private static boolean unmap(MappedByteBuffer bb) {
    /*// w  ww .j a  va 2  s  .  c o  m
     * From  sun.nio.ch.FileChannelImpl
     * private static void  unmap(MappedByteBuffer bb) {
                  
           Cleaner cl = ((DirectBuffer)bb).cleaner();
           if (cl != null)
       cl.clean();
            
            
       }
     */
    try {
        Method cleaner_method = ReflectionUtils.findMethod(bb.getClass(), "cleaner");
        if (cleaner_method != null) {
            cleaner_method.setAccessible(true);
            Object cleaner = cleaner_method.invoke(bb);
            if (cleaner != null) {
                Method clean_method = ReflectionUtils.findMethod(cleaner.getClass(), "clean");
                clean_method.setAccessible(true);
                clean_method.invoke(cleaner);
                return true;
            }
        }

    } catch (Exception ex) {
        log.debug("", ex);
    }
    return false;
}

From source file:ja.centre.util.io.nio.MappedByteBufferWrapper.java

private void clean(final MappedByteBuffer buffer) {
    AccessController.doPrivileged(new PrivilegedAction<Object>() {
        public Object run() {
            try {
                Method cleanerMethod = buffer.getClass().getMethod("cleaner");
                cleanerMethod.setAccessible(true);
                sun.misc.Cleaner cleaner = (sun.misc.Cleaner) cleanerMethod.invoke(buffer);
                cleaner.clean();/*from   ww  w. j a va  2s.c o  m*/
            } catch (IllegalAccessException e) {
                States.shouldNeverReachHere(e);
            } catch (NoSuchMethodException e) {
                States.shouldNeverReachHere(e);
            } catch (InvocationTargetException e) {
                States.shouldNeverReachHere(e);
            }
            return null;
        }
    });
}