MASTER_RESULT - master result for computation in each iteration.WORKER_RESULT - worker result for computation in each iteration.KEY - key type for each recordVALUE - value type for each recordpublic abstract class AbstractWorkerComputable<MASTER_RESULT extends Bytable,WORKER_RESULT extends Bytable,KEY extends Bytable,VALUE extends Bytable> extends Object implements WorkerComputable<MASTER_RESULT,WORKER_RESULT>
WorkerComputable implementation to load data one by one and only in the very 1st iteration.
To load data successfully, make sure GuaguaRecordReader is initialized firstly.
After data is loaded in the first iteration, one can store the data into collections (meomory or disk) to do later iteration logic.
TODO add multi-thread version to load data.
| Constructor and Description |
|---|
AbstractWorkerComputable() |
| Modifier and Type | Method and Description |
|---|---|
WORKER_RESULT |
compute(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Worker computation for each iteration.
|
abstract WORKER_RESULT |
doCompute(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Real computation logic after data loading.
|
GuaguaRecordReader<KEY,VALUE> |
getRecordReader() |
abstract void |
init(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Initialization work for the whole computation
|
abstract void |
initRecordReader(GuaguaFileSplit fileSplit)
Each
GuaguaFileSplit must be initialized before loading data. |
abstract void |
load(KEY currentKey,
VALUE currentValue,
WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Load data one by one before computation.
|
protected void |
postLoad(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Do some post work before loading data.
|
protected void |
preLoad(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
Do some pre work before loading data.
|
void |
setRecordReader(GuaguaRecordReader<KEY,VALUE> recordReader) |
public WORKER_RESULT compute(WorkerContext<MASTER_RESULT,WORKER_RESULT> context) throws IOException
WorkerComputablecompute in interface WorkerComputable<MASTER_RESULT extends Bytable,WORKER_RESULT extends Bytable>context - the worker context instance which includes worker info, master result of last iteration or other
useful into for each iteration.IOException - if any io exception in computation, for example, IOException in reading data.protected void preLoad(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
protected void postLoad(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
public abstract void initRecordReader(GuaguaFileSplit fileSplit) throws IOException
GuaguaFileSplit must be initialized before loading data.IOExceptionpublic abstract void init(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
public abstract WORKER_RESULT doCompute(WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
public abstract void load(KEY currentKey, VALUE currentValue, WorkerContext<MASTER_RESULT,WORKER_RESULT> context)
public GuaguaRecordReader<KEY,VALUE> getRecordReader()
public void setRecordReader(GuaguaRecordReader<KEY,VALUE> recordReader)
Copyright © 2018. All Rights Reserved.