Package org.voltcore.utils

Examples of org.voltcore.utils.DeferredSerialization


    public static Supplier<DeferredSerialization> getSupplier(final ByteBuffer buf) {
        return new Supplier<DeferredSerialization>() {
            @Override
            public DeferredSerialization get() {
                 return new DeferredSerialization() {
                    @Override
                    public void serialize(final ByteBuffer outbuf) throws IOException {
                        outbuf.put(buf);
                    }
                    @Override
View Full Code Here


                return;
            }

            updateLastPendingWriteTimeAndQueueBackpressure();

            m_queuedWrites.offer(new DeferredSerialization() {
                @Override
                public void serialize(ByteBuffer outbuf) {
                    for (ByteBuffer buf : b) {
                        outbuf.put(buf);
                    }
View Full Code Here

     * and will be freed when the thread terminates.
     */
    @Override
    synchronized void shutdown() {
        super.shutdown();
        DeferredSerialization ds = null;
        while ((ds = m_queuedWrites.poll()) != null) {
            ds.cancel();
        }
    }
View Full Code Here

    final int swapAndSerializeQueuedWrites(final NetworkDBBPool pool) throws IOException {
        int processedWrites = 0;
        final ArrayDeque<DeferredSerialization> oldlist = getQueuedWrites();
        if (oldlist.isEmpty()) return 0;

        DeferredSerialization ds = null;
        int bytesQueued = 0;
        while ((ds = oldlist.poll()) != null) {
            processedWrites++;
            final int serializedSize = ds.getSerializedSize();
            if (serializedSize == DeferredSerialization.EMPTY_MESSAGE_LENGTH) continue;
            BBContainer outCont = m_queuedBuffers.peekLast();
            ByteBuffer outbuf = null;
            if (outCont == null || !outCont.b().hasRemaining()) {
                outCont = pool.acquire();
                outCont.b().clear();
                m_queuedBuffers.offer(outCont);
            }

            outbuf = outCont.b();

            //Fastpath, serialize to direct buffer creating no garbage
            if (outbuf.remaining() >= serializedSize) {
                final int oldLimit = outbuf.limit();
                outbuf.limit(outbuf.position() + serializedSize);
                final ByteBuffer slice = outbuf.slice();
                ds.serialize(slice);
                checkSloppySerialization(slice, ds);
                slice.position(0);
                bytesQueued += slice.remaining();
                outbuf.position(outbuf.limit());
                outbuf.limit(oldLimit);
            } else {
                //Slow path serialize to heap, and then put in buffers
                ByteBuffer buf = ByteBuffer.allocate(serializedSize);
                ds.serialize(buf);
                checkSloppySerialization(buf, ds);
                buf.position(0);
                bytesQueued += buf.remaining();
                while (buf.hasRemaining()) {
                    if (!outbuf.hasRemaining()) {
View Full Code Here

     * and will be freed when the thread terminates.
     */
    @Override
    synchronized void shutdown() {
        super.shutdown();
        DeferredSerialization ds = null;
        while ((ds = m_queuedWrites.poll()) != null) {
            ds.cancel();
        }
    }
View Full Code Here

        assert(!buf.isDirect());//Don't queue direct buffers, they leak memory without a container
        if (buf.remaining() == 0) {
            throw new IllegalArgumentException("Attempted to queue a zero length buffer");
        }
        if (m_isShutdown) return;
        m_queuedWrites.offer(new DeferredSerialization() {

            @Override
            public void serialize(final ByteBuffer outbuf) throws IOException {
                outbuf.put(buf);
            }
View Full Code Here

        if (destinations.length == 0) {
            return;
        }

        m_network.enqueue(
                new DeferredSerialization() {
                    @Override
                    public final void serialize(final ByteBuffer buf) throws IOException {
                        buf.putInt(buf.capacity() - 4);
                        buf.putLong(message.m_sourceHSId);
                        buf.putInt(destinations.length);
View Full Code Here

        // Deliver a restart response
        m_ci.m_mailbox.deliver(respMsg);

        // Make sure that the txn is NOT restarted
        DeferredSerialization resp = responsesDS.take();

        if (shouldRestart) {
            assertEquals(-1, resp.getSerializedSize());
            checkInitMsgSent("hello", 1, true, true);
        } else {
            assertTrue(-1 != resp.getSerializedSize());
            verify(m_messenger, never()).send(anyLong(), any(VoltMessage.class));
        }

        // the hashinator should've been updated in either case
        assertEquals(newHashinatorVersion, TheHashinator.getCurrentVersionedConfig().getFirst().longValue());
View Full Code Here

            //Change the bytes of the topology results and expect a topology update
            //to make its way to the client
            ByteBuffer expectedBuf = getClientResponse("bar");
            statsAnswers.offer(dsOf(expectedBuf));
            DeferredSerialization ds = responsesDS.take();
            ByteBuffer actualBuf = ByteBuffer.allocate(ds.getSerializedSize());
            ds.serialize(actualBuf);
            assertEquals(expectedBuf, actualBuf);
        } finally {
            RateLimitedClientNotifier.WARMUP_MS = 1000;
            ClientInterface.TOPOLOGY_CHANGE_CHECK_MS = 5000;
            m_ci.shutdown();
View Full Code Here

            m_ci.shutdown();
        }
    }

    private DeferredSerialization dsOf(final ByteBuffer buf) {
        return new DeferredSerialization() {
            @Override
            public void serialize(final ByteBuffer outbuf) throws IOException {
                outbuf.put(buf);
            }
            @Override
View Full Code Here

TOP

Related Classes of org.voltcore.utils.DeferredSerialization

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.