public abstract class AbstractMasterComputable<MASTER_RESULT extends Bytable,WORKER_RESULT extends Bytable> extends Object implements MasterComputable<MASTER_RESULT,WORKER_RESULT>
AbstractMasterComputable is a abstract MasterComputable implementation to add
init(MasterContext) for master. Real computation logic is derived into doCompute(MasterContext).| Modifier and Type | Field and Description |
|---|---|
protected AtomicBoolean |
isInitialized |
| Constructor and Description |
|---|
AbstractMasterComputable() |
| Modifier and Type | Method and Description |
|---|---|
MASTER_RESULT |
compute(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
Master computation for each iteration.
|
abstract MASTER_RESULT |
doCompute(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
Real computable logic excludes init part.
|
abstract void |
init(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
Initialization logic.
|
protected AtomicBoolean isInitialized
public MASTER_RESULT compute(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
MasterComputablecompute in interface MasterComputable<MASTER_RESULT extends Bytable,WORKER_RESULT extends Bytable>context - the master context instance which includes worker results and other useful parameters.public abstract void init(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
MasterComputable, for fail-over, the state should also be recoverd.
To do that, like this in this method:
if (!context.isFirstIteration) { // not first iteration means we need recover state
lastMasterResult = context.getMasterResult();
if ( lasterMasterResult != null ) {
this.weights = lastMasterResult.getWeights()
} else {
this.weights = initWeights();
}
}
public abstract MASTER_RESULT doCompute(MasterContext<MASTER_RESULT,WORKER_RESULT> context)
Copyright © 2019. All Rights Reserved.