Package org.globus.ftp.vanilla

# Class FTPServerFacade

java.lang.Object
org.globus.ftp.vanilla.FTPServerFacade

Direct Known Subclasses:
  `GridFTPServerFacade`

public class FTPServerFacade extends Object
This class is not ment directly for the users. This class represents the part of the client responsible for data channel management. Especially when the remote server is in the passive mode, it behaves a lot like a local server. Thus its interface looks very much like a server interface.
Current implementation is multithreaded. One thread is used for thread management and one for each transfer (this makes sense in GridFTP parallelism).
The public methods can generally be divided into setter methods and active methods. Active methods are setActive(), setPassive(), retrieve(), and store(), and setter methods are the remaining. Setter methods do not generally throw exceptions related to ftp. Settings are not checked for correctness until the server is asked to performed some action, which is done by active methods. So you are safe to cal setXX() methods with any argument you like, until you call one of the "active" methods mentioned above.
The managing thread is not started until one of the "active" methods is called: setActive(), retrieve(), or store(). These methods are asynchronous (return before completion) and the action is undertaken by the local manager thread. From this point on, all communication back to the caller is done through unidirectional local control channel. Information is communicated back to the user in form of FTP replies (instances of LocalReply). Generally, the sequence of replies should be the same as when communicating with remote server during the transfer (1xx intermediary reply; markers; final 226). Exceptions are serialized into 451 negative reply.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`protected class`
`FTPServerFacade.LocalControlChannel`
This inner class represents a local control channel.

## Field Summary

Fields
Modifier and Type
Field
Description
`static final int`
`ANY_PORT`
local server socket parameter; used in setPassive()
`protected DataChannelFactory`
`dataChannelFactory`
`static final int`
`DEFAULT_QUEUE`
local server socket parameter; used in setPassive()
`protected FTPServerFacade.LocalControlChannel`
`localControlChannel`
`protected FTPControlChannel`
`remoteControlChannel`
`protected HostPort`
`remoteServerAddress`
`protected ServerSocket`
`serverSocket`
`protected Session`
`session`

## Constructor Summary

Constructors
Constructor
Description
`FTPServerFacade(FTPControlChannel remoteControlChannel)`

## Method Summary

Modifier and Type
Method
Description
`void`
`abort()`
close data channels, but not control, nor the server
`void`
`authorize()`
No need for parameters; locally you are always authorized.
`static void`
`cannotPropagateError(Throwable e)`
Data channels are operated in multithreaded manner and they pass information (including exceptions) to the user using the local control channel.
`void`
`close()`
`protected TransferContext`
`createTransferContext()`
`protected void`
`exceptionToControlChannel(Throwable e, String msg)`
Convert the exception to a negative 451 reply, and pipe it to the control channel.
`static void`
`exceptionToControlChannel(Throwable e, String msg, BasicServerControlChannel control)`
Convert the exception to a negative 451 reply, and pipe it to the provided control channel.
`BasicClientControlChannel`
`getControlChannel()`
Use this method to get the client end of the local control channel.
`Session`
`getSession()`
`void`
`retrieve(DataSource source)`
Asynchronous; return before completion.
`void`
`setActive(HostPort hp)`
Asynchronous; return before completion.
`void`
`setOptions(Options opts)`
Do nothing; this class does not support any options
`HostPort`
`setPassive()`
Behave like setPassive(ANY_PORT, DEFAULT_QUEUE)
`HostPort`
`setPassive(int port, int queue)`
Start the local server
`void`
`setProtectionBufferSize(int size)`
`void`
`setTransferMode(int mode)`
`void`
`setTransferType(int type)`
`protected void`
`stopTaskThread()`
`void`
`store(DataSink sink)`
Asynchronous; return before completion.
`protected void`
`transferAbort()`
`protected void`
`unblockServer()`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### ANY_PORT

public static final int ANY_PORT
local server socket parameter; used in setPassive()

See Also:
  - Constant Field Values

### DEFAULT_QUEUE

public static final int DEFAULT_QUEUE
local server socket parameter; used in setPassive()

See Also:
  - Constant Field Values

### session

protected Session session

### localControlChannel

protected FTPServerFacade.LocalControlChannel localControlChannel

### dataChannelFactory

protected DataChannelFactory dataChannelFactory

### serverSocket

protected ServerSocket serverSocket

### remoteControlChannel

protected FTPControlChannel remoteControlChannel

### remoteServerAddress

protected HostPort remoteServerAddress

## Constructor Details

### FTPServerFacade

public FTPServerFacade(FTPControlChannel remoteControlChannel)

## Method Details

### cannotPropagateError

public static void cannotPropagateError(Throwable e)
Data channels are operated in multithreaded manner and they pass information (including exceptions) to the user using the local control channel. In the unlikely event that it fails, there is no way to communicate the exception to the user. In such circumstances this method should be called to print the exception directly to console.

### getControlChannel

public BasicClientControlChannel getControlChannel()
Use this method to get the client end of the local control channel. It is the only way to get the information of the current transfer state.

### getSession

public Session getSession()

Returns:
  the session object associated with this server

### authorize

public void authorize()
No need for parameters; locally you are always authorized.

### setTransferType

public void setTransferType(int type)

### setTransferMode

public void setTransferMode(int mode)

### setProtectionBufferSize

public void setProtectionBufferSize(int size)

### setOptions

public void setOptions(Options opts)
Do nothing; this class does not support any options

### setPassive

public HostPort setPassive() throws IOException
Behave like setPassive(ANY_PORT, DEFAULT_QUEUE)

Throws:
  `IOException`

### setPassive

public HostPort setPassive(int port, int queue) throws IOException
Start the local server

Parameters:
  `port` - required server port; can be set to ANY_PORT
  `queue` - max size of queue of awaiting new connection requests
Returns:
  the server address
Throws:
  `IOException`

### setActive

public void setActive(HostPort hp) throws UnknownHostException, ClientException, IOException
Asynchronous; return before completion. Connect to the remote server. Any exception that would occure will not be thrown but returned through the local control channel.

Throws:
  `UnknownHostException`
  `ClientException`
  `IOException`

### exceptionToControlChannel

protected void exceptionToControlChannel(Throwable e, String msg)
Convert the exception to a negative 451 reply, and pipe it to the control channel.

### exceptionToControlChannel

public static void exceptionToControlChannel(Throwable e, String msg, BasicServerControlChannel control)
Convert the exception to a negative 451 reply, and pipe it to the provided control channel.

### store

public void store(DataSink sink)
Asynchronous; return before completion. Start the incoming transfer and store the file to the supplied data sink. Any exception that would occure will not be thrown but returned through the local control channel.

### retrieve

public void retrieve(DataSource source)
Asynchronous; return before completion. Start the outgoing transfer reading the data from the supplied data source. Any exception that would occure will not be thrown but returned through the local control channel.

### abort

public void abort() throws IOException
close data channels, but not control, nor the server

Throws:
  `IOException`

### transferAbort

protected void transferAbort()

### unblockServer

protected void unblockServer()

### close

public void close() throws IOException

Throws:
  `IOException`

### stopTaskThread

protected void stopTaskThread()

### createTransferContext

protected TransferContext createTransferContext()