public class GridIoManager.TransmissionSender extends Object implements Closeable
GridTopic can be used).
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.
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.
Each transmission can have two different high-level types of exception which are handled differently:
The transmission will be stopped immediately and wrapping IgniteExcpetion thrown in case of any application exception occured.
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.
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.
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 and Description |
|---|
TransmissionSender(UUID rmtId,
Object topic) |
| Modifier and Type | Method and Description |
|---|---|
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) |
public void send(File file, Map<String,Serializable> params, TransmissionPolicy plc) throws IgniteCheckedException, InterruptedException, IOException
file - Source file to send to remote.params - Additional file params.plc - The policy of handling data on remote.IgniteCheckedException - If fails.InterruptedExceptionIOExceptionpublic void send(File file, TransmissionPolicy plc) throws IgniteCheckedException, InterruptedException, IOException
file - Source file to send to remote.plc - The policy of handling data on remote.IgniteCheckedException - If fails.InterruptedExceptionIOExceptionpublic void send(File file, long offset, long cnt, Map<String,Serializable> params, TransmissionPolicy plc) throws IgniteCheckedException, InterruptedException, IOException
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.IgniteCheckedException - If fails.InterruptedExceptionIOExceptionpublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOException
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.9.1 Release Date : December 9 2020