Class Tailer.Builder

All Implemented Interfaces:
IOSupplier<Tailer>
Enclosing class:
Tailer

public static class Tailer.Builder extends AbstractStreamBuilder<Tailer,Tailer.Builder>
Builds a Tailer with default values.

For example:


 Tailer t = Tailer.builder()
   .setPath(path)
   .setCharset(StandardCharsets.UTF_8)
   .setDelayDuration(Duration.ofSeconds(1))
   .setExecutorService(Executors.newSingleThreadExecutor(Builder::newDaemonThread))
   .setReOpen(false)
   .setStartThread(true)
   .setTailable(tailable)
   .setTailerListener(tailerListener)
   .setTailFromEnd(false)
   .get();
 
Since:
2.12.0
  • Field Details

    • DEFAULT_DELAY_DURATION

      private static final Duration DEFAULT_DELAY_DURATION
    • tailable

      private Tailer.Tailable tailable
    • tailerListener

      private TailerListener tailerListener
    • delayDuration

      private Duration delayDuration
    • end

      private boolean end
    • reOpen

      private boolean reOpen
    • startThread

      private boolean startThread
    • executorService

      private ExecutorService executorService
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • newDaemonThread

      private static Thread newDaemonThread(Runnable runnable)
      Creates a new daemon thread.
      Parameters:
      runnable - the thread's runnable.
      Returns:
      a new daemon thread.
    • get

      public Tailer get()
      Constructs a new instance.

      This builder use the aspects tailable, Charset, TailerListener, delayDuration, end, reOpen, buffer size.

      Returns:
      a new instance.
    • setDelayDuration

      public Tailer.Builder setDelayDuration(Duration delayDuration)
      Sets the delay duration. null resets to the default delay of one second.
      Parameters:
      delayDuration - the delay between checks of the file for new content.
      Returns:
      this
    • setExecutorService

      public Tailer.Builder setExecutorService(ExecutorService executorService)
      Sets the executor service to use when startThread is true.
      Parameters:
      executorService - the executor service to use when startThread is true.
      Returns:
      this
    • setOrigin

      protected Tailer.Builder setOrigin(AbstractOrigin<?,?> origin)
      Sets the origin.
      Overrides:
      setOrigin in class AbstractOriginSupplier<Tailer,Tailer.Builder>
      Parameters:
      origin - the new origin.
      Returns:
      this
      Throws:
      UnsupportedOperationException - if the origin cannot be converted to a Path.
    • setReOpen

      public Tailer.Builder setReOpen(boolean reOpen)
      Sets the re-open behavior.
      Parameters:
      reOpen - whether to close/reopen the file between chunks
      Returns:
      this
    • setStartThread

      public Tailer.Builder setStartThread(boolean startThread)
      Sets the daemon thread startup behavior.
      Parameters:
      startThread - whether to create a daemon thread automatically.
      Returns:
      this
    • setTailable

      public Tailer.Builder setTailable(Tailer.Tailable tailable)
      Sets the tailable.
      Parameters:
      tailable - the tailable.
      Returns:
      this.
    • setTailerListener

      public Tailer.Builder setTailerListener(TailerListener tailerListener)
      Sets the listener.
      Parameters:
      tailerListener - the listener.
      Returns:
      this
    • setTailFromEnd

      public Tailer.Builder setTailFromEnd(boolean end)
      Sets the tail start behavior.
      Parameters:
      end - Set to true to tail from the end of the file, false to tail from the beginning of the file.
      Returns:
      this