Class FileTransferConnection
- java.lang.Object
-
- com.adaptris.core.AdaptrisConnectionImp
-
- com.adaptris.core.NoOpConnection
-
- com.adaptris.core.ftp.FileTransferConnection
-
- All Implemented Interfaces:
AdaptrisComponent,AdaptrisConnection,ComponentLifecycle,ComponentLifecycleExtension,StateManagedComponent
- Direct Known Subclasses:
FileTransferConnectionUsingPassword,StandardSftpConnection
public abstract class FileTransferConnection extends NoOpConnection
Class containing common configuration for all FTP Connection types.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classFileTransferConnection.UserInfo
-
Field Summary
Fields Modifier and Type Field Description protected static TimeIntervalDEFAULT_EXPIRATIONprotected static intDEFAULT_MAX_CACHE_SIZEThe default size of the cache if a size isn't specified (16)-
Fields inherited from class com.adaptris.core.AdaptrisConnectionImp
log
-
-
Constructor Summary
Constructors Constructor Description FileTransferConnection()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract booleanacceptProtocol(java.lang.String s)Validate the URL Protocol when a URL is used.booleanadditionalDebug()booleancacheConnection()protected voidcloseConnection()Close the underlying connection.FileTransferClientconnect(java.lang.String hostUrl)Connect to the host.protected abstract FileTransferClientcreate(java.lang.String host, int port, FileTransferConnection.UserInfo ui)Create an instance of theFileTransferClientfor use with the producer or consumer.protected abstract FileTransferConnection.UserInfocreateUserInfo()abstract intdefaultControlPort()voiddisconnect(FileTransferClient ftp)Disconnect the FTP client.protected longexpirationMillis()booleanforceRelativePath()java.lang.BooleangetAdditionalDebug()The additional debug flag.java.lang.BooleangetCacheConnection()TimeIntervalgetCacheExpiration()java.lang.IntegergetDefaultControlPort()java.lang.StringgetDefaultUserName()Returns the default user name.java.lang.StringgetDirectoryRoot(java.lang.String hostUrl)Returns the directory root for the passed host URL.java.lang.BooleangetForceRelativePath()Get the force relative path flag.java.lang.IntegergetMaxClientCacheSize()Get the max number of entries in the cache.java.lang.BooleangetWindowsWorkAround()protected voidinitConnection()Initialise the underlying connection.intmaxClientCacheSize()voidsetAdditionalDebug(java.lang.Boolean b)Get additional logging output where available.voidsetCacheConnection(java.lang.Boolean b)Set whether or not connections created are held open for future use.voidsetCacheExpiration(TimeInterval expiration)voidsetDefaultControlPort(java.lang.Integer i)Override the default port.voidsetDefaultUserName(java.lang.String s)Set the user name.voidsetForceRelativePath(java.lang.Boolean b)Force the path to be relative when using getDirectoryRoot(String).voidsetMaxClientCache(java.lang.Integer maxSize)Set the max number of entries in the cache.voidsetWindowsWorkAround(java.lang.Boolean b)Set whether the target server is a windows machine that returns backslash separated filenames when doing NLIST on a directory rather than the normal forward slashes.booleanwindowsWorkaround()<T extends FileTransferConnection>
TwithCacheExpiration(TimeInterval i)-
Methods inherited from class com.adaptris.core.NoOpConnection
prepareConnection, startConnection, stopConnection
-
Methods inherited from class com.adaptris.core.AdaptrisConnectionImp
addExceptionListener, addMessageConsumer, addMessageProducer, changeState, cloneForTesting, close, connectionErrorHandler, getConnectionErrorHandler, getUniqueId, getWorkersFirstOnShutdown, init, prepare, requestClose, requestInit, requestStart, requestStop, retrieveComponentState, retrieveConnection, retrieveExceptionListeners, retrieveMessageConsumers, retrieveMessageProducers, setConnectionErrorHandler, setUniqueId, setWorkersFirstOnShutdown, start, stop, workersFirstOnShutdown
-
-
-
-
Field Detail
-
DEFAULT_MAX_CACHE_SIZE
protected static final int DEFAULT_MAX_CACHE_SIZE
The default size of the cache if a size isn't specified (16)- See Also:
setMaxClientCache(Integer), Constant Field Values
-
DEFAULT_EXPIRATION
protected static final TimeInterval DEFAULT_EXPIRATION
-
-
Method Detail
-
setForceRelativePath
public void setForceRelativePath(java.lang.Boolean b)
Force the path to be relative when using getDirectoryRoot(String).This is useful in the situation where the server in question does not have the user in a ftp jail
- Parameters:
b- true to prefix a.to the path.- See Also:
getDirectoryRoot(String)
-
getForceRelativePath
public java.lang.Boolean getForceRelativePath()
Get the force relative path flag.- Returns:
- true or false.
- See Also:
setForceRelativePath(Boolean)
-
forceRelativePath
public boolean forceRelativePath()
-
getDefaultUserName
public java.lang.String getDefaultUserName()
Returns the default user name.
- Returns:
- the default user name
-
setDefaultUserName
public void setDefaultUserName(java.lang.String s)
Set the user name.- Parameters:
s- the username.
-
getDefaultControlPort
public java.lang.Integer getDefaultControlPort()
- Returns:
- Returns the defaultControlPort.
-
defaultControlPort
public abstract int defaultControlPort()
-
setDefaultControlPort
public void setDefaultControlPort(java.lang.Integer i)
Override the default port.- Parameters:
i- The defaultControlPort to set.
-
setAdditionalDebug
public void setAdditionalDebug(java.lang.Boolean b)
Get additional logging output where available.- Parameters:
b- true to get additional logging.
-
getAdditionalDebug
public java.lang.Boolean getAdditionalDebug()
The additional debug flag.- Returns:
- true or false (default false)
- See Also:
setAdditionalDebug(Boolean)
-
additionalDebug
public boolean additionalDebug()
-
getWindowsWorkAround
public java.lang.Boolean getWindowsWorkAround()
- Returns:
- the windowsWorkAround
- See Also:
setWindowsWorkAround(Boolean)
-
setWindowsWorkAround
public void setWindowsWorkAround(java.lang.Boolean b)
Set whether the target server is a windows machine that returns backslash separated filenames when doing NLIST on a directory rather than the normal forward slashes.- Parameters:
b- the windowsWorkAround to set
-
windowsWorkaround
public boolean windowsWorkaround()
-
getCacheConnection
public java.lang.Boolean getCacheConnection()
- Returns:
- whether connection is held open after use
-
setCacheConnection
public void setCacheConnection(java.lang.Boolean b)
Set whether or not connections created are held open for future use.This feature is primarily intended to mitigate the connection cost when using FtpConsumer with a frequent poll interval.If multiple components end up using the same FileTransferClient instance from the cache (perhaps you have multiple FtpConsumer instances configured in the same channel) then you will likely end up with non-optimal performance due to thread synchronisation.
It is generally recommended that you configure the associated FtpConsumer and FtpProducer instances using the URL form of the destination if you intend to use the caching feature; this allows you to make sure that each component has its own unique FileTransferClient instance associated with it.
- Parameters:
b- true to enable, default false.- See Also:
setMaxClientCache(Integer)
-
cacheConnection
public boolean cacheConnection()
-
initConnection
protected void initConnection() throws CoreExceptionDescription copied from class:AdaptrisConnectionImpInitialise the underlying connection.- Overrides:
initConnectionin classNoOpConnection- Throws:
CoreException- wrapping any exception.- See Also:
NoOpConnection.initConnection()
-
closeConnection
protected void closeConnection()
Description copied from class:AdaptrisConnectionImpClose the underlying connection.- Overrides:
closeConnectionin classNoOpConnection- See Also:
AdaptrisConnectionImp.closeConnection()
-
connect
public FileTransferClient connect(java.lang.String hostUrl) throws FileTransferException, java.io.IOException, PasswordException
Connect to the host.- Parameters:
hostUrl- the host to connect to which can be in the form of an url or simply just the hostname in which case the default credentials and port numbers are used.- Returns:
- an FtpClient that is ready to use.
- Throws:
FileTransferExceptionjava.io.IOExceptionPasswordException
-
getMaxClientCacheSize
public java.lang.Integer getMaxClientCacheSize()
Get the max number of entries in the cache.- Returns:
- the maximum number of entries.
-
setMaxClientCache
public void setMaxClientCache(java.lang.Integer maxSize)
Set the max number of entries in the cache.Entries will be removed on a least recently accessed basis.
- Parameters:
maxSize- the maximum number of entries, default is 16- See Also:
setCacheConnection(Boolean)
-
maxClientCacheSize
public int maxClientCacheSize()
-
getCacheExpiration
public TimeInterval getCacheExpiration()
-
setCacheExpiration
public void setCacheExpiration(TimeInterval expiration)
-
withCacheExpiration
public <T extends FileTransferConnection> T withCacheExpiration(TimeInterval i)
-
expirationMillis
protected long expirationMillis()
-
acceptProtocol
protected abstract boolean acceptProtocol(java.lang.String s)
Validate the URL Protocol when a URL is used.- Parameters:
s- the URL Protocol- Returns:
- true if the URL protocol is acceptable to the concrete imp.
-
create
protected abstract FileTransferClient create(java.lang.String host, int port, FileTransferConnection.UserInfo ui) throws java.io.IOException, FileTransferException, PasswordException
Create an instance of theFileTransferClientfor use with the producer or consumer.- Parameters:
host- the remote host.port- the port to connect toui- a local UserInfo containing username and password- Returns:
- a
FileTransferClientobject - Throws:
java.io.IOException- wrapping a general comms error.FileTransferException- if a protocol specific exception occurred.PasswordException
-
getDirectoryRoot
public java.lang.String getDirectoryRoot(java.lang.String hostUrl)
Returns the directory root for the passed host URL.
- Parameters:
hostUrl- the host URL- Returns:
- the directory root for the passed host URL
-
disconnect
public void disconnect(FileTransferClient ftp)
Disconnect the FTP client.- Parameters:
ftp- the ftp client implementation
-
createUserInfo
protected abstract FileTransferConnection.UserInfo createUserInfo() throws FileTransferException
- Throws:
FileTransferException
-
-