<commit_before>package org.ow2.proactive_grid_cloud_portal.cli.cmd.sched;

import org.ow2.proactive_grid_cloud_portal.cli.ApplicationContext;
import org.ow2.proactive_grid_cloud_portal.cli.CLIException;
import org.ow2.proactive_grid_cloud_portal.cli.cmd.AbstractJobCommand;
import org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface;

import java.util.concurrent.TimeUnit;


public class LiveLogCommand extends AbstractJobCommand {
    public LiveLogCommand(String jobId) {
        super(jobId);
    }

    @Override
    public void execute(ApplicationContext currentContext) throws CLIException {
        SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
        writeLine(currentContext, "Displaying live log for job %s. Press 'q' to stop.", jobId);
        try {
            while (true) {
                String log = scheduler.getLiveLogJob(currentContext.getSessionId(), jobId);
                writeLine(currentContext, "%s", log.trim());
                while (currentContext.getDevice().canRead()) {
                    int c = currentContext.getDevice().read();
                    if (c != -1 && c == 'q') {
                        return;
                    }
                }
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    Thread.currentThread().interrupt();
                }
            }
        } catch (Exception e) {
            handleError("An error occurred while displaying live log", e, currentContext);
        }
    }
}<commit_msg>SCHEDULING-2091 CLI: cannot exit livelog command.<commit_after>package org.ow2.proactive_grid_cloud_portal.cli.cmd.sched;

import org.ow2.proactive_grid_cloud_portal.cli.ApplicationContext;
import org.ow2.proactive_grid_cloud_portal.cli.CLIException;
import org.ow2.proactive_grid_cloud_portal.cli.cmd.AbstractJobCommand;
import org.ow2.proactive_grid_cloud_portal.common.SchedulerRestInterface;

import com.google.common.base.Strings;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;


public class LiveLogCommand extends AbstractJobCommand {
    public LiveLogCommand(String jobId) {
        super(jobId);
    }

    @Override
    public void execute(ApplicationContext currentContext) throws CLIException {
        writeLine(currentContext, "Displaying live log for job %s. Press 'q' to stop.", jobId);
        try {
            LogReader reader = new LogReader(currentContext);
            ExecutorService executor = Executors.newSingleThreadExecutor();
            executor.submit(reader);
            String line  = readLine(currentContext, "> ");
            while (Strings.isNullOrEmpty(line) || ! line.trim().equals("q")) {
                line = readLine(currentContext, "> ");
            }
            reader.terminate();
            executor.shutdownNow();
        } catch (Exception e) {
            handleError("An error occurred while displaying live log", e, currentContext);
        }
    }

    private class LogReader implements Runnable {
        private final ApplicationContext currentContext;
        private volatile boolean terminate = false;

        public LogReader(ApplicationContext currentContext) {
            this.currentContext = currentContext;
        }

        public void terminate() {
            this.terminate =true;
        }

        @Override
        public void run() {
            SchedulerRestInterface scheduler = currentContext.getRestClient().getScheduler();
            writeLine(currentContext, "Displaying live log for job %s. Press 'q' to stop.", jobId);
            try {
                while (!terminate) {
                    String log = scheduler.getLiveLogJob(currentContext.getSessionId(), jobId);
                    writeLine(currentContext, "%s", log.trim());
                    try {
                        TimeUnit.SECONDS.sleep(1);
                    } catch (InterruptedException ignorable) {
                    }
                }
            } catch (Exception e) {
                handleError("An error occurred while displaying live log", e, currentContext);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.0924310304173544, 'fraction_numerical': 0.00400848856401792, 'mean_word_length': 2.321848081440877, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1924293', 'n_tokens_mistral': 1117, 'n_tokens_neox': 1082, 'n_words': 235}