Author: tibordigana Date: Mon Feb 27 22:43:17 2017 New Revision: 1784666 URL: http://svn.apache.org/viewvc?rev=1784666&view=rev Log: monitor object in synchronized() and much more logs
Modified: maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamFeeder.java maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java Modified: maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java URL: http://svn.apache.org/viewvc/maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java?rev=1784666&r1=1784665&r2=1784666&view=diff ============================================================================== --- maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java (original) +++ maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/AbstractStreamHandler.java Mon Feb 27 22:43:17 2017 @@ -25,6 +25,8 @@ package org.apache.maven.shared.utils.cl class AbstractStreamHandler extends Thread { + protected final Object lock = new Object(); + private volatile boolean done; private volatile boolean disabled; @@ -34,16 +36,18 @@ class AbstractStreamHandler return done; } - public synchronized void waitUntilDone() + public void waitUntilDone() throws InterruptedException { - while ( !isDone() ) + synchronized ( lock ) { - wait(); + while ( !isDone() ) + { + lock.wait(); + } } } - boolean isDisabled() { return disabled; @@ -51,6 +55,8 @@ class AbstractStreamHandler public void disable() { + System.out.printf( "%d %s %d disable()\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); disabled = true; } Modified: maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java URL: http://svn.apache.org/viewvc/maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java?rev=1784666&r1=1784665&r2=1784666&view=diff ============================================================================== --- maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java (original) +++ maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/CommandLineUtils.java Mon Feb 27 22:43:17 2017 @@ -226,14 +226,27 @@ public abstract class CommandLineUtils throw new IllegalArgumentException( "cl cannot be null." ); } + System.out.printf( "%d %s before CLI execute %d\n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); final Process p = cl.execute(); + System.out.printf( "%d %s after CLI execute %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); final StreamFeeder inputFeeder = systemIn != null ? new StreamFeeder( systemIn, p.getOutputStream() ) : null; + System.out.printf( "%d %s after getOutputStream() %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + final StreamPumper outputPumper = new StreamPumper( p.getInputStream(), systemOut ); + System.out.printf( "%d %s after getInputStream() %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + final StreamPumper errorPumper = new StreamPumper( p.getErrorStream(), systemErr ); + System.out.printf( "%d %s after getErrorStream() %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + if ( inputFeeder != null ) { inputFeeder.start(); @@ -247,6 +260,9 @@ public abstract class CommandLineUtils ShutdownHookUtils.addShutDownHook( processHook ); + System.out.printf( "%d %s before return %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + return new CommandLineCallable() { public Integer call() @@ -257,7 +273,13 @@ public abstract class CommandLineUtils int returnValue; if ( timeoutInSeconds <= 0 ) { + System.out.printf( "%d %s before waitFor %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + returnValue = p.waitFor(); + + System.out.printf( "%d %s after waitFor %d \n", System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); } else { @@ -279,11 +301,25 @@ public abstract class CommandLineUtils if ( runAfterProcessTermination != null ) { + System.out.printf( "%d %s before runAfterProcessTermination.run() %d \n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); runAfterProcessTermination.run(); + System.out.printf( "%d %s after runAfterProcessTermination.run() %d \n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); } + System.out.printf( "%d %s before waitForAllPumpers() %d \n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + waitForAllPumpers( inputFeeder, outputPumper, errorPumper ); + System.out.printf( "%d %s after waitForAllPumpers() %d \n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); + if ( outputPumper.getException() != null ) { throw new CommandLineException( "Error inside systemOut parser", outputPumper.getException() ); @@ -298,6 +334,10 @@ public abstract class CommandLineUtils } catch ( InterruptedException ex ) { + System.out.printf( "%d %s %d ex=%s\n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode(), ex ); + if ( inputFeeder != null ) { inputFeeder.disable(); @@ -310,6 +350,9 @@ public abstract class CommandLineUtils } finally { + System.out.printf( "%d %s %d finally call()\n", + System.currentTimeMillis(), + CommandLineUtils.class.getSimpleName(), cl.hashCode() ); ShutdownHookUtils.removeShutdownHook( processHook ); processHook.run(); Modified: maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamFeeder.java URL: http://svn.apache.org/viewvc/maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamFeeder.java?rev=1784666&r1=1784665&r2=1784666&view=diff ============================================================================== --- maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamFeeder.java (original) +++ maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamFeeder.java Mon Feb 27 22:43:17 2017 @@ -55,6 +55,7 @@ class StreamFeeder @Override public void run() { + System.out.printf( "%d %s %d run()\n", System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); try { feed(); @@ -67,9 +68,9 @@ class StreamFeeder { close(); - synchronized ( this ) + synchronized ( lock ) { - notifyAll(); + lock.notifyAll(); } } } @@ -120,13 +121,31 @@ class StreamFeeder OutputStream os = output.get(); if ( is != null && os != null ) { + StringBuilder line = new StringBuilder(); for ( int data; !isDone() && ( data = is.read() ) != -1; ) { + if ( data == '\n' ) + { + System.out.printf( "%d %s %d line=%s\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode(), + line ); + line.setLength( 0 ); + } + else + { + line.append( (char) data ); + } + if ( !isDisabled() ) { os.write( data ); os.flush(); } + else + { + System.out.printf( "%d %s %d disabled\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); + } } } } Modified: maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java URL: http://svn.apache.org/viewvc/maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java?rev=1784666&r1=1784665&r2=1784666&view=diff ============================================================================== --- maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java (original) +++ maven/shared/branches/maven-shared-utils-0.9.x/src/main/java/org/apache/maven/shared/utils/cli/StreamPumper.java Mon Feb 27 22:43:17 2017 @@ -73,18 +73,29 @@ public class StreamPumper { try { + System.out.printf( "%d %s before run() %d\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); for ( String line = in.readLine(); line != null; line = in.readLine() ) { + System.out.printf( "%d %s %d line=%s\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode(), line ); try { if ( exception == null ) { + System.out.printf( "%d %s %d before consumeLine( line )\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); consumeLine( line ); + System.out.printf( "%d %s %d after consumeLine( line )\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); } } catch ( Exception t ) { exception = t; + System.out.printf( "%d %s %d exception=%s\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode(), + exception ); } if ( out != null ) @@ -99,16 +110,21 @@ public class StreamPumper catch ( IOException e ) { exception = e; + System.out.printf( "%d %s %d exception=%s\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode(), + exception ); } finally { + System.out.printf( "%d %s after run() %d\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode() ); IOUtil.close( in ); - synchronized ( this ) + synchronized ( lock ) { setDone(); - this.notifyAll(); + lock.notifyAll(); } } } @@ -135,6 +151,9 @@ public class StreamPumper { if ( consumer != null && !isDisabled() ) { + System.out.printf( "%d %s %d sending to %s\n", + System.currentTimeMillis(), getClass().getSimpleName(), hashCode(), + consumer.getClass().getSimpleName() ); consumer.consumeLine( line ); } }