Class FtpEIThread

java.lang.Object
java.lang.Thread
com.metasolv.nm.collector.file.FtpEIThread
All Implemented Interfaces:
Runnable

public class FtpEIThread extends Thread
This class is based on the FtpEITransport class. The main differences are the use of the FtpSupportInf interface in order to support both regular FTP and SFTP, and the use of a file tracking object. The FtpEIThread class is responsible for managing the FTP connection to a single FTP server. It uses the FtpSupportIntf interface so that it can instantiate different types of FTP objects, which allows it to support regular and passive FTP via the FtpSession class, and SFTP via the SftpSession class. It will poll the remote FTP server for new files based on the configuration settings, and retrieve new files as they are identified. It will also keep track of the files that it has retrieved via the FtpFileTracker object, which will be used to ensure that the same files are not retrieved on subsequent polls. After retrieving a file, it will rename, delete, or leave the remote file unchanged based on the configuration settings.
  • Field Details

    • MILLISECS_PER_MINUTE

      protected static final int MILLISECS_PER_MINUTE
      See Also:
    • WILDCARD

      protected static final String WILDCARD
      See Also:
    • PATH_SEPARATOR

      protected static final String PATH_SEPARATOR
      See Also:
    • REMOTE_SUFFIX

      protected static final String REMOTE_SUFFIX
      See Also:
    • HOSTS_FILE

      protected static final String HOSTS_FILE
      See Also:
    • SFTP_PORT

      protected static final int SFTP_PORT
      See Also:
    • ipAddress

      protected String ipAddress
    • username

      protected String username
    • password

      protected String password
    • ftpSession

      protected FtpSupportIntf ftpSession
    • remotePath

      protected String remotePath
    • remoteRegExp

      protected String remoteRegExp
    • remoteFilePattern

      protected Pattern remoteFilePattern
    • localSuffix

      protected String localSuffix
    • logger

      protected LoggerIfc logger
    • running

      protected boolean running
    • deleteRemoteFiles

      protected boolean deleteRemoteFiles
    • renameRemoteFiles

      protected boolean renameRemoteFiles
    • usePassiveFTP

      protected boolean usePassiveFTP
    • overwriteExisting

      protected boolean overwriteExisting
    • sleepTime

      protected int sleepTime
    • RETRY_DELAY

      protected static final int RETRY_DELAY
      See Also:
    • MAX_RETRIES

      protected static final int MAX_RETRIES
      See Also:
    • node

      protected DCNode node
    • ftpFileTracker

      protected FtpFileTracker ftpFileTracker
    • sd

      protected SynchronizedDirectory sd
      The SynchronizedDirectory ensures that files won't be processed prematurely.
    • interruptTimeDelay

      protected int interruptTimeDelay
    • ioLock

      protected com.nt.common.util.SMGLock ioLock
  • Constructor Details

    • FtpEIThread

      public FtpEIThread(String ftpType, String remoteHost, String login, String pass, String remoteFileDir, String mode, String prefix, String suffix, String regExp, String localSuffix, int delayTime, boolean binary, boolean deleteFlag, boolean renameFlag, SynchronizedDirectory dir, DCNode node, FtpFileTracker tracker, int interruptDelay)
      Constructor
      Parameters:
      ftpType - The type of FTP to use
      remoteHost - The IP address of the FTP server
      login - The username to use for logging in
      pass - The password for the given username
      remoteFileDir - The remote directory to retrieve from the FTP server
      mode - The remote file filter pattern mode
      prefix - The remote file prefix
      suffix - The remote file suffix
      regExp - The regular expression for remote file
      localSuffix - Specifies the local suffix for the retrieved files
      delayTime - The number of milliseconds to wait between successive retrievals
      binary - Determines if files should be retrieved in binary mode (false = ASCII mode)
      deleteFlag - Determines whether to delete the remote files after processing
      renameFlag - Determines whether to rename the remote files after processing
      dir - The local directory into which files will be placed
      node - The EI Node that is using this FTP object
    • FtpEIThread

      public FtpEIThread(String ftpType, String remoteHost, String login, String pass, String remoteFileDir, String mode, String prefix, String suffix, String regExp, String localSuffix, int delayTime, boolean binary, boolean deleteFlag, boolean renameFlag, SynchronizedDirectory dir, DCNode node, FtpFileTracker tracker)
  • Method Details

    • run

      public void run()
      Continuously polls for new files to retrieve until it's time to shut down.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • connectAndGetFiles

      protected boolean connectAndGetFiles()
      This method creates the connection, retrieves the files and notifies the consumer of the files via the SynchronizedDirectory object.
      Returns:
      true, if successful - false, if not
    • sleep

      protected void sleep(int sleepSecs) throws InterruptedException
      Throws:
      InterruptedException
    • shutdown

      public void shutdown()
    • listFiles

      protected ArrayList listFiles(String path, Pattern pattern) throws IOException
      List all the files with the specified suffix that are in the specified directory on the FTP server.
      Parameters:
      path - Remote file directory
      pattern - Remote file pattern to retrieve
      Returns:
      ArrayList containing a list of the files to retrieve
      Throws:
      IOException
    • retrieveSingleFile

      protected boolean retrieveSingleFile(String remote)
      This method will retrieve a single file from the remote FTP server.
      Parameters:
      remote - Specifies the name of the remote file (incl path)
      Returns:
      true-if successful
    • getLocalName

      protected String getLocalName(String prefix, String filename)
      Generates a unique local file name.
    • isHealthy

      public boolean isHealthy()
      This method is used to check if the transport is fully functional.
    • setOverwriteExisting

      public void setOverwriteExisting(boolean flag)
    • setBinaryMode

      public void setBinaryMode()
    • setASCIIMode

      public void setASCIIMode()
    • setRemotePath

      public void setRemotePath(String path)
    • getRemotePath

      public String getRemotePath()
    • setLocalSuffix

      public void setLocalSuffix(String suffix)
    • getLocalSuffix

      public String getLocalSuffix()
    • getRemoteRegExp

      public String getRemoteRegExp()
    • setSleepTime

      public void setSleepTime(int time)
    • getSleepTime

      public int getSleepTime()
    • setSynchronizedDirectory

      public void setSynchronizedDirectory(SynchronizedDirectory dir)
    • getSynchronizedDirectory

      public SynchronizedDirectory getSynchronizedDirectory()
    • getUsername

      public String getUsername() throws NullPointerException
      Throws:
      NullPointerException
    • getPassword

      public String getPassword() throws NullPointerException
      Throws:
      NullPointerException
    • getIPAddress

      public String getIPAddress() throws NullPointerException
      Throws:
      NullPointerException
    • setIOLock

      public void setIOLock(com.nt.common.util.SMGLock lock)