org.embulk.spi.PageImpl Maven / Gradle / Ivy
package org.embulk.spi;
import java.util.List;
import org.msgpack.value.ImmutableValue;
/**
* Page is an in-process (in-JVM) container of data records.
*
* It serializes records to byte[] (in org.embulk.spi.Buffer) in order to:
* A) Avoid slowness by handling many Java Objects
* B) Avoid complexity by type-safe primitive arrays
* C) Track memory consumption by records
* D) Use off-heap memory
*
* (C) and (D) may not be so meaningful as of v0.7+ (or since earlier) as recent Embulk unlikely
* allocates so many Pages at the same time. Recent Embulk is streaming-driven instead of
* multithreaded queue-based.
*
* Page is NOT for inter-process communication. For multi-process execution such as MapReduce
* Executor, the executor plugin takes responsibility about interoperable serialization.
*/
public class PageImpl extends Page {
private final Buffer buffer;
private List stringReferences;
private List valueReferences;
protected PageImpl(Buffer buffer) {
this.buffer = buffer;
}
@SuppressWarnings("deprecation") // Page.allocate(int) is deprecated.
public static Page allocate(int length) {
return new PageImpl(BufferImpl.allocate(length));
}
@SuppressWarnings("deprecation") // Page.wrap(Buffer) is deprecated.
public static Page wrap(Buffer buffer) {
return new PageImpl(buffer);
}
@Override
public Page setStringReferences(List values) {
this.stringReferences = values;
return this;
}
@Override
public Page setValueReferences(List values) {
this.valueReferences = values;
return this;
}
@Override
public List getStringReferences() {
// TODO used by mapreduce executor
return stringReferences;
}
@Override
public List getValueReferences() {
// TODO used by mapreduce executor
return valueReferences;
}
@Override
public String getStringReference(int index) {
return stringReferences.get(index);
}
@Override
public ImmutableValue getValueReference(int index) {
return valueReferences.get(index);
}
@Override
public void release() {
buffer.release();
}
@Override
public Buffer buffer() {
return buffer;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy