Class DirPoll

All Implemented Interfaces:
FilenameFilter, Runnable, Configurable, Destroyable, LogSource

DirPoll operates on a set of directories which defaults to
  • request
  • response
  • tmp
  • run
  • bad
  • archive
scanning for incoming requests (of varying priorities) on the request directory and processing them by means of DirPoll.Processor or DirPoll.FileProcessor
Since:
jPOS 1.2.7
  • Field Details

  • Constructor Details

    • DirPoll

      public DirPoll()
      Default constructor.
  • Method Details

    • setPath

      public void setPath(String base)
      Sets the base poll directory and derives the standard subdirectories from it.
      Parameters:
      base - the base directory path
    • setShouldTimestampArchive

      public void setShouldTimestampArchive(boolean shouldTimestampArchive)
      When true, archive files are timestamped.
      Parameters:
      shouldTimestampArchive - true to timestamp archived files
    • setArchiveDateFormat

      public void setArchiveDateFormat(String dateFormat)
      Sets the date format pattern used when timestamping archived files.
      Parameters:
      dateFormat - the date format pattern (see SimpleDateFormat)
    • setShouldArchive

      public void setShouldArchive(boolean shouldArchive)
      When true, processed request files are moved to the archive directory.
      Parameters:
      shouldArchive - true to archive processed files
    • setShouldCompressArchive

      public void setShouldCompressArchive(boolean shouldCompressArchive)
      When true, archived files are compressed.
      Parameters:
      shouldCompressArchive - true to compress archived files
    • setAcceptZeroLength

      public void setAcceptZeroLength(boolean acceptZeroLength)
      When true, zero-length request files are accepted.
      Parameters:
      acceptZeroLength - true to accept zero-length files
    • getPath

      public String getPath()
      Returns the base poll directory path.
      Returns:
      the base path
    • setRequestDir

      public void setRequestDir(String dir)
      Sets the request sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setResponseDir

      public void setResponseDir(String dir)
      Sets the response sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setTmpDir

      public void setTmpDir(String dir)
      Sets the tmp sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setBadDir

      public void setBadDir(String dir)
      Sets the bad (failed) sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setRunDir

      public void setRunDir(String dir)
      Sets the run (in-progress) sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setArchiveDir

      public void setArchiveDir(String dir)
      Sets the archive sub-directory name relative to the base path.
      Parameters:
      dir - the sub-directory name
    • setPollInterval

      public void setPollInterval(long pollInterval)
      Sets the polling interval in milliseconds.
      Parameters:
      pollInterval - the interval in milliseconds
    • setResponseSuffix

      public void setResponseSuffix(String suffix)
      Sets the suffix appended to response file names.
      Parameters:
      suffix - the response file suffix
    • getPollInterval

      public long getPollInterval()
      Returns the polling interval in milliseconds.
      Returns:
      poll interval
    • setProcessor

      public void setProcessor(Object processor)
      Sets the processor used to handle request files.
      Parameters:
      processor - a DirPoll.Processor or DirPoll.FileProcessor instance
    • getRequestDir

      protected File getRequestDir()
      Returns the request directory.
      Returns:
      request directory
    • getResponseDir

      protected File getResponseDir()
      Returns the response directory.
      Returns:
      response directory
    • getTmpDir

      protected File getTmpDir()
      Returns the tmp directory.
      Returns:
      tmp directory
    • getBadDir

      protected File getBadDir()
      Returns the bad (failed) directory.
      Returns:
      bad directory
    • getRunDir

      protected File getRunDir()
      Returns the run (in-progress) directory.
      Returns:
      run directory
    • getArchiveDir

      protected File getArchiveDir()
      Returns the archive directory.
      Returns:
      archive directory
    • isRegexPriorityMatching

      public boolean isRegexPriorityMatching()
      Returns whether regex-based priority matching is enabled.
      Returns:
      true if regex priority matching is active
    • setRegexPriorityMatching

      public void setRegexPriorityMatching(boolean regexPriorityMatching)
      Enables or disables regex-based file extension priority matching.
      Parameters:
      regexPriorityMatching - true to enable regex priority matching
    • getProcessor

      public Object getProcessor()
      Return instance implementing DirPoll.FileProcessor or DirPoll.Processor
      Returns:
      Object - need to be casted to DirPoll.FileProcessor or DirPoll.Processor
    • setConfiguration

      DirPool receives Configuration requests and pass along them to the underlying processor.
      Specified by:
      setConfiguration in interface Configurable
      Parameters:
      cfg - Configuration object
      Throws:
      ConfigurationException - on errors
    • setPriorities

      public void setPriorities(String priorities)
      Sets the file extension priority order for polling.
      Parameters:
      priorities - blank-separated list of file extensions in priority order
    • setThreadPool

      public void setThreadPool(ExecutorService executor)
      Sets the thread pool used to execute processor tasks.
      Parameters:
      executor - the executor service to use
    • accept

      public boolean accept(File dir, String name)
      FilenameFilter implementation that selects files matching the current priority extension.
      Specified by:
      accept in interface FilenameFilter
      Parameters:
      dir - the directory
      name - the file name
      Returns:
      true if the file should be accepted
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • destroy

      public void destroy()
      Description copied from interface: Destroyable
      Releases resources held by this object.
      Specified by:
      destroy in interface Destroyable
    • createDirs

      public void createDirs()
      Creates all required poll directories (request, response, tmp, bad, run, archive).
    • addPriority

      public void addPriority(String fileExtension)
      Adds a file extension to the priority list.
      Parameters:
      fileExtension - the extension to add (e.g. "xml")
    • scan

      protected File scan()
      Scans the request directory for the next file to process, respecting priority order.
      Returns:
      the next request File, or null if none is available
    • pause

      public void pause()
      Pauses the poll loop.
    • unpause

      public void unpause()
      Resumes a paused poll loop.
    • isPaused

      public boolean isPaused()
      Returns whether the poll loop is currently paused.
      Returns:
      true if paused