Commits

Sebastian Bub committed 0dfb135

changed returnCode to be a String; warnings removed

  • Participants
  • Parent commits 488fa12

Comments (0)

Files changed (2)

File src/main/java/de/derbub/rpigpio/cmd/ExternalProcess.java

     /**
      * this will start the command and pipe the parameter to it with STDIN
      *
-     * @param parameter
-     * @return
+     * @param parameter the parameter that is given to external process
+     * @return the return code as string from the external process or -1 if a timeout happened
      */
-    public int start(String parameter) {
-        int exitVal = -1;
+    public String start(String parameter) {
+        String exitVal = "-1";
 
         try {
             log.debug("starting external process: " + externalCommand + " with timeout " + commandTimeout);
             TimeoutRunner runner = new TimeoutRunner(proc, commandName, commandTimeout);
 
             try {
-                exitVal = proc.waitFor();
+                exitVal = Integer.toString(proc.waitFor());
                 log.info("external process exited with code: " + exitVal + " with parameter " + parameter);
             } catch (InterruptedException e) {
-                StringBuilder b = new StringBuilder();
-                log.error("external process" + externalCommand + "was interrupted and probably has not finished on parameter " + parameter);
+                log.warn("external process" + externalCommand + "was interrupted and probably has not finished on parameter " + parameter);
             }
             if (runner.isThreadAlive()) {
                 runner.interruptThread();

File src/main/java/de/derbub/rpigpio/cmd/ExternalProcessesManager.java

     /**
      * constuctor reads in config file and initialized ExternalProcess Map
      *
-     * @param cmdConfigFile
+     * @param cmdConfigFile a File which referenceres the properties
      */
     public ExternalProcessesManager(File cmdConfigFile) {
         Properties configProperties = new Properties();
         }
 
         String noOfExtCmdString = configProperties.getProperty(NO_OF_EXTCMD);
-        int noOfExtCmd = 0;
+        int noOfExtCmd;
         try {
             noOfExtCmd = Integer.parseInt(noOfExtCmdString);
             log.debug(NO_OF_EXTCMD + " is set to " + noOfExtCmd);
             }
 
             try {
-                long timeout = 0;
+                long timeout;
                 try {
                     timeout = Long.parseLong(configProperties.getProperty(EXTCMD_TIMEOUT_KEY_PREFIX + i));
                 } catch (NumberFormatException nfe){
                     log.warn("Multiple commands named: " + previousP.commandName + ". Ignoring old " + previousP.externalCommand);
                 }
             } catch (IOException e) {
-                log.warn(EXTCMD_NAME_KEY_PREFIX + i +" throws exception (ignoring command): " + e.getMessage());
+                log.warn(EXTCMD_NAME_KEY_PREFIX + i +" throws exception during init (ignoring command): " + e.getMessage());
             }
         }
     }
     /**
      * calls the command with the given parameter
      *
-     * @param name
-     * @param parameter
-     * @return
+     * @param name the name prefixed with CMD
+     * @param parameter the parameter given to the external process
+     * @return the exit code of the external process
      */
-    public int process(String name, String parameter) {
+    public String process(String name, String parameter) {
         ExternalProcess ep = externalProcesses.get(name);
         if (null == ep) {
-            log.warn("Did not find process with name " + name + " - will return -1");
-            return -1;
+            log.warn("Did not find process with name " + name + " (not found) - will return -1");
+            return "-1";
         }
         return ep.start(parameter);
     }