@SuppressWarnings("unchecked") private MasterComputable<MASTER_RESULT, WORKER_RESULT> newMasterComputable() { MasterComputable<MASTER_RESULT, WORKER_RESULT> masterComputable; try { masterComputable = (MasterComputable<MASTER_RESULT, WORKER_RESULT>) ReflectionUtils.newInstance(Class .forName(this.getProps().get(GuaguaConstants.MASTER_COMPUTABLE_CLASS).toString())); } catch (ClassNotFoundException e) { throw new GuaguaRuntimeException(e); } return masterComputable; }
/** * Parameter initialization, such as set result class name, iteration number and so on. */ @Override public void init(Properties props) { this.setProps(props); checkAndSetMasterInterceptors(props); this.setMasterComputable(newMasterComputable()); this.isMonitored = this.getMasterComputable().getClass().isAnnotationPresent(ComputableMonitor.class); if(this.isMonitored) { this.isSoftForComputableTimeout = masterComputable.getClass().getAnnotation(ComputableMonitor.class) .isSoft(); this.executor = Executors.newSingleThreadExecutor(); } this.setTotalIteration(Integer.valueOf(this.getProps().getProperty(GuaguaConstants.GUAGUA_ITERATION_COUNT, Integer.MAX_VALUE + ""))); this.setWorkers(Integer.valueOf(this.getProps().getProperty(GuaguaConstants.GUAGUA_WORKER_NUMBER))); this.setMasterResultClassName(this.getProps().getProperty(GuaguaConstants.GUAGUA_MASTER_RESULT_CLASS)); this.setWorkerResultClassName(this.getProps().getProperty(GuaguaConstants.GUAGUA_WORKER_RESULT_CLASS)); double minWorkersRatio = NumberFormatUtils.getDouble( this.getProps().getProperty(GuaguaConstants.GUAGUA_MIN_WORKERS_RATIO), GuaguaConstants.GUAGUA_DEFAULT_MIN_WORKERS_RATIO); this.setMinWorkersRatio(minWorkersRatio); long minWorkersTimeOut = NumberFormatUtils.getLong( this.getProps().getProperty(GuaguaConstants.GUAGUA_MIN_WORKERS_TIMEOUT), 5 * 1000l); this.setMinWorkersTimeOut(minWorkersTimeOut); }
private MasterContext<MASTER_RESULT, WORKER_RESULT> buildContext() { if(getContext() != null) { return getContext(); } this.context = new MasterContext<MASTER_RESULT, WORKER_RESULT>(getTotalIteration(), getWorkers(), getProps(), getAppId(), getContainerId(), getMasterResultClassName(), getWorkerResultClassName(), getMinWorkersRatio(), getMinWorkersTimeOut()); return getContext(); }