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 arbitratyGridTopiccan be used).Zero-copy approach
Current implementation of transmission sender is based on file zero-copy approach (the
FileSenderis 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 withGridIoManager.TransmissionSendermight 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)andTransmissionHandler.fileHandler(UUID, TransmissionMeta). You can use an appropriateTransmissionPolicyforsend(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
IOExceptionby 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
IOExceptionwill be considered as reconnection required.Timeout exceptions
For read operations over the
InputStreamor write operation through theOutputStreamtheSocket.setSoTimeout(int)will be used and anSocketTimeoutExceptionwill be thrown when the timeout occured. The default value is taken fromIgniteConfiguration.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.
-
-
Constructor Summary
Constructors Constructor Description TransmissionSender(UUID rmtId, Object topic)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidsend(File file, long offset, long cnt, Map<String,Serializable> params, TransmissionPolicy plc)voidsend(File file, Map<String,Serializable> params, TransmissionPolicy plc)voidsend(File file, TransmissionPolicy plc)
-
-
-
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.InterruptedExceptionIOException
-
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.InterruptedExceptionIOException
-
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.InterruptedExceptionIOException
-
close
public void close() throws IOException- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
-