Package net.openhft.lang.io

Examples of net.openhft.lang.io.ByteBufferBytes


        final SharedHashMap<IntValue, CharSequence> map = new SharedHashMapBuilder()
                .entries(1000)
                .entries(20000).file(getPersistenceFile()).kClass(IntValue.class).vClass(CharSequence.class).create();

        IntValue$$Native value = new IntValue$$Native();
        value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);

        value.setValue(1);
        final String expected = "test";
        map.put(value, expected);
View Full Code Here


        } else if (type == Type.REMOTE_PRODUCER || type == Type.REMOTE_CONSUMER) {

            final int bufferSize = capacity * align(maxSize, 4);
            final ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize).order(ByteOrder.nativeOrder());
            final ByteBufferBytes byteBufferBytes = new ByteBufferBytes(buffer);

            final BytesDataLocator<E, ByteBufferBytes> bytesDataLocator = new BytesDataLocator<E, ByteBufferBytes>(
                    clazz,
                    capacity,
                    maxSize,
                    byteBufferBytes.slice(),
                    byteBufferBytes.slice());

            if (type == Type.REMOTE_PRODUCER) {
                final Producer producer = new Producer<E, ByteBufferBytes>(new LocalRingIndex(), bytesDataLocator, bytesDataLocator, new ServerSocketChannelProvider(port), bytesDataLocator, buffer);
                ringIndex = producer;
                dataLocator = producer;
View Full Code Here

                           final int entrySize,
                           @NotNull final Replica.EntryExternalizable externalizable) {

        //todo HCOLL-71 fix the 128 padding
        final int entrySize0 = entrySize + 128;
        entryBuffer = new ByteBufferBytes(ByteBuffer.allocateDirect(entrySize0));

        // in bound
        Executors.newSingleThreadExecutor(new ThreadFactory() {

            @Override
            public Thread newThread(Runnable r) {
                final Thread thread = new Thread(r, "reader-map" + externalizable);
                thread.setDaemon(true);
                return thread;
            }

        }).execute(new Runnable() {

            @Override
            public void run() {

                // this is used in nextEntry() below, its what could be described as callback method

                try {

                    for (; ; ) {

                        byte[] item = null;
                        try {


                            for (; ; ) {
                                isReadingEntry.set(true);
                                item = input.poll();
                                if (item == null) {
                                    isReadingEntry.set(false);
                                    Thread.sleep(1);
                                } else {
                                    break;
                                }

                            }

                            final ByteBufferBytes bufferBytes = new ByteBufferBytes(ByteBuffer.wrap(item));

                            while (bufferBytes.remaining() > 0) {

                                final long entrySize = bufferBytes.readStopBit();

                                final long position = bufferBytes.position();
                                final long limit = bufferBytes.limit();

                                bufferBytes.limit(position + entrySize);
                                externalizable.readExternalEntry(bufferBytes);

                                bufferBytes.position(position);
                                bufferBytes.limit(limit);

                                // skip onto the next entry
                                bufferBytes.skip(entrySize);

                            }
                            isReadingEntry.set(false);

                        } catch (InterruptedException e1) {
                            LOG.warn("", e1);
                        }

                    }
                } catch (Exception e) {
                    LOG.warn("", e);
                }

            }

        });

        // out bound
        Executors.newSingleThreadExecutor().execute(new Runnable() {


            @Override
            public void run() {

                buffer = new ByteBufferBytes(ByteBuffer.allocate(entrySize0 * MAX_NUMBER_OF_ENTRIES_PER_CHUNK));

                // this is used in nextEntry() below, its what could be described as callback method
                final Replica.AbstractEntryCallback entryCallback =
                        new Replica.AbstractEntryCallback() {

View Full Code Here

    private IntValue$$Native value;

    @Before
    public void setup() throws IOException {
        value = new IntValue$$Native();
        value.bytes(new ByteBufferBytes(ByteBuffer.allocateDirect(4)), 0);
        map1 = newTcpSocketShmIntValueString((byte) 1, 8076, new InetSocketAddress("localhost", 8077));
        map2 = newTcpSocketShmIntValueString((byte) 2, 8077);
    }
View Full Code Here

        private final EntryCallback entryCallback;
        private long lastSentTime;

        private TcpSocketChannelEntryWriter() {
            out = ByteBuffer.allocateDirect(packetSize + maxEntrySizeBytes);
            in = new ByteBufferBytes(out);
            entryCallback = new EntryCallback(externalizable, in);
        }
View Full Code Here

        private int sizeOfNextEntry = Integer.MIN_VALUE;
        public long lastHeartBeatReceived = System.currentTimeMillis();

        private TcpSocketChannelEntryReader() {
            in = ByteBuffer.allocateDirect(packetSize + maxEntrySizeBytes);
            out = new ByteBufferBytes(in);
            out.limit(0);
            in.clear();
        }
View Full Code Here

        UdpSocketChannelEntryWriter(final int serializedEntrySize,
                                    @NotNull final Replica.EntryExternalizable externalizable) {

            // we make the buffer twice as large just to give ourselves headroom
            out = ByteBuffer.allocateDirect(serializedEntrySize * 2);
            in = new ByteBufferBytes(out);
            entryCallback = new EntryCallback(externalizable, in);

        }
View Full Code Here

        UdpSocketChannelEntryReader(final int serializedEntrySize,
                                    @NotNull final Replica.EntryExternalizable externalizable) {
            // we make the buffer twice as large just to give ourselves headroom
            in = ByteBuffer.allocateDirect(serializedEntrySize * 2);
            this.externalizable = externalizable;
            out = new ByteBufferBytes(in);
            out.limit(0);
            in.clear();
        }
View Full Code Here

TOP

Related Classes of net.openhft.lang.io.ByteBufferBytes

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.