Package com.metasolv.nm.collector.file
Class FtpEIThread
java.lang.Object
java.lang.Thread
com.metasolv.nm.collector.file.FtpEIThread
- All Implemented Interfaces:
Runnable
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected boolean
protected FtpFileTracker
protected FtpSupportIntf
protected static final String
protected int
protected com.nt.common.util.SMGLock
protected String
protected String
protected LoggerIfc
protected static final int
protected static final int
protected DCNode
protected boolean
protected String
protected static final String
protected static final String
protected Pattern
protected String
protected String
protected boolean
protected static final int
protected boolean
protected SynchronizedDirectory
The SynchronizedDirectory ensures that files won't be processed prematurely.protected static final int
protected int
protected boolean
protected String
protected static final String
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
ConstructorsConstructorDescriptionFtpEIThread
(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) 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 -
Method Summary
Modifier and TypeMethodDescriptionprotected boolean
This method creates the connection, retrieves the files and notifies the consumer of the files via the SynchronizedDirectory object.protected String
getLocalName
(String prefix, String filename) Generates a unique local file name.int
boolean
This method is used to check if the transport is fully functional.protected ArrayList
List all the files with the specified suffix that are in the specified directory on the FTP server.protected boolean
retrieveSingleFile
(String remote) This method will retrieve a single file from the remote FTP server.void
run()
Continuously polls for new files to retrieve until it's time to shut down.void
void
void
setIOLock
(com.nt.common.util.SMGLock lock) void
setLocalSuffix
(String suffix) void
setOverwriteExisting
(boolean flag) void
setRemotePath
(String path) void
setSleepTime
(int time) void
void
shutdown()
protected void
sleep
(int sleepSecs) Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
MILLISECS_PER_MINUTE
protected static final int MILLISECS_PER_MINUTE- See Also:
-
WILDCARD
- See Also:
-
PATH_SEPARATOR
- See Also:
-
REMOTE_SUFFIX
- See Also:
-
HOSTS_FILE
- See Also:
-
SFTP_PORT
protected static final int SFTP_PORT- See Also:
-
ipAddress
-
username
-
password
-
ftpSession
-
remotePath
-
remoteRegExp
-
remoteFilePattern
-
localSuffix
-
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
-
ftpFileTracker
-
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 useremoteHost
- The IP address of the FTP serverlogin
- The username to use for logging inpass
- The password for the given usernameremoteFileDir
- The remote directory to retrieve from the FTP servermode
- The remote file filter pattern modeprefix
- The remote file prefixsuffix
- The remote file suffixregExp
- The regular expression for remote filelocalSuffix
- Specifies the local suffix for the retrieved filesdelayTime
- The number of milliseconds to wait between successive retrievalsbinary
- Determines if files should be retrieved in binary mode (false = ASCII mode)deleteFlag
- Determines whether to delete the remote files after processingrenameFlag
- Determines whether to rename the remote files after processingdir
- The local directory into which files will be placednode
- 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. -
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
- Throws:
InterruptedException
-
shutdown
public void shutdown() -
listFiles
List all the files with the specified suffix that are in the specified directory on the FTP server.- Parameters:
path
- Remote file directorypattern
- Remote file pattern to retrieve- Returns:
- ArrayList containing a list of the files to retrieve
- Throws:
IOException
-
retrieveSingleFile
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
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
-
getRemotePath
-
setLocalSuffix
-
getLocalSuffix
-
getRemoteRegExp
-
setSleepTime
public void setSleepTime(int time) -
getSleepTime
public int getSleepTime() -
setSynchronizedDirectory
-
getSynchronizedDirectory
-
getUsername
- Throws:
NullPointerException
-
getPassword
- Throws:
NullPointerException
-
getIPAddress
- Throws:
NullPointerException
-
setIOLock
public void setIOLock(com.nt.common.util.SMGLock lock)
-