Refactoring and code style improving
authorSasha <Main-laptop2>
Mon, 29 Jul 2013 11:55:21 +0000 (12:55 +0100)
committerSasha <Main-laptop2>
Mon, 29 Jul 2013 11:55:21 +0000 (12:55 +0100)
engine/compbio/engine/local/ExecutableWrapper.java
webservices/compbio/stat/collector/JobStat.java
webservices/compbio/stat/collector/StatDB.java
webservices/compbio/ws/server/SetExecutableFlag.java

index 597af4e..9e652f9 100644 (file)
@@ -75,17 +75,14 @@ public final class ExecutableWrapper implements
 \r
        pbuilder = new ProcessBuilder(params);\r
        if (executable.getEnvironment() != null) {\r
-           log.debug("Setting command environment variables: "\r
-                   + pbuilder.environment());\r
-           Util.mergeEnvVariables(pbuilder.environment(), executable\r
-                   .getEnvironment());\r
+           log.debug("Setting command environment variables: " + pbuilder.environment());\r
+           Util.mergeEnvVariables(pbuilder.environment(), executable.getEnvironment());\r
            log.debug("Process environment:" + pbuilder.environment());\r
        }\r
        log.debug("Setting command: " + pbuilder.command());\r
        PathValidator.validateDirectory(workDirectory);\r
        pbuilder.directory(new File(workDirectory));\r
-       log.debug("Current working directory is "\r
-               + SysPrefs.getCurrentDirectory());\r
+       log.debug("Current working directory is " + SysPrefs.getCurrentDirectory());\r
        log.debug("Setting working directory: " + workDirectory);\r
        // Initialize private executor to dump processes output if any to the\r
        // file system\r
@@ -98,8 +95,7 @@ public final class ExecutableWrapper implements
                // get access to the thread efficiently deadlocking the\r
                // proccess!\r
                this.es = Executors.newCachedThreadPool();\r
-               log\r
-                       .debug("Initializing executor for local processes output dump");\r
+               log.debug("Initializing executor for local processes output dump");\r
                // Make sure that the executors are going to be properly closed\r
                Runtime.getRuntime().addShutdownHook(new Thread() {\r
                    @Override\r
@@ -119,7 +115,7 @@ public final class ExecutableWrapper implements
      */\r
     public static final void shutdownService() {\r
        if (es != null) {\r
-           es.shutdownNow();\r
+               es.shutdownNow();\r
        }\r
     }\r
 \r
index 72c7ae1..2ad48ff 100644 (file)
-/* Copyright (c) 2011 Peter Troshin\r
- *  \r
- *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     \r
- * \r
- *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
- *  Apache License version 2 as published by the Apache Software Foundation\r
- * \r
- *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
- *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
- *  License for more details.\r
- * \r
- *  A copy of the license is in apache_license.txt. It is also available here:\r
- * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
- * \r
- * Any republication or derived work distributed in source code form\r
- * must include this copyright and license notice.\r
- */\r
-package compbio.stat.collector;\r
-\r
-import java.sql.Timestamp;\r
-import java.text.DateFormat;\r
-import java.text.SimpleDateFormat;\r
-import java.util.Comparator;\r
-import java.util.Date;\r
-import java.util.Locale;\r
-\r
-import compbio.engine.client.ConfExecutable;\r
-import compbio.util.Util;\r
-import compbio.ws.client.Services;\r
-\r
-public class JobStat {\r
-\r
-       static final Comparator<JobStat> RUNTIME = new Comparator<JobStat>() {\r
-               @Override\r
-               public int compare(JobStat o1, JobStat o2) {\r
-                       return new Integer(o2.getRuntime()).compareTo(o1.getRuntime());\r
-               }\r
-       };\r
-\r
-       static final Comparator<JobStat> STARTTIME = new Comparator<JobStat>() {\r
-               @Override\r
-               public int compare(JobStat o1, JobStat o2) {\r
-                       return new Long(o1.start).compareTo(o2.start);\r
-               }\r
-       };\r
-\r
-       static final Comparator<JobStat> RESULTSIZE = new Comparator<JobStat>() {\r
-               @Override\r
-               public int compare(JobStat o1, JobStat o2) {\r
-                       return new Long(o2.resultSize).compareTo(o1.resultSize);\r
-               }\r
-       };\r
-\r
-       private static DateFormat DATE_TIME = SimpleDateFormat.getDateTimeInstance(\r
-                       DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.UK);\r
-\r
-       Services webService;\r
-       String clusterJobId;\r
-       String jobname;\r
-       long start;\r
-       long finish;\r
-       long inputSize;\r
-       long resultSize;\r
-       boolean isCollected;\r
-       boolean isCancelled;\r
-\r
-       private JobStat(Services webService, String clusterJobId, String jobname,\r
-                       long start, long finish, long inputSize, long resultSize,\r
-                       boolean isCancelled, boolean isCollected) {\r
-               super();\r
-               this.webService = webService;\r
-               this.clusterJobId = clusterJobId;\r
-               this.jobname = jobname;\r
-               this.start = start;\r
-               this.finish = finish;\r
-               this.inputSize = inputSize;\r
-               this.resultSize = resultSize;\r
-               this.isCancelled = isCancelled;\r
-               this.isCollected = isCollected;\r
-               validate();\r
-       }\r
-\r
-       static JobStat newInstance(Services webService, String clusterJobId,\r
-                       String jobname, long start, long finish, long inputSize,\r
-                       long resultSize, boolean isCancelled, boolean isCollected) {\r
-               return new JobStat(webService, clusterJobId, jobname, start, finish,\r
-                               inputSize, resultSize, isCancelled, isCollected);\r
-       }\r
-\r
-       static JobStat newInstance(Services webService, String clusterJobId,\r
-                       String jobname, Timestamp start, Timestamp finish, long inputSize,\r
-                       long resultSize, boolean isCancelled, boolean isCollected) {\r
-               long startm = ExecutionStatCollector.UNDEFINED;\r
-               long stopm = ExecutionStatCollector.UNDEFINED;\r
-               if (start != null) {\r
-                       startm = start.getTime();\r
-               }\r
-               if (finish != null) {\r
-                       stopm = finish.getTime();\r
-               }\r
-               return new JobStat(webService, clusterJobId, jobname, startm, stopm,\r
-                               inputSize, resultSize, isCancelled, isCollected);\r
-       }\r
-\r
-       void validate() {\r
-               if (webService == null) {\r
-                       throw new AssertionError("webService must be defined!:\n " + this);\r
-               }\r
-               if (Util.isEmpty(jobname)) {\r
-                       throw new AssertionError("jobname must be defined!:\n" + this);\r
-               }\r
-       }\r
-\r
-       private JobStat(String jobId) {\r
-               assert !Util.isEmpty(jobname);\r
-               this.jobname = jobId;\r
-       }\r
-\r
-       static JobStat newIncompleteStat(String jobname) {\r
-               return new JobStat(jobname);\r
-       }\r
-\r
-       public boolean isClusterJob() {\r
-               return jobname.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX);\r
-       }\r
-\r
-       @Override\r
-       public int hashCode() {\r
-               final int prime = 31;\r
-               int result = 1;\r
-               result = prime * result + ((jobname == null) ? 0 : jobname.hashCode());\r
-               return result;\r
-       }\r
-\r
-       @Override\r
-       public boolean equals(Object obj) {\r
-               if (this == obj)\r
-                       return true;\r
-               if (obj == null)\r
-                       return false;\r
-               if (getClass() != obj.getClass())\r
-                       return false;\r
-               JobStat other = (JobStat) obj;\r
-               if (jobname == null) {\r
-                       if (other.jobname != null)\r
-                               return false;\r
-               } else if (!jobname.equals(other.jobname))\r
-                       return false;\r
-               return true;\r
-       }\r
-\r
-       public int getRuntime() {\r
-               if (start != ExecutionStatCollector.UNDEFINED\r
-                               && finish != ExecutionStatCollector.UNDEFINED) {\r
-                       return (int) (finish - start) / 1000;\r
-               }\r
-               return ExecutionStatCollector.UNDEFINED;\r
-       }\r
-\r
-       @Override\r
-       public String toString() {\r
-               return getJobReport();\r
-       }\r
-\r
-       String getJobReport() {\r
-               String report = "WS: " + webService + "\n";\r
-               report += "JOB: " + jobname + "\n";\r
-               if (start != ExecutionStatCollector.UNDEFINED) {\r
-                       report += "Started " + new Date(start) + "\n";\r
-               }\r
-               if (finish != ExecutionStatCollector.UNDEFINED) {\r
-                       report += "Finished " + new Date(finish) + "\n";\r
-               }\r
-               if (start != ExecutionStatCollector.UNDEFINED\r
-                               && finish != ExecutionStatCollector.UNDEFINED) {\r
-                       report += "Runtime " + getRuntime() + "\n";\r
-               }\r
-               report += "Input size " + inputSize + "\n";\r
-               report += "Result size " + resultSize + "\n";\r
-               report += "ClusterJobID " + clusterJobId + "\n";\r
-               report += "Collected? " + isCollected + "\n";\r
-               report += "Cancelled? " + isCancelled + "\n";\r
-               return report;\r
-       }\r
-\r
-       /**\r
-        * Header Job Started Finished Runtime Input Result\r
-        */\r
-       String getJobReportTabulated() {\r
-               String report = webService + "\t";\r
-               report += jobname + "\t";\r
-               if (start != ExecutionStatCollector.UNDEFINED) {\r
-                       report += ExecutionStatCollector.DF.format(new Date(start)) + "\t";\r
-               } else {\r
-                       report += ExecutionStatCollector.UNDEFINED + "\t";\r
-               }\r
-               if (finish != ExecutionStatCollector.UNDEFINED) {\r
-                       report += ExecutionStatCollector.DF.format(new Date(finish)) + "\t";\r
-               } else {\r
-                       report += ExecutionStatCollector.UNDEFINED + "\t";\r
-               }\r
-               if (start != ExecutionStatCollector.UNDEFINED\r
-                               && finish != ExecutionStatCollector.UNDEFINED) {\r
-                       report += getRuntime() + "\t";\r
-               } else {\r
-                       report += ExecutionStatCollector.UNDEFINED + "\t";\r
-               }\r
-               report += inputSize + "\t";\r
-               report += resultSize + "\t";\r
-               report += clusterJobId + "\t";\r
-               report += isCollected + "\t";\r
-               report += isCancelled + "\t";\r
-               return report;\r
-       }\r
-\r
-       public Services getWebService() {\r
-               return webService;\r
-       }\r
-\r
-       public String getClusterJobId() {\r
-               return clusterJobId;\r
-       }\r
-\r
-       public String getJobname() {\r
-               return jobname;\r
-       }\r
-\r
-       public String getEscJobname() {\r
-               String[] parts = jobname.split("#");\r
-               return parts[0] + "%23" + parts[1];\r
-       }\r
-\r
-       public String getStart() {\r
-               if (start != ExecutionStatCollector.UNDEFINED) {\r
-                       return DATE_TIME.format(new Date(start));\r
-               }\r
-               return "?";\r
-       }\r
-\r
-       public String getFinish() {\r
-               if (finish != ExecutionStatCollector.UNDEFINED) {\r
-                       return DATE_TIME.format(new Date(finish));\r
-               }\r
-               return "?";\r
-       }\r
-\r
-       public long getInputSize() {\r
-               if (inputSize != ExecutionStatCollector.UNDEFINED) {\r
-                       return inputSize;\r
-               }\r
-               return 0;\r
-       }\r
-\r
-       public long getResultSize() {\r
-               if (resultSize > 0) {\r
-                       return resultSize;\r
-               }\r
-               return 0;\r
-       }\r
-\r
-       public boolean hasResult() {\r
-               return resultSize > 0;\r
-       }\r
-\r
-       public boolean hasStarted() {\r
-               return start != ExecutionStatCollector.UNDEFINED;\r
-       }\r
-\r
-       public boolean getIsCollected() {\r
-               return isCollected;\r
-       }\r
-\r
-       public boolean getIsCancelled() {\r
-               return isCancelled;\r
-       }\r
-\r
-       public boolean getIsFinished() {\r
-               return finish != ExecutionStatCollector.UNDEFINED;\r
-       }\r
-\r
-}
\ No newline at end of file
+/* Copyright (c) 2011 Peter Troshin
+ *  
+ *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 2.0     
+ * 
+ *  This library is free software; you can redistribute it and/or modify it under the terms of the
+ *  Apache License version 2 as published by the Apache Software Foundation
+ * 
+ *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
+ *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache 
+ *  License for more details.
+ * 
+ *  A copy of the license is in apache_license.txt. It is also available here:
+ * @see: http://www.apache.org/licenses/LICENSE-2.0.txt
+ * 
+ * Any republication or derived work distributed in source code form
+ * must include this copyright and license notice.
+ */
+package compbio.stat.collector;
+
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Comparator;
+import java.util.Date;
+import java.util.Locale;
+
+import compbio.engine.client.ConfExecutable;
+import compbio.util.Util;
+import compbio.ws.client.Services;
+
+public class JobStat {
+
+       static final Comparator<JobStat> RUNTIME = new Comparator<JobStat>() {
+               @Override
+               public int compare(JobStat o1, JobStat o2) {
+                       return new Integer(o2.getRuntime()).compareTo(o1.getRuntime());
+               }
+       };
+
+       static final Comparator<JobStat> STARTTIME = new Comparator<JobStat>() {
+               @Override
+               public int compare(JobStat o1, JobStat o2) {
+                       return new Long(o1.start).compareTo(o2.start);
+               }
+       };
+
+       static final Comparator<JobStat> RESULTSIZE = new Comparator<JobStat>() {
+               @Override
+               public int compare(JobStat o1, JobStat o2) {
+                       return new Long(o2.resultSize).compareTo(o1.resultSize);
+               }
+       };
+
+       private static DateFormat DATE_TIME = SimpleDateFormat.getDateTimeInstance(
+                       DateFormat.DEFAULT, DateFormat.DEFAULT, Locale.UK);
+
+       Services webService;
+       String clusterJobId;
+       String jobname;
+       long start;
+       long finish;
+       long inputSize;
+       long resultSize;
+       boolean isCollected;
+       boolean isCancelled;
+
+       private JobStat(Services webService, String clusterJobId, String jobname,
+                       long start, long finish, long inputSize, long resultSize,
+                       boolean isCancelled, boolean isCollected) {
+               super();
+               this.webService = webService;
+               this.clusterJobId = clusterJobId;
+               this.jobname = jobname;
+               this.start = start;
+               this.finish = finish;
+               this.inputSize = inputSize;
+               this.resultSize = resultSize;
+               this.isCancelled = isCancelled;
+               this.isCollected = isCollected;
+               validate();
+       }
+
+       public static JobStat newInstance(Services webService, String clusterJobId,
+                       String jobname, long start, long finish, long inputSize,
+                       long resultSize, boolean isCancelled, boolean isCollected) {
+               return new JobStat(webService, clusterJobId, jobname, start, finish,
+                               inputSize, resultSize, isCancelled, isCollected);
+       }
+
+       public static JobStat newInstance(Services webService, String clusterJobId,
+                       String jobname, Timestamp start, Timestamp finish, long inputSize,
+                       long resultSize, boolean isCancelled, boolean isCollected) {
+               long startm = ExecutionStatCollector.UNDEFINED;
+               long stopm = ExecutionStatCollector.UNDEFINED;
+               if (start != null) {
+                       startm = start.getTime();
+               }
+               if (finish != null) {
+                       stopm = finish.getTime();
+               }
+               return new JobStat(webService, clusterJobId, jobname, startm, stopm,
+                               inputSize, resultSize, isCancelled, isCollected);
+       }
+
+       void validate() {
+               if (webService == null) {
+                       throw new AssertionError("webService must be defined!:\n " + this);
+               }
+               if (Util.isEmpty(jobname)) {
+                       throw new AssertionError("jobname must be defined!:\n" + this);
+               }
+       }
+
+       private JobStat(String jobId) {
+               assert !Util.isEmpty(jobname);
+               this.jobname = jobId;
+       }
+
+       public static JobStat newIncompleteStat(String jobname) {
+               return new JobStat(jobname);
+       }
+
+       public boolean isClusterJob() {
+               return jobname.startsWith(ConfExecutable.CLUSTER_TASK_ID_PREFIX);
+       }
+
+       @Override
+       public int hashCode() {
+               final int prime = 31;
+               int result = 1;
+               result = prime * result + ((jobname == null) ? 0 : jobname.hashCode());
+               return result;
+       }
+
+       @Override
+       public boolean equals(Object obj) {
+               if (this == obj)
+                       return true;
+               if (obj == null)
+                       return false;
+               if (getClass() != obj.getClass())
+                       return false;
+               JobStat other = (JobStat) obj;
+               if (jobname == null) {
+                       if (other.jobname != null)
+                               return false;
+               } else if (!jobname.equals(other.jobname))
+                       return false;
+               return true;
+       }
+
+       public int getRuntime() {
+               if (start != ExecutionStatCollector.UNDEFINED && finish != ExecutionStatCollector.UNDEFINED) {
+                       return (int) (finish - start) / 1000;
+               }
+               return ExecutionStatCollector.UNDEFINED;
+       }
+
+       @Override
+       public String toString() {
+               return getJobReport();
+       }
+
+       String getJobReport() {
+               String report = "WS: " + webService + "\n";
+               report += "JOB: " + jobname + "\n";
+               if (start != ExecutionStatCollector.UNDEFINED) {
+                       report += "Started " + new Date(start) + "\n";
+               }
+               if (finish != ExecutionStatCollector.UNDEFINED) {
+                       report += "Finished " + new Date(finish) + "\n";
+               }
+               if (start != ExecutionStatCollector.UNDEFINED && finish != ExecutionStatCollector.UNDEFINED) {
+                       report += "Runtime " + getRuntime() + "\n";
+               }
+               report += "Input size " + inputSize + "\n";
+               report += "Result size " + resultSize + "\n";
+               report += "ClusterJobID " + clusterJobId + "\n";
+               report += "Collected? " + isCollected + "\n";
+               report += "Cancelled? " + isCancelled + "\n";
+               return report;
+       }
+
+       /**
+        * Header Job Started Finished Runtime Input Result
+        */
+       String getJobReportTabulated() {
+               String report = webService + "\t";
+               report += jobname + "\t";
+               if (start != ExecutionStatCollector.UNDEFINED) {
+                       report += ExecutionStatCollector.DF.format(new Date(start)) + "\t";
+               } else {
+                       report += ExecutionStatCollector.UNDEFINED + "\t";
+               }
+               if (finish != ExecutionStatCollector.UNDEFINED) {
+                       report += ExecutionStatCollector.DF.format(new Date(finish)) + "\t";
+               } else {
+                       report += ExecutionStatCollector.UNDEFINED + "\t";
+               }
+               if (start != ExecutionStatCollector.UNDEFINED && finish != ExecutionStatCollector.UNDEFINED) {
+                       report += getRuntime() + "\t";
+               } else {
+                       report += ExecutionStatCollector.UNDEFINED + "\t";
+               }
+               report += inputSize + "\t";
+               report += resultSize + "\t";
+               report += clusterJobId + "\t";
+               report += isCollected + "\t";
+               report += isCancelled + "\t";
+               return report;
+       }
+
+       public Services getWebService() {
+               return webService;
+       }
+
+       public String getClusterJobId() {
+               return clusterJobId;
+       }
+
+       public String getJobname() {
+               return jobname;
+       }
+
+       public String getEscJobname() {
+               String[] parts = jobname.split("#");
+               return parts[0] + "%23" + parts[1];
+       }
+
+       public String getStart() {
+               if (start != ExecutionStatCollector.UNDEFINED) {
+                       return DATE_TIME.format(new Date(start));
+               }
+               return "?";
+       }
+
+       public long getNumericalStart() {
+                       return start;
+       }
+
+       public long getNumericalFinish() {
+               return finish;
+       }
+
+       public String getFinish() {
+               if (finish != ExecutionStatCollector.UNDEFINED) {
+                       return DATE_TIME.format(new Date(finish));
+               }
+               return "?";
+       }
+
+       public long getInputSize() {
+               if (inputSize != ExecutionStatCollector.UNDEFINED) {
+                       return inputSize;
+               }
+               return 0;
+       }
+
+       public long getResultSize() {
+               if (resultSize > 0) {
+                       return resultSize;
+               }
+               return 0;
+       }
+
+       public boolean hasResult() {
+               return resultSize > 0;
+       }
+
+       public boolean hasStarted() {
+               return start != ExecutionStatCollector.UNDEFINED;
+       }
+
+       public boolean getIsCollected() {
+               return isCollected;
+       }
+
+       public boolean getIsCancelled() {
+               return isCancelled;
+       }
+
+       public boolean getIsFinished() {
+               return finish != ExecutionStatCollector.UNDEFINED;
+       }
+}
index b469c44..3af1b14 100644 (file)
@@ -52,22 +52,19 @@ public class StatDB {
 \r
        static Connection conn;\r
 \r
-       private synchronized static Connection getDBConnection()\r
-                       throws SQLException {\r
+       private synchronized static Connection getDBConnection() throws SQLException {\r
 \r
                if (conn != null && !conn.isClosed()) {\r
                        return conn;\r
                } else {\r
                        try {\r
                                String dbpath = PropertyHelperManager.getLocalPath();\r
-                               log.info("Looking for JABAWS access statistics database at: "\r
-                                               + dbpath);\r
+                               log.info("Looking for JABAWS access statistics database at: " + dbpath);\r
                                System.setProperty("derby.system.home", dbpath);\r
                                // Apparently under Tomcat webapp you cannot rely on Java\r
                                // auto discovery and have to register the driver explicitly\r
                                Class.forName(driver);\r
-                               conn = DriverManager.getConnection(protocol + statDBName\r
-                                               + ";create=false");\r
+                               conn = DriverManager.getConnection(protocol + statDBName + ";create=false");\r
 \r
                                conn.setAutoCommit(true);\r
                                /*\r
@@ -81,6 +78,7 @@ public class StatDB {
                }\r
                return conn;\r
        }\r
+\r
        public StatDB() throws SQLException {\r
                this.conn = getDBConnection();\r
        }\r
index dea7cbe..a04e547 100644 (file)
@@ -58,11 +58,10 @@ public class SetExecutableFlag implements ServletContextListener {
                // Run only one once if not on Windows\r
                if (!SysPrefs.isWindows && !isExec) {\r
 \r
-                       // verify script exist\r
+                       // verify script exists\r
                        File scriptFile = new File(workDir, script);\r
                        if (!scriptFile.exists()) {\r
-                               log.debug("Setexecflag.sh script is NOT found in "\r
-                                               + scriptFile.getAbsolutePath());\r
+                               log.debug("Setexecflag.sh script is NOT found in " + scriptFile.getAbsolutePath());\r
                                return;\r
                        } else {\r
                                scriptFile.setExecutable(true);\r