io.deephaven.chunk.util.pools.MultiChunkPool Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of deephaven-engine-chunk Show documentation
Show all versions of deephaven-engine-chunk Show documentation
Engine Chunks: Array-like data structures for dense, efficient data movement
The newest version!
//
// Copyright (c) 2016-2024 Deephaven Data Labs and Patent Pending
//
package io.deephaven.chunk.util.pools;
import io.deephaven.chunk.ChunkType;
import io.deephaven.chunk.ResettableBooleanChunk;
import io.deephaven.chunk.ResettableByteChunk;
import io.deephaven.chunk.ResettableCharChunk;
import io.deephaven.chunk.ResettableDoubleChunk;
import io.deephaven.chunk.ResettableFloatChunk;
import io.deephaven.chunk.ResettableIntChunk;
import io.deephaven.chunk.ResettableLongChunk;
import io.deephaven.chunk.ResettableObjectChunk;
import io.deephaven.chunk.ResettableShortChunk;
import io.deephaven.chunk.ResettableWritableBooleanChunk;
import io.deephaven.chunk.ResettableWritableByteChunk;
import io.deephaven.chunk.ResettableWritableCharChunk;
import io.deephaven.chunk.ResettableWritableDoubleChunk;
import io.deephaven.chunk.ResettableWritableFloatChunk;
import io.deephaven.chunk.ResettableWritableIntChunk;
import io.deephaven.chunk.ResettableWritableLongChunk;
import io.deephaven.chunk.ResettableWritableObjectChunk;
import io.deephaven.chunk.ResettableWritableShortChunk;
import io.deephaven.chunk.WritableBooleanChunk;
import io.deephaven.chunk.WritableByteChunk;
import io.deephaven.chunk.WritableCharChunk;
import io.deephaven.chunk.WritableDoubleChunk;
import io.deephaven.chunk.WritableFloatChunk;
import io.deephaven.chunk.WritableIntChunk;
import io.deephaven.chunk.WritableLongChunk;
import io.deephaven.chunk.WritableObjectChunk;
import io.deephaven.chunk.WritableShortChunk;
import io.deephaven.chunk.attributes.Any;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.EnumMap;
import java.util.Map;
/**
* Provides a set of per-type {@link ChunkPool}s. Normally accessed via a {@link ThreadLocal}, to allow some threads to
* share a common pool and others to allocate their own.
*/
public final class MultiChunkPool implements BooleanChunkPool, ByteChunkPool, CharChunkPool, ShortChunkPool,
IntChunkPool, LongChunkPool, FloatChunkPool, DoubleChunkPool, ObjectChunkPool {
private static final MultiChunkPool SHARED_POOL = new MultiChunkPool();
private static final ThreadLocal POOL_THREAD_LOCAL = ThreadLocal.withInitial(() -> SHARED_POOL);
public static void enableDedicatedPoolForThisThread() {
if (POOL_THREAD_LOCAL.get() == SHARED_POOL) {
POOL_THREAD_LOCAL.set(new MultiChunkPool());
}
}
public static MultiChunkPool forThisThread() {
return POOL_THREAD_LOCAL.get();
}
private final BooleanChunkPool booleanChunkPool = new BooleanChunkSoftPool();
private final CharChunkPool charChunkPool = new CharChunkSoftPool();
private final ByteChunkPool byteChunkPool = new ByteChunkSoftPool();
private final ShortChunkPool shortChunkPool = new ShortChunkSoftPool();
private final IntChunkPool intChunkPool = new IntChunkSoftPool();
private final LongChunkPool longChunkPool = new LongChunkSoftPool();
private final FloatChunkPool floatChunkPool = new FloatChunkSoftPool();
private final DoubleChunkPool doubleChunkPool = new DoubleChunkSoftPool();
private final ObjectChunkPool objectChunkPool = new ObjectChunkSoftPool();
private final Map pools;
{
final EnumMap tempPools = new EnumMap<>(ChunkType.class);
tempPools.put(ChunkType.Boolean, booleanChunkPool.asChunkPool());
tempPools.put(ChunkType.Char, charChunkPool.asChunkPool());
tempPools.put(ChunkType.Byte, byteChunkPool.asChunkPool());
tempPools.put(ChunkType.Short, shortChunkPool.asChunkPool());
tempPools.put(ChunkType.Int, intChunkPool.asChunkPool());
tempPools.put(ChunkType.Long, longChunkPool.asChunkPool());
tempPools.put(ChunkType.Float, floatChunkPool.asChunkPool());
tempPools.put(ChunkType.Double, doubleChunkPool.asChunkPool());
tempPools.put(ChunkType.Object, objectChunkPool.asChunkPool());
pools = Collections.unmodifiableMap(tempPools);
}
private MultiChunkPool() {}
@SuppressWarnings("unused")
public ChunkPool getChunkPool(@NotNull final ChunkType chunkType) {
return pools.get(chunkType);
}
public BooleanChunkPool getBooleanChunkPool() {
return booleanChunkPool;
}
public CharChunkPool getCharChunkPool() {
return charChunkPool;
}
public ByteChunkPool getByteChunkPool() {
return byteChunkPool;
}
public ShortChunkPool getShortChunkPool() {
return shortChunkPool;
}
public IntChunkPool getIntChunkPool() {
return intChunkPool;
}
public LongChunkPool getLongChunkPool() {
return longChunkPool;
}
public FloatChunkPool getFloatChunkPool() {
return floatChunkPool;
}
public DoubleChunkPool getDoubleChunkPool() {
return doubleChunkPool;
}
public ObjectChunkPool getObjectChunkPool() {
return objectChunkPool;
}
@Override
public ChunkPool asChunkPool() {
throw new UnsupportedOperationException(
"MultiChunkPool can't create a ChunkPool, call this on the specific type required");
}
@Override
public WritableBooleanChunk takeWritableBooleanChunk(int capacity) {
return booleanChunkPool.takeWritableBooleanChunk(capacity);
}
@Override
public void giveWritableBooleanChunk(@NotNull WritableBooleanChunk> writableBooleanChunk) {
booleanChunkPool.giveWritableBooleanChunk(writableBooleanChunk);
}
@Override
public ResettableBooleanChunk takeResettableBooleanChunk() {
return booleanChunkPool.takeResettableBooleanChunk();
}
@Override
public void giveResettableBooleanChunk(@NotNull ResettableBooleanChunk> resettableBooleanChunk) {
booleanChunkPool.giveResettableBooleanChunk(resettableBooleanChunk);
}
@Override
public ResettableWritableBooleanChunk takeResettableWritableBooleanChunk() {
return booleanChunkPool.takeResettableWritableBooleanChunk();
}
@Override
public void giveResettableWritableBooleanChunk(
@NotNull ResettableWritableBooleanChunk> resettableWritableBooleanChunk) {
booleanChunkPool.giveResettableWritableBooleanChunk(resettableWritableBooleanChunk);
}
@Override
public WritableCharChunk takeWritableCharChunk(int capacity) {
return charChunkPool.takeWritableCharChunk(capacity);
}
@Override
public void giveWritableCharChunk(@NotNull WritableCharChunk> writableCharChunk) {
charChunkPool.giveWritableCharChunk(writableCharChunk);
}
@Override
public ResettableCharChunk takeResettableCharChunk() {
return charChunkPool.takeResettableCharChunk();
}
@Override
public void giveResettableCharChunk(@NotNull ResettableCharChunk> resettableCharChunk) {
charChunkPool.giveResettableCharChunk(resettableCharChunk);
}
@Override
public ResettableWritableCharChunk takeResettableWritableCharChunk() {
return charChunkPool.takeResettableWritableCharChunk();
}
@Override
public void giveResettableWritableCharChunk(@NotNull ResettableWritableCharChunk> resettableWritableCharChunk) {
charChunkPool.giveResettableWritableCharChunk(resettableWritableCharChunk);
}
@Override
public WritableByteChunk takeWritableByteChunk(int capacity) {
return byteChunkPool.takeWritableByteChunk(capacity);
}
@Override
public void giveWritableByteChunk(@NotNull WritableByteChunk> writableByteChunk) {
byteChunkPool.giveWritableByteChunk(writableByteChunk);
}
@Override
public ResettableByteChunk takeResettableByteChunk() {
return byteChunkPool.takeResettableByteChunk();
}
@Override
public void giveResettableByteChunk(@NotNull ResettableByteChunk> resettableByteChunk) {
byteChunkPool.giveResettableByteChunk(resettableByteChunk);
}
@Override
public ResettableWritableByteChunk takeResettableWritableByteChunk() {
return byteChunkPool.takeResettableWritableByteChunk();
}
@Override
public void giveResettableWritableByteChunk(@NotNull ResettableWritableByteChunk> resettableWritableByteChunk) {
byteChunkPool.giveResettableWritableByteChunk(resettableWritableByteChunk);
}
@Override
public WritableShortChunk takeWritableShortChunk(int capacity) {
return shortChunkPool.takeWritableShortChunk(capacity);
}
@Override
public void giveWritableShortChunk(@NotNull WritableShortChunk> writableShortChunk) {
shortChunkPool.giveWritableShortChunk(writableShortChunk);
}
@Override
public ResettableShortChunk takeResettableShortChunk() {
return shortChunkPool.takeResettableShortChunk();
}
@Override
public void giveResettableShortChunk(@NotNull ResettableShortChunk> resettableShortChunk) {
shortChunkPool.giveResettableShortChunk(resettableShortChunk);
}
@Override
public ResettableWritableShortChunk takeResettableWritableShortChunk() {
return shortChunkPool.takeResettableWritableShortChunk();
}
@Override
public void giveResettableWritableShortChunk(
@NotNull ResettableWritableShortChunk> resettableWritableShortChunk) {
shortChunkPool.giveResettableWritableShortChunk(resettableWritableShortChunk);
}
@Override
public WritableIntChunk takeWritableIntChunk(int capacity) {
return intChunkPool.takeWritableIntChunk(capacity);
}
@Override
public void giveWritableIntChunk(@NotNull WritableIntChunk> writableIntChunk) {
intChunkPool.giveWritableIntChunk(writableIntChunk);
}
@Override
public ResettableIntChunk takeResettableIntChunk() {
return intChunkPool.takeResettableIntChunk();
}
@Override
public void giveResettableIntChunk(@NotNull ResettableIntChunk> resettableIntChunk) {
intChunkPool.giveResettableIntChunk(resettableIntChunk);
}
@Override
public ResettableWritableIntChunk takeResettableWritableIntChunk() {
return intChunkPool.takeResettableWritableIntChunk();
}
@Override
public void giveResettableWritableIntChunk(@NotNull ResettableWritableIntChunk> resettableWritableIntChunk) {
intChunkPool.giveResettableWritableIntChunk(resettableWritableIntChunk);
}
@Override
public WritableLongChunk takeWritableLongChunk(int capacity) {
return longChunkPool.takeWritableLongChunk(capacity);
}
@Override
public void giveWritableLongChunk(@NotNull WritableLongChunk> writableLongChunk) {
longChunkPool.giveWritableLongChunk(writableLongChunk);
}
@Override
public ResettableLongChunk takeResettableLongChunk() {
return longChunkPool.takeResettableLongChunk();
}
@Override
public void giveResettableLongChunk(@NotNull ResettableLongChunk> resettableLongChunk) {
longChunkPool.giveResettableLongChunk(resettableLongChunk);
}
@Override
public ResettableWritableLongChunk takeResettableWritableLongChunk() {
return longChunkPool.takeResettableWritableLongChunk();
}
@Override
public void giveResettableWritableLongChunk(@NotNull ResettableWritableLongChunk> resettableWritableLongChunk) {
longChunkPool.giveResettableWritableLongChunk(resettableWritableLongChunk);
}
@Override
public WritableFloatChunk takeWritableFloatChunk(int capacity) {
return floatChunkPool.takeWritableFloatChunk(capacity);
}
@Override
public void giveWritableFloatChunk(@NotNull WritableFloatChunk> writableFloatChunk) {
floatChunkPool.giveWritableFloatChunk(writableFloatChunk);
}
@Override
public ResettableFloatChunk takeResettableFloatChunk() {
return floatChunkPool.takeResettableFloatChunk();
}
@Override
public void giveResettableFloatChunk(@NotNull ResettableFloatChunk> resettableFloatChunk) {
floatChunkPool.giveResettableFloatChunk(resettableFloatChunk);
}
@Override
public ResettableWritableFloatChunk takeResettableWritableFloatChunk() {
return floatChunkPool.takeResettableWritableFloatChunk();
}
@Override
public void giveResettableWritableFloatChunk(
@NotNull ResettableWritableFloatChunk> resettableWritableFloatChunk) {
floatChunkPool.giveResettableWritableFloatChunk(resettableWritableFloatChunk);
}
@Override
public WritableDoubleChunk takeWritableDoubleChunk(int capacity) {
return doubleChunkPool.takeWritableDoubleChunk(capacity);
}
@Override
public void giveWritableDoubleChunk(@NotNull WritableDoubleChunk> writableDoubleChunk) {
doubleChunkPool.giveWritableDoubleChunk(writableDoubleChunk);
}
@Override
public ResettableDoubleChunk takeResettableDoubleChunk() {
return doubleChunkPool.takeResettableDoubleChunk();
}
@Override
public void giveResettableDoubleChunk(@NotNull ResettableDoubleChunk> resettableDoubleChunk) {
doubleChunkPool.giveResettableDoubleChunk(resettableDoubleChunk);
}
@Override
public ResettableWritableDoubleChunk takeResettableWritableDoubleChunk() {
return doubleChunkPool.takeResettableWritableDoubleChunk();
}
@Override
public void giveResettableWritableDoubleChunk(
@NotNull ResettableWritableDoubleChunk> resettableWritableDoubleChunk) {
doubleChunkPool.giveResettableWritableDoubleChunk(resettableWritableDoubleChunk);
}
@Override
public WritableObjectChunk takeWritableObjectChunk(int capacity) {
return objectChunkPool.takeWritableObjectChunk(capacity);
}
@Override
public void giveWritableObjectChunk(@NotNull WritableObjectChunk, ?> writableObjectChunk) {
objectChunkPool.giveWritableObjectChunk(writableObjectChunk);
}
@Override
public ResettableObjectChunk takeResettableObjectChunk() {
return objectChunkPool.takeResettableObjectChunk();
}
@Override
public void giveResettableObjectChunk(@NotNull ResettableObjectChunk, ?> resettableObjectChunk) {
objectChunkPool.giveResettableObjectChunk(resettableObjectChunk);
}
@Override
public ResettableWritableObjectChunk takeResettableWritableObjectChunk() {
return objectChunkPool.takeResettableWritableObjectChunk();
}
@Override
public void giveResettableWritableObjectChunk(
@NotNull ResettableWritableObjectChunk, ?> resettableWritableObjectChunk) {
objectChunkPool.giveResettableWritableObjectChunk(resettableWritableObjectChunk);
}
}