Class TimeoutProcessCloser

  • All Implemented Interfaces:
    ProcessCloser

    public class TimeoutProcessCloser
    extends StandardProcessCloser
    Same as StandardProcessCloser but only waits fixed period for the closing. On timeout a warning is logged but no error is thrown.

    This is used on Windows where sometimes sub process' streams do not close properly.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static org.slf4j.Logger log  
      private long timeout  
      private java.util.concurrent.TimeUnit unit  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close​(java.lang.Process process)
      Closes standard streams of a given sub process.
      protected void doClose​(java.lang.Process process)  
      private static java.lang.String getUnitsAsString​(long d, java.util.concurrent.TimeUnit unit)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • log

        private static final org.slf4j.Logger log
      • timeout

        private final long timeout
      • unit

        private final java.util.concurrent.TimeUnit unit
    • Constructor Detail

      • TimeoutProcessCloser

        public TimeoutProcessCloser​(ExecuteStreamHandler streams,
                                    long timeout,
                                    java.util.concurrent.TimeUnit unit)
        Creates new instance of TimeoutProcessCloser.
        Parameters:
        streams - helper for pumping the streams.
        timeout - how long should we wait for the closing.
        unit - unit of the timeout value.
    • Method Detail

      • close

        public void close​(java.lang.Process process)
                   throws java.io.IOException,
                          java.lang.InterruptedException
        Description copied from interface: ProcessCloser
        Closes standard streams of a given sub process.
        Specified by:
        close in interface ProcessCloser
        Overrides:
        close in class StandardProcessCloser
        Parameters:
        process - sub process (not null).
        Throws:
        java.io.IOException - if I/O errors occur while closing the underlying stream
        java.lang.InterruptedException - if underlying throws a InterruptedException
      • doClose

        protected void doClose​(java.lang.Process process)
                        throws java.io.IOException,
                               java.lang.InterruptedException
        Throws:
        java.io.IOException
        java.lang.InterruptedException
      • getUnitsAsString

        private static java.lang.String getUnitsAsString​(long d,
                                                         java.util.concurrent.TimeUnit unit)