public abstract void interrupt(); }
public Result run(JobContext jobContext) throws Throwable { // 1. 设置LTS环境为 UNIT_TEST LTSConfig.setEnvironment(Environment.UNIT_TEST); // 设置 BizLogger jobContext.setBizLogger(BizLoggerFactory.getLogger(Level.INFO, null, null)); // 2. load context (Spring Context 或者其他的) initContext(); // 3. new jobRunner JobRunner jobRunner = newJobRunner(); // 4. run job return jobRunner.run(jobContext); }
private void interrupt() { if (!interrupted.compareAndSet(false, true)) { return; } if (this.curJobRunner != null && this.curJobRunner instanceof InterruptibleJobRunner) { ((InterruptibleJobRunner) this.curJobRunner).interrupt(); } }
public RunnerPool(final TaskTrackerAppContext appContext) { this.appContext = appContext; this.runningJobManager = new RunningJobManager(); threadPoolExecutor = initThreadPoolExecutor(); runnerFactory = appContext.getRunnerFactory(); if (runnerFactory == null) { runnerFactory = new DefaultRunnerFactory(appContext); } // 向事件中心注册事件, 改变工作线程大小 appContext.getEventCenter().subscribe( new EventSubscriber(appContext.getConfig().getIdentity(), new Observer() { @Override public void onObserved(EventInfo eventInfo) { setWorkThread(appContext.getConfig().getWorkThreads()); } }), EcTopic.WORK_THREAD_CHANGE); }
@Override public HttpCmdResponse execute(HttpCmdRequest request) throws Exception { String jobId = request.getParam("jobId"); if (StringUtils.isEmpty(jobId)) { return HttpCmdResponse.newResponse(false, "jobId can't be empty"); } if (!appContext.getRunnerPool().getRunningJobManager().running(jobId)) { return HttpCmdResponse.newResponse(false, "jobId dose not running in this TaskTracker now"); } appContext.getRunnerPool().getRunningJobManager().terminateJob(jobId); return HttpCmdResponse.newResponse(true, "Execute terminate Command success"); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobAskRequest requestBody = request.getBody(); List<String> jobIds = requestBody.getJobIds(); List<String> notExistJobIds = appContext.getRunnerPool() .getRunningJobManager().getNotExists(jobIds); JobAskResponse responseBody = CommandBodyWrapper.wrapper(appContext, new JobAskResponse()); responseBody.setJobIds(notExistJobIds); return RemotingCommand.createResponseCommand( RemotingProtos.ResponseCode.SUCCESS.code(), "查询成功", responseBody); } }
private void checkInterrupted(BizLogger logger) { try { if (isInterrupted()) { logger.info("SYSTEM:Interrupted"); } } catch (Throwable t) { LOGGER.warn("checkInterrupted error", t); } }
@Override public void onObserved(EventInfo eventInfo) { setWorkThread(appContext.getConfig().getWorkThreads()); } }), EcTopic.WORK_THREAD_CHANGE);
public void terminateJob(String jobId) { JobRunnerDelegate jobRunnerDelegate = JOBS.get(jobId); if (jobRunnerDelegate != null) { try { jobRunnerDelegate.currentThread().interrupt(); } catch (Throwable e) { LOGGER.error("terminateJob [" + jobId + "] error", e); } } } }
@Override protected void afterStop() { appContext.getMStatReporter().stop(); appContext.getStopWorkingMonitor().stop(); appContext.getRunnerPool().shutDown(); }
public Result run(JobContext jobContext) throws Throwable { // 1. 设置LTS环境为 UNIT_TEST LTSConfig.setEnvironment(Environment.UNIT_TEST); // 设置 BizLogger jobContext.setBizLogger(BizLoggerFactory.getLogger(Level.INFO, null, null)); // 2. load context (Spring Context 或者其他的) initContext(); // 3. new jobRunner JobRunner jobRunner = newJobRunner(); // 4. run job return jobRunner.run(jobContext); }
public RunnerPool(final TaskTrackerAppContext appContext) { this.appContext = appContext; this.runningJobManager = new RunningJobManager(); threadPoolExecutor = initThreadPoolExecutor(); runnerFactory = appContext.getRunnerFactory(); if (runnerFactory == null) { runnerFactory = new DefaultRunnerFactory(appContext); } // 向事件中心注册事件, 改变工作线程大小 appContext.getEventCenter().subscribe( new EventSubscriber(appContext.getConfig().getIdentity(), new Observer() { @Override public void onObserved(EventInfo eventInfo) { setWorkThread(appContext.getConfig().getWorkThreads()); } }), EcTopic.WORK_THREAD_CHANGE); }
@Override public HttpCmdResponse execute(HttpCmdRequest request) throws Exception { String jobId = request.getParam("jobId"); if (StringUtils.isEmpty(jobId)) { return HttpCmdResponse.newResponse(false, "jobId can't be empty"); } if (!appContext.getRunnerPool().getRunningJobManager().running(jobId)) { return HttpCmdResponse.newResponse(false, "jobId dose not running in this TaskTracker now"); } appContext.getRunnerPool().getRunningJobManager().terminateJob(jobId); return HttpCmdResponse.newResponse(true, "Execute terminate Command success"); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobAskRequest requestBody = request.getBody(); List<String> jobIds = requestBody.getJobIds(); List<String> notExistJobIds = appContext.getRunnerPool() .getRunningJobManager().getNotExists(jobIds); JobAskResponse responseBody = CommandBodyWrapper.wrapper(appContext, new JobAskResponse()); responseBody.setJobIds(notExistJobIds); return RemotingCommand.createResponseCommand( RemotingProtos.ResponseCode.SUCCESS.code(), "查询成功", responseBody); } }
private boolean isStopToGetNewJob() { if (isInterrupted()) { // 如果当前线程被阻断了,那么也就不接受新任务了 return true; } // 机器资源是否充足 return !appContext.getConfig().getInternalData(Constants.MACHINE_RES_ENOUGH, true); }
public abstract void interrupt(); }
private void interrupt() { if (!interrupted.compareAndSet(false, true)) { return; } if (this.curJobRunner != null && this.curJobRunner instanceof InterruptibleJobRunner) { ((InterruptibleJobRunner) this.curJobRunner).interrupt(); } }
@Override public void onObserved(EventInfo eventInfo) { setWorkThread(appContext.getConfig().getWorkThreads()); } }), EcTopic.WORK_THREAD_CHANGE);
private boolean isStopToGetNewJob() { if (isInterrupted()) { // 如果当前线程被阻断了,那么也就不接受新任务了 return true; } // 机器资源是否充足 return !appContext.getConfig().getInternalData(Constants.MACHINE_RES_ENOUGH, true); }
private void checkInterrupted(BizLogger logger) { try { if (isInterrupted()) { logger.info("SYSTEM:Interrupted"); } } catch (Throwable t) { LOGGER.warn("checkInterrupted error", t); } }