You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ni...@apache.org on 2010/10/08 19:41:58 UTC

svn commit: r1005921 - in /commons/proper/io/trunk/src: main/java/org/apache/commons/io/input/Tailer.java test/java/org/apache/commons/io/input/TailerTest.java

Author: niallp
Date: Fri Oct  8 17:41:58 2010
New Revision: 1005921

URL: http://svn.apache.org/viewvc?rev=1005921&view=rev
Log:
IO-177 Should be handling InterruptedException when sleeping - not calling the exception handler

Modified:
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java

Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java?rev=1005921&r1=1005920&r2=1005921&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java Fri Oct  8 17:41:58 2010
@@ -192,7 +192,10 @@ public class Tailer implements Runnable 
                 }
 
                 if (reader == null) {
-                    Thread.sleep(delay);
+                    try {
+                        Thread.sleep(delay);
+                    } catch (InterruptedException e) {
+                    }
                 } else {
                     // The current position in the file
                     position = end ? file.length() : 0;
@@ -250,8 +253,10 @@ public class Tailer implements Runnable 
                         position = readLines(reader);
                     }
                 }
-
-                Thread.sleep(delay);
+                try {
+                    Thread.sleep(delay);
+                } catch (InterruptedException e) {
+                }
             }
 
         } catch (Exception e) {

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java?rev=1005921&r1=1005920&r2=1005921&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/input/TailerTest.java Fri Oct  8 17:41:58 2010
@@ -45,7 +45,9 @@ public class TailerTest extends FileBase
         File file = new File(getTestDirectory(), "tailer1-test.txt");
         createFile(file, 0);
         TestTailerListener listener = new TestTailerListener();
-        Tailer tailer = start(file, listener, delay, false);
+        final Tailer tailer = new Tailer(file, listener, delay, false);
+        final Thread thread = new Thread(tailer);
+        thread.start();
 
         // Write some lines to the file
         write(file, "Line one", "Line two");
@@ -86,6 +88,7 @@ public class TailerTest extends FileBase
 
         // Stop
         tailer.stop();
+        thread.interrupt();
         Thread.sleep(delay * 2);
         write(file, "Line five");
         assertEquals("4 line count", 0, listener.getLines().size());
@@ -95,14 +98,6 @@ public class TailerTest extends FileBase
         assertEquals("fileRotated should be be called", 1 , listener.rotated);
     }
 
-    /** Start a tailer */
-    private Tailer start(File file, TailerListener listener, long delay, boolean end) {
-        Tailer tailer = new Tailer(file, listener, delay, end);
-        Thread thread = new Thread(tailer);
-        thread.start();
-        return tailer;
-    }
-
     /** Append some lines to a file */
     private void write(File file, String... lines) throws Exception {
         FileWriter writer = null;