Package org.apache.ignite.internal.managers.communication

## Class GridIoManager.TransmissionSender

- java.lang.Object
- - org.apache.ignite.internal.managers.communication.GridIoManager.TransmissionSender

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

Enclosing class:
  GridIoManager

    public class GridIoManager.TransmissionSender
    extends Object
    implements Closeable

Сlass represents an implementation of transmission file writer. Each new instance of transmission sender will establish a new connection with unique transmission session identifier to the remote node and given topic (an arbitraty `GridTopic` can be used).

## Zero-copy approach

Current implementation of transmission sender is based on file zero-copy approach (the `FileSender` is used under the hood). It is much more efficient than a simple loop that reads data from given file and writes it to the target socket channel. But if operating system does not support zero-copy file transfer, sending a file with `GridIoManager.TransmissionSender` might fail or yield worse performance.

Please, refer to http://en.wikipedia.org/wiki/Zero-copy or `FileChannel.transferTo(long, long, WritableByteChannel)` for details of such approach.

## File and Chunk handlers

It is possible to choose a file handler prior to sendig the file to remote node within opened transmission session. There are two types of handlers available: `TransmissionHandler.chunkHandler(UUID, TransmissionMeta)` and `TransmissionHandler.fileHandler(UUID, TransmissionMeta)`. You can use an appropriate `TransmissionPolicy` for `send(File, long, long, Map, TransmissionPolicy)` method to switch between them.

## Exceptions handling

Each transmission can have two different high-level types of exception which are handled differently:

- transport exception(e.g. some network issues)
- application\handler level exception

### Application exceptions

The transmission will be stopped immediately and wrapping IgniteExcpetion thrown in case of any application exception occured.

### Transport exceptions

All transport level exceptions of transmission file sender will require transmission to be reconnected. For instance, when the local node closes the socket connection in orderly way, but the file is not fully handled by remote node, the read operation over the same socket endpoint will return `-1`. Such result will be consideread as an `IOException` by handler and it will wait for reestablishing connection to continue file loading.

Another example, the transmission sender gets the Connection reset by peer IOException message. This means that the remote node you are connected to has to reset the connection. This is usually caused by a high amount of traffic on the host, but may be caused by a server error or the remote node has exhausted system resources as well. Such `IOException` will be considered as reconnection required.

### Timeout exceptions

For read operations over the `InputStream` or write operation through the `OutputStream` the `Socket.setSoTimeout(int)` will be used and an `SocketTimeoutException` will be thrown when the timeout occured. The default value is taken from `IgniteConfiguration.getNetworkTimeout()`.

If reconnection is not occurred withing configured timeout interval the timeout object will be fired which clears corresponding to the used topic the `GridIoManager.ReceiverContext`.

## Release resources

It is important to call close() method or use try-with-resource statement to release all resources once you've done with sending files.

See Also:
  `FileChannel.transferTo(long, long, WritableByteChannel)`

### Constructor Summary

Constructors
`TransmissionSender​(UUID rmtId, Object topic)`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `close()`
`void` `send​(File file, long offset, long cnt, Map<String,​Serializable> params, TransmissionPolicy plc)`
`void` `send​(File file, Map<String,​Serializable> params, TransmissionPolicy plc)`
`void` `send​(File file, TransmissionPolicy plc)`

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

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

### Constructor Detail

#### TransmissionSender

    public TransmissionSender​(UUID rmtId,
                              Object topic)

Parameters:
  `rmtId` - The remote node to connect to.
  `topic` - The remote topic to connect to.

### Method Detail

#### send

    public void send​(File file,
                     Map<String,​Serializable> params,
                     TransmissionPolicy plc)
              throws IgniteCheckedException,
                     InterruptedException,
                     IOException

Parameters:
  `file` - Source file to send to remote.
  `params` - Additional file params.
  `plc` - The policy of handling data on remote.
Throws:
  `IgniteCheckedException` - If fails.
  `InterruptedException`
  `IOException`

#### send

    public void send​(File file,
                     TransmissionPolicy plc)
              throws IgniteCheckedException,
                     InterruptedException,
                     IOException

Parameters:
  `file` - Source file to send to remote.
  `plc` - The policy of handling data on remote.
Throws:
  `IgniteCheckedException` - If fails.
  `InterruptedException`
  `IOException`

#### send

    public void send​(File file,
                     long offset,
                     long cnt,
                     Map<String,​Serializable> params,
                     TransmissionPolicy plc)
              throws IgniteCheckedException,
                     InterruptedException,
                     IOException

Parameters:
  `file` - Source file to send to remote.
  `offset` - Position to start trasfer at.
  `cnt` - Number of bytes to transfer.
  `params` - Additional file params.
  `plc` - The policy of handling data on remote.
Throws:
  `IgniteCheckedException` - If fails.
  `InterruptedException`
  `IOException`

#### close

    public void close()
               throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Throws:
  `IOException`