Author: ggregory
Date: Fri Sep 28 12:10:39 2012
New Revision: 1391419

URL: http://svn.apache.org/viewvc?rev=1391419&view=rev
Log:
[IO-345] Supply a hook method allowing Tailer actively determining stop 
condition.

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    
commons/proper/io/trunk/src/main/java/org/apache/commons/io/input/Tailer.java

Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: 
http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1391419&r1=1391418&r2=1391419&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Fri Sep 28 12:10:39 2012
@@ -47,6 +47,9 @@ The <action> type attribute can be add,u
   <body>
     <!-- The release date is the date RC is cut -->
     <release version="2.5" date="201?-??-??" description="New features and bug 
fixes.">
+      <action issue="IO-345" dev="ggregory" type="add" due-to="mkresse">
+        Supply a hook method allowing Tailer actively determining stop 
condition.
+      </action>            
     </release>
     <!-- The release date is the date RC is cut -->
     <release version="2.4" date="2012-06-12" description="New features and bug 
fixes.">

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=1391419&r1=1391418&r2=1391419&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 Sep 28 12:10:39 2012
@@ -322,6 +322,16 @@ public class Tailer implements Runnable 
     }
 
     /**
+     * Gets whether to keep on running.
+     * 
+     * @return whether to keep on running.
+     * @since 2.5
+     */
+    protected boolean getRun() {
+        return run;
+    }
+
+    /**
      * Return the delay in milliseconds.
      *
      * @return the delay in milliseconds.
@@ -339,7 +349,7 @@ public class Tailer implements Runnable 
             long last = 0; // The last time the file was checked for changes
             long position = 0; // position within the file
             // Open the file
-            while (run && reader == null) {
+            while (getRun() && reader == null) {
                 try {
                     reader = new RandomAccessFile(file, RAF_MODE);
                 } catch (FileNotFoundException e) {
@@ -359,7 +369,7 @@ public class Tailer implements Runnable 
                 }
             }
 
-            while (run) {
+            while (getRun()) {
 
                 boolean newer = FileUtils.isFileNewer(file, last); // IO-279, 
must be done first
 
@@ -416,7 +426,7 @@ public class Tailer implements Runnable 
                     Thread.sleep(delayMillis);
                 } catch (InterruptedException e) {
                 }
-                if (run && reOpen) {
+                if (getRun() && reOpen) {
                     reader = new RandomAccessFile(file, RAF_MODE);
                     reader.seek(position);
                 }
@@ -453,7 +463,7 @@ public class Tailer implements Runnable 
 
         int num;
         boolean seenCR = false;
-        while (run && ((num = reader.read(inbuf)) != -1)) {
+        while (getRun() && ((num = reader.read(inbuf)) != -1)) {
             for (int i = 0; i < num; i++) {
                 byte ch = inbuf[i];
                 switch (ch) {


Reply via email to