RemotingCommand commandRequest = RemotingCommand.createRequestCommand(JobProtos.RequestCode.JOB_COMPLETED.code(), requestBody);
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); } }
public static RequestCode valueOf(int code) { for (RequestCode requestCode : RequestCode.values()) { if (requestCode.code == code) { return requestCode; } } throw new IllegalArgumentException("can't find the request code !"); }
int requestCode = JobProtos.RequestCode.JOB_COMPLETED.code();
RemotingCommand commandRequest = RemotingCommand.createRequestCommand(JobProtos.RequestCode.PUSH_JOB.code(), body);
JobProtos.RequestCode.SUBMIT_JOB.code(), jobSubmitRequest);
RemotingCommand commandRequest = RemotingCommand.createRequestCommand(JobProtos.RequestCode.JOB_COMPLETED.code(), requestBody);
RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.BIZ_LOG_SEND.code(), requestBody); try {
JobProtos.RequestCode.CANCEL_JOB.code(), request);
RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.JOB_ASK.code(), requestBody); remotingServer.invokeAsync(channel, request, new AsyncCallback() { @Override
RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.JOB_PULL.code(), requestBody);
/** * 发送JobResults */ private boolean retrySendJobResults(List<JobRunResult> results) { // 发送消息给 JobTracker JobCompletedRequest requestBody = appContext.getCommandBodyWrapper().wrapper(new JobCompletedRequest()); requestBody.setJobRunResults(results); requestBody.setReSend(true); int requestCode = JobProtos.RequestCode.JOB_COMPLETED.code(); RemotingCommand request = RemotingCommand.createRequestCommand(requestCode, requestBody); try { // 这里一定要用同步,不然异步会发生文件锁,死锁 RemotingCommand commandResponse = remotingClient.invokeSync(request); if (commandResponse != null && commandResponse.getCode() == RemotingProtos.ResponseCode.SUCCESS.code()) { return true; } else { LOGGER.warn("Send job failed, {}", commandResponse); return false; } } catch (JobTrackerNotFoundException e) { LOGGER.error("Retry send job result failed! jobResults={}", results, e); } return false; }
/** * 发送心跳 */ private boolean beat(RemotingClientDelegate remotingClient, String addr) { HeartBeatRequest commandBody = appContext.getCommandBodyWrapper().wrapper(new HeartBeatRequest()); RemotingCommand request = RemotingCommand.createRequestCommand( JobProtos.RequestCode.HEART_BEAT.code(), commandBody); try { RemotingCommand response = remotingClient.getRemotingClient().invokeSync(addr, request, 5000); if (response != null && JobProtos.ResponseCode.HEART_BEAT_SUCCESS == JobProtos.ResponseCode.valueOf(response.getCode())) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("heart beat success. "); } return true; } } catch (Exception e) { LOGGER.warn(e.getMessage()); } return false; }
private boolean sendBizLog(List<BizLog> bizLogs) { if (CollectionUtils.isEmpty(bizLogs)) { return true; } BizLogSendRequest requestBody = CommandBodyWrapper.wrapper(appContext, new BizLogSendRequest()); requestBody.setBizLogs(bizLogs); RemotingCommand request = RemotingCommand.createRequestCommand(JobProtos.RequestCode.BIZ_LOG_SEND.code(), requestBody); try { RemotingCommand response = remotingClient.invokeSync(request); if (response != null && response.getCode() == JobProtos.ResponseCode.BIZ_LOG_SEND_SUCCESS.code()) { // success return true; } } catch (JobTrackerNotFoundException ignored) { } return false; }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { // 心跳 if (request.getCode() == JobProtos.RequestCode.HEART_BEAT.code()) { offerHandler(channel, request); return RemotingCommand.createResponseCommand(JobProtos.ResponseCode.HEART_BEAT_SUCCESS.code(), ""); } if (reqLimitEnable) { return doBizWithReqLimit(channel, request); } else { return doBiz(channel, request); } }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = JobProtos.RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); }
public static RequestCode valueOf(int code) { for (RequestCode requestCode : RequestCode.values()) { if (requestCode.code == code) { return requestCode; } } throw new IllegalArgumentException("can't find the request code !"); }
@Override public RemotingCommand processRequest(Channel channel, RemotingCommand request) throws RemotingCommandException { JobProtos.RequestCode code = valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } return processor.processRequest(channel, request); } }
private RemotingCommand doBiz(Channel channel, RemotingCommand request) throws RemotingCommandException { // 其他的请求code RequestCode code = RequestCode.valueOf(request.getCode()); RemotingProcessor processor = processors.get(code); if (processor == null) { return RemotingCommand.createResponseCommand(RemotingProtos.ResponseCode.REQUEST_CODE_NOT_SUPPORTED.code(), "request code not supported!"); } offerHandler(channel, request); return processor.processRequest(channel, request); }
RemotingCommand commandRequest = RemotingCommand.createRequestCommand(JobProtos.RequestCode.PUSH_JOB.code(), body);