Class 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)