Package sun.nio.ch

Examples of sun.nio.ch.DirectBuffer


     * Wrap the entire capacity of a {@link java.nio.ByteBuffer}.
     */
    public static Slice wrappedBuffer(ByteBuffer buffer)
    {
        if (buffer instanceof DirectBuffer) {
            DirectBuffer direct = (DirectBuffer) buffer;
            return new Slice(null, direct.address(), buffer.capacity(), direct);
        }

        if (buffer.hasArray()) {
            int address = ARRAY_BYTE_BASE_OFFSET + buffer.arrayOffset();
            return new Slice(buffer.array(), address, buffer.capacity(), null);
View Full Code Here


    @Test
    public void testWhileEqual() {
        if (!Platform.isLinux()) return;

        DirectBuffer buffer = (DirectBuffer) ByteBuffer.allocateDirect(8);
        int runs = 100000000;
        long start = System.nanoTime();
        assertEquals(0, JNIBusyWaiting.INSTANCE.whileEqual(null, buffer.address(), runs, 0));
        long time = System.nanoTime() - start;
        System.out.printf("The average time to poll equals was %.1f ns%n", (double) time / runs);
    }
View Full Code Here

    @Test
    public void testWhileLessThan() {
        if (!Platform.isLinux()) return;

        DirectBuffer buffer = (DirectBuffer) ByteBuffer.allocateDirect(8);
        int runs = 100000000;
        long start = System.nanoTime();
        assertEquals(0, JNIBusyWaiting.INSTANCE.whileLessThan(null, buffer.address(), runs, 1));
        long time = System.nanoTime() - start;
        System.out.printf("The average time to poll less than was %.1f ns%n", (double) time / runs);
    }
View Full Code Here

        System.out.printf("The average time to pause was %.1f ns%n", (double) time / runs);
    }

    @Test
    public void testWhileEqual() {
        DirectBuffer buffer = (DirectBuffer) ByteBuffer.allocateDirect(8);
        int runs = 1000000;
        long start = System.nanoTime();
        assertEquals(0, JavaBusyWaiting.INSTANCE.whileEqual(null, buffer.address(), runs, 0));
        long time = System.nanoTime() - start;
        System.out.printf("The average time to poll equals was %.1f ns%n", (double) time / runs);
    }
View Full Code Here

        System.out.printf("The average time to poll equals was %.1f ns%n", (double) time / runs);
    }

    @Test
    public void testWhileLessThan() {
        DirectBuffer buffer = (DirectBuffer) ByteBuffer.allocateDirect(8);
        int runs = 1000000;
        long start = System.nanoTime();
        assertEquals(0, JavaBusyWaiting.INSTANCE.whileLessThan(null, buffer.address(), runs, 1));
        long time = System.nanoTime() - start;
        System.out.printf("The average time to poll less than was %.1f ns%n", (double) time / runs);
    }
View Full Code Here

     * Wrap the entire capacity of a {@link java.nio.ByteBuffer}.
     */
    public static Slice wrappedBuffer(ByteBuffer buffer)
    {
        if (buffer instanceof DirectBuffer) {
            DirectBuffer direct = (DirectBuffer) buffer;
            return new Slice(null, direct.address(), buffer.capacity(), direct);
        }

        if (buffer.hasArray()) {
            int address = ARRAY_BYTE_BASE_OFFSET + buffer.arrayOffset();
            return new Slice(buffer.array(), address, buffer.capacity(), null);
View Full Code Here

     * @param bb
     */
    MessageBuffer(ByteBuffer bb) {
        if(bb.isDirect()) {
            // Direct buffer or off-heap memory
            DirectBuffer db = DirectBuffer.class.cast(bb);
            this.base = null;
            this.address = db.address();
            this.size = bb.capacity();
            this.reference = bb;
        }
        else if(bb.hasArray()) {
            this.base = bb.array();
View Full Code Here

    public void putByteBuffer(int index, ByteBuffer src, int len) {
        assert(len <= src.remaining());

        if(src.isDirect()) {
            DirectBuffer db = (DirectBuffer) src;
            unsafe.copyMemory(null, db.address() + src.position(), base, address+index, len);
        } else if(src.hasArray()) {
            byte[] srcArray = src.array();
            unsafe.copyMemory(srcArray, ARRAY_BYTE_BASE_OFFSET + src.position(), base, address+index, len);
        } else {
            if(base != null) {
View Full Code Here

     * Wrap the entire capacity of a {@link java.nio.ByteBuffer}.
     */
    public static Slice wrappedBuffer(ByteBuffer buffer)
    {
        if (buffer instanceof DirectBuffer) {
            DirectBuffer direct = (DirectBuffer) buffer;
            return new Slice(null, direct.address(), buffer.capacity(), direct);
        }

        if (buffer.hasArray()) {
            int address = ARRAY_BYTE_BASE_OFFSET + buffer.arrayOffset();
            return new Slice(buffer.array(), address, buffer.capacity(), null);
View Full Code Here

    public static Slice toUnsafeSlice(ByteBuffer byteBuffer)
    {
        checkNotNull(byteBuffer, "byteBuffer is null");
        checkArgument(byteBuffer instanceof DirectBuffer, "byteBuffer is not an instance of %s", DirectBuffer.class.getName());
        DirectBuffer directBuffer = (DirectBuffer) byteBuffer;
        long address = directBuffer.address();
        int capacity = byteBuffer.capacity();
        return new Slice(null, address, capacity, byteBuffer);
    }
View Full Code Here

TOP

Related Classes of sun.nio.ch.DirectBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.