diff options
author | Simon Rettberg | 2015-02-24 16:28:58 +0100 |
---|---|---|
committer | Simon Rettberg | 2015-02-24 16:28:58 +0100 |
commit | 9820962a9a0fb0fa9a49ddf49ee551ac41a708ae (patch) | |
tree | 551b7d4ddc7b521d721ac54d532c5f123b7d9c2e /api/src | |
parent | Make taskmanager an instance, add callback for finished jobs, improve parent ... (diff) | |
download | taskman-lite-9820962a9a0fb0fa9a49ddf49ee551ac41a708ae.tar.gz taskman-lite-9820962a9a0fb0fa9a49ddf49ee551ac41a708ae.tar.xz taskman-lite-9820962a9a0fb0fa9a49ddf49ee551ac41a708ae.zip |
Switch to semaphore for signalling the mainloop to check for work
Diffstat (limited to 'api/src')
-rw-r--r-- | api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java | 1 | ||||
-rw-r--r-- | api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java | 27 |
2 files changed, 18 insertions, 10 deletions
diff --git a/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java b/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java index a1c81e8..271a8bd 100644 --- a/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java +++ b/api/src/main/java/org/openslx/taskmanager/api/AbstractTask.java @@ -299,6 +299,7 @@ public abstract class AbstractTask implements Runnable } else { this.status.statusCode = StatusCode.TASK_ERROR; } + LOG.debug( "Finished task " + this.getClass().getSimpleName() + ": " + this.status.statusCode.toString() + " (" + this.id + ")" ); if ( this.finishCallback != null ) this.finishCallback.taskFinished(); } diff --git a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java index ea71ea5..ed47336 100644 --- a/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java +++ b/api/src/main/java/org/openslx/taskmanager/api/SystemCommandTask.java @@ -14,9 +14,8 @@ public abstract class SystemCommandTask extends AbstractTask private static final Logger log = Logger.getLogger( SystemCommandTask.class ); private String[] command = null; - - private Process process = null; + private Process process = null; @Override protected final boolean execute() @@ -50,7 +49,7 @@ public abstract class SystemCommandTask extends AbstractTask processStdOut( line ); } } - } catch ( IOException e ) { + } catch ( Exception e ) { } } } ); @@ -67,7 +66,7 @@ public abstract class SystemCommandTask extends AbstractTask processStdErr( line ); } } - } catch ( IOException e ) { + } catch ( Exception e ) { } } } ); @@ -76,9 +75,17 @@ public abstract class SystemCommandTask extends AbstractTask stderr.start(); // Wait for everything - stdout.join(); - stderr.join(); process.waitFor(); + try { + process.getErrorStream().close(); + } catch ( Throwable t ) { + } + try { + process.getOutputStream().close(); + } catch ( Throwable t ) { + } + stdout.join( 2000 ); + stderr.join( 2000 ); return processEnded( process.exitValue() ); @@ -98,14 +105,14 @@ public abstract class SystemCommandTask extends AbstractTask process.destroy(); } } - + /** * Write data to the process's stdin. * * @param data stuff to write * @return success or failure mapped to a boolean in a really complicated way */ - protected final boolean toStdIn(byte[] data) + protected final boolean toStdIn( byte[] data ) { try { process.getOutputStream().write( data ); @@ -122,7 +129,7 @@ public abstract class SystemCommandTask extends AbstractTask * @param text stuff to write * @return success or failure mapped to a boolean in a really complicated way */ - protected final boolean toStdIn(String text) + protected final boolean toStdIn( String text ) { return toStdIn( text.getBytes( StandardCharsets.UTF_8 ) ); } @@ -147,7 +154,7 @@ public abstract class SystemCommandTask extends AbstractTask * Called when the process has finished running * * @param exitCode the process' exit code - * @return + * @return */ protected abstract boolean processEnded( int exitCode ); |