From 98efb7bb82b1a2a3c5ada01c7b2265ecf408db82 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lesot Date: Wed, 1 Apr 2015 14:40:08 +0200 Subject: Rework finally in Jack simple server, add a retry counter in script Change-Id: Id9a8a08e27d923a347cc18fb2b861c1963f3f858 --- .../com/android/jack/server/JackSimpleServer.java | 130 ++++++++++----------- 1 file changed, 65 insertions(+), 65 deletions(-) (limited to 'jack-server') diff --git a/jack-server/src/com/android/jack/server/JackSimpleServer.java b/jack-server/src/com/android/jack/server/JackSimpleServer.java index baca0d1c..fa2184ce 100644 --- a/jack-server/src/com/android/jack/server/JackSimpleServer.java +++ b/jack-server/src/com/android/jack/server/JackSimpleServer.java @@ -87,7 +87,6 @@ import javax.annotation.Nonnull; * Server controlling the number of Jack compilations that are executed simultaneously. */ public class JackSimpleServer { - static { // It seems that loggers must be created from parents to children to have the loggers // correctly initialized. Thus load the initial configuration that define specific level @@ -97,7 +96,6 @@ public class JackSimpleServer { LoggerFactory.loadLoggerConfiguration(JackSimpleServer.class, "/initial.logging.properties"); } - @Nonnull private static Logger logger = Logger.getLogger(JackSimpleServer.class.getName()); @@ -305,8 +303,8 @@ public class JackSimpleServer { if (currentLocal == 0) { cancelTimer(); } + currentLocal++; - logger.log(Level.INFO, "Number of concurrent compilations: " + currentLocal); if (currentLocal > maxLocal) { maxLocal = currentLocal; } @@ -330,79 +328,81 @@ public class JackSimpleServer { return; } - logger.log(Level.INFO, "Open standard output '" + command[CMD_IDX_OUT] + "'"); - try { - out = new FifoStreamFile(command[CMD_IDX_OUT]).getPrintStream(10000); - } catch (IOException | TimeoutException e) { - logger.log(Level.SEVERE, e.getMessage()); - response.setStatus(Status.BAD_REQUEST); - return; - } - - logger.log(Level.INFO, "Open standard error '" + command[CMD_IDX_ERR] + "'"); - try { - err = new FifoStreamFile(command[CMD_IDX_ERR]).getPrintStream(10000); - } catch (IOException | TimeoutException e) { - logger.log(Level.SEVERE, e.getMessage()); - response.setStatus(Status.BAD_REQUEST); - return; - } - - logger.log(Level.INFO, "Parse command line"); - TokenIterator args = new TokenIterator(new NoLocation(), "@" + command[CMD_IDX_CLI]); - args.allowFileReferenceInFile(); - if (!args.hasNext()) { - logger.log(Level.SEVERE, "Cli format error"); - response.setStatus(Status.BAD_REQUEST); - return; - } - - String workingDir; try { - workingDir = args.next(); - } catch (IOException e) { - logger.log(Level.SEVERE, "Cli format error"); - response.setStatus(Status.BAD_REQUEST); - return; - } + logger.log(Level.INFO, "Open standard output '" + command[CMD_IDX_OUT] + "'"); + try { + out = new FifoStreamFile(command[CMD_IDX_OUT]).getPrintStream(10000); + } catch (IOException | TimeoutException e) { + logger.log(Level.SEVERE, e.getMessage()); + response.setStatus(Status.BAD_REQUEST); + return; + } - int code = -1; - long start = System.currentTimeMillis(); - try { - logger.log(Level.INFO, "Run Compilation #" + id); - start = System.currentTimeMillis(); - code = service.run(out, err, new File(workingDir), args); - } finally { - long stop = System.currentTimeMillis(); - logger.log(Level.INFO, "Compilation #" + id + " return exit code " + code); - logger.log(Level.INFO, "Compilation #" + id + " run in " + (stop - start) + " ms"); + logger.log(Level.INFO, "Open standard error '" + command[CMD_IDX_ERR] + "'"); + try { + err = new FifoStreamFile(command[CMD_IDX_ERR]).getPrintStream(10000); + } catch (IOException | TimeoutException e) { + logger.log(Level.SEVERE, e.getMessage()); + response.setStatus(Status.BAD_REQUEST); + return; + } - response.setStatus(Status.OK); + logger.log(Level.INFO, "Parse command line"); + TokenIterator args = new TokenIterator(new NoLocation(), "@" + command[CMD_IDX_CLI]); + args.allowFileReferenceInFile(); + if (!args.hasNext()) { + logger.log(Level.SEVERE, "Cli format error"); + response.setStatus(Status.BAD_REQUEST); + return; + } - PrintStream printer; + String workingDir; try { - printer = response.getPrintStream(); - printer.println(code); - printer.close(); + workingDir = args.next(); } catch (IOException e) { - logger.log(Level.SEVERE, "Problem to send exit code for compilation #" + id); + logger.log(Level.SEVERE, "Cli format error"); response.setStatus(Status.BAD_REQUEST); return; } - } - } finally { - if (out != null) { - out.close(); - } else { - unblock(command[CMD_IDX_OUT]); - } - if (err != null) { - err.close(); - } else { - unblock(command[CMD_IDX_ERR]); - } + int code = -1; + long start = System.currentTimeMillis(); + try { + logger.log(Level.INFO, "Run Compilation #" + id); + start = System.currentTimeMillis(); + code = service.run(out, err, new File(workingDir), args); + } finally { + long stop = System.currentTimeMillis(); + logger.log(Level.INFO, "Compilation #" + id + " return exit code " + code); + logger.log(Level.INFO, "Compilation #" + id + " run in " + (stop - start) + " ms"); + + response.setStatus(Status.OK); + + PrintStream printer; + try { + printer = response.getPrintStream(); + printer.println(code); + printer.close(); + } catch (IOException e) { + logger.log(Level.SEVERE, "Problem to send exit code for compilation #" + id); + response.setStatus(Status.BAD_REQUEST); + return; + } + } + } finally { + if (out != null) { + out.close(); + } else { + unblock(command[CMD_IDX_OUT]); + } + if (err != null) { + err.close(); + } else { + unblock(command[CMD_IDX_ERR]); + } + } + } finally { lock.lock(); try { currentLocal--; -- cgit v1.2.3