com.ning.compress.lzf.parallel.BlockManager Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spark-core Show documentation
Show all versions of spark-core Show documentation
Shaded version of Apache Spark 2.x.x for Presto
The newest version!
package com.ning.compress.lzf.parallel;
import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
/**
* @author Cédrik LIME
*/
class BlockManager {
/* used as a blocking Stack (FIFO) */
private final BlockingDeque blockPool;
public BlockManager(int blockPoolSize, int blockSize) {
// log.debug("Using block pool size of " + blockPoolSize);
blockPool = new LinkedBlockingDeque(blockPoolSize);
for (int i = 0; i < blockPoolSize; ++i) {
blockPool.addFirst(new byte[blockSize]);
}
}
public byte[] getBlockFromPool() {
byte[] block = null;
try {
block = blockPool.takeFirst();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return block;
}
public void releaseBlockToPool(byte[] block) {
assert ! blockPool.contains(block);
// Arrays.fill(block, (byte)0);
try {
blockPool.putLast(block);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy