Source:
public void start() { final File taskFile = Preconditions.checkNotNull(config.getTaskFile(), "taskFile"); final File statusFile = Preconditions.checkNotNull(config.getStatusFile(), "statusFile"); final File portFile = Preconditions.checkNotNull(config.getPortFile(), "portFile"); try(OutputStream outputStream = new FileOutputStream(portFile)){ outputStream.write(String.format("%d", druidNode.getPort()).getBytes("UTF-8")); } catch (IOException e) { throw Throwables.propagate(e); } final Task task; try { task = jsonMapper.readValue(taskFile, Task.class); log.info( "Running with task: %s", jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task) ); } catch (IOException e) { throw Throwables.propagate(e); } try { if (!task.isReady(taskActionClientFactory.create(task))) { throw new ISE("Task is not ready to run yet!", task.getId()); } } catch (Exception e) { throw new ISE(e, "Failed to run isReady", task.getId()); } statusFuture = Futures.transform( taskRunner.run(task), new Function<TaskStatus, TaskStatus>() { @Override public TaskStatus apply(TaskStatus taskStatus) { try { log.info( "Task completed with status: %s", jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskStatus) ); final File statusFileParent = statusFile.getParentFile(); if (statusFileParent != null) { statusFileParent.mkdirs(); } jsonMapper.writeValue(statusFile, taskStatus); return taskStatus; } catch (Exception e) { throw Throwables.propagate(e); } } } ); }

Target:
public void start() { final File taskFile = Preconditions.checkNotNull(config.getTaskFile(), "taskFile"); final File statusFile = Preconditions.checkNotNull(config.getStatusFile(), "statusFile"); final File portFile = Preconditions.checkNotNull(config.getPortFile(), "portFile"); try(final FileChannel portFileChannel = FileChannel.open(portFile.toPath(), StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE)) { final String portStr = String.format("%d", druidNode.getPort()); final FileLock lock = portFileChannel.lock(); try { CharsetEncoder encoder = Charsets.UTF_8.newEncoder(); portFileChannel.write(encoder.encode(CharBuffer.wrap(portStr))); }finally{ lock.release(); } } catch (IOException e) { throw Throwables.propagate(e); } final Task task; try { task = jsonMapper.readValue(taskFile, Task.class); log.info( "Running with task: %s", jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(task) ); } catch (IOException e) { throw Throwables.propagate(e); } try { if (!task.isReady(taskActionClientFactory.create(task))) { throw new ISE("Task is not ready to run yet!", task.getId()); } } catch (Exception e) { throw new ISE(e, "Failed to run isReady", task.getId()); } statusFuture = Futures.transform( taskRunner.run(task), new Function<TaskStatus, TaskStatus>() { @Override public TaskStatus apply(TaskStatus taskStatus) { try { log.info( "Task completed with status: %s", jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskStatus) ); final File statusFileParent = statusFile.getParentFile(); if (statusFileParent != null) { statusFileParent.mkdirs(); } jsonMapper.writeValue(statusFile, taskStatus); return taskStatus; } catch (Exception e) { throw Throwables.propagate(e); } } } ); }