All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.deephaven.kafka.publish.SimpleKeyOrValueSerializer Maven / Gradle / Ivy

There is a newer version: 0.37.1
Show newest version
/**
 * Copyright (c) 2016-2022 Deephaven Data Labs and Patent Pending
 */
package io.deephaven.kafka.publish;

import io.deephaven.chunk.attributes.Values;
import io.deephaven.engine.table.Table;
import io.deephaven.engine.table.ColumnSource;
import io.deephaven.chunk.Chunk;
import io.deephaven.engine.table.ChunkSource;
import io.deephaven.chunk.ObjectChunk;
import io.deephaven.engine.table.impl.chunkboxer.ChunkBoxer;
import io.deephaven.engine.rowset.RowSequence;
import org.jetbrains.annotations.NotNull;

public class SimpleKeyOrValueSerializer implements KeyOrValueSerializer {

    private final ColumnSource source;
    private final ChunkBoxer.BoxerKernel boxer;

    public SimpleKeyOrValueSerializer(Table table, String columnName) {
        source = table.getColumnSource(columnName);
        boxer = ChunkBoxer.getBoxer(source.getChunkType(), PublishToKafka.CHUNK_SIZE);
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public ObjectChunk handleChunk(
            @NotNull final Context context,
            @NotNull final RowSequence rowSequence,
            final boolean previous) {
        final SimpleContext simpleContext = (SimpleContext) context;
        final Chunk chunk;
        if (previous) {
            chunk = source.getPrevChunk(simpleContext.sourceGetContext, rowSequence);
        } else {
            chunk = source.getChunk(simpleContext.sourceGetContext, rowSequence);
        }
        return boxer.box(chunk);
    }

    @Override
    public Context makeContext(int size) {
        return new SimpleContext(size);
    }

    private class SimpleContext implements Context {

        private final ChunkSource.GetContext sourceGetContext;

        private SimpleContext(final int size) {
            sourceGetContext = source.makeGetContext(size);
        }

        @Override
        public void close() {
            sourceGetContext.close();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy