public abstract class SendThroughClient extends AbstractTransfer
This class does not included the real file transfer since it is up to the business project to implement how to read new data to be sent to the remote host. If an error occurs, no transfer log is kept.
1) Configuration must have been loaded
2) Pipeline and NetworkTransaction must have been initiated:
Configuration.configuration.pipelineInit();
NetworkTransaction networkTransaction = new
NetworkTransaction();
3) Prepare the request of transfer:
R66Future futureReq = new R66Future(true);
SendThroughClient transaction = new SendThroughClient(futureReq,...);
if (! transaction.initiateRequest()) { error }
4) Once initiateRequest() gives true, you are ready to send the data in
through mode like:
byte[] data = readOrGetInSomeWayData();
DataBlock block = transaction.transformToDataBlock(data);
futureWrite = transaction.writeWhenPossible(block);
5) Once you have finished, so this is the last block, you have to do the
following:
If the last block is not empty:
DataBlock block = transaction.transformToDataBlock(data);
block.setEOF(true);
Or if the last block is empty:
DataBlock block = transaction.transformToDataBlock(null);
Then
futureWrite = transaction.writeWhenPossible(block);
futureWrite.awaitUninterruptibly();
6) If everything is in success:
transaction.finalizeRequest();
And now wait for the transfer to finish:
futureReq.awaitUninterruptibly();
R66Result result = futureReq.getResult();
7) If there is the need to re-do, just re-execute the steps from 3 to 6.
Don't forget at the very end to finish the global structure (steps 3 to 6 no
more executed):
networkTransaction.closeAll();
8) In case of errors during steps 4 or 5 (and only those), call the
following:
Class as example of usage in test part
Modifier and Type | Field and Description |
---|---|
protected LocalChannelReference |
localChannelReference |
protected NetworkTransaction |
networkTransaction |
protected DbTaskRunner |
taskRunner |
_INFO_ARGS, block, blocksize, fileinfo, fileInfo, filename, future, id, idt, ismd5, isMD5, localFilename, logger, NO_INFO_ARGS, nolog, normalInfoAsWarn, remoteHost, rhost, rule, rulename, snormalInfoAsWarn, startTime, ttimestart
Modifier | Constructor and Description |
---|---|
protected |
SendThroughClient(R66Future future,
String remoteHost,
String filename,
String rulename,
String fileinfo,
boolean isMD5,
int blocksize,
long id,
NetworkTransaction networkTransaction) |
Modifier and Type | Method and Description |
---|---|
void |
finalizeRequest()
Finalize the request
|
boolean |
initiateRequest()
Prior to call this method, the pipeline and NetworkTransaction must have
been initialized.
|
void |
run()
DO NOT CALL THIS!
|
void |
transferInError(OpenR66Exception e)
To be used in case of error after a correct initiate of the request
|
DataBlock |
transformToDataBlock(byte[] data)
Utility method for send through mode
|
io.netty.channel.ChannelFuture |
writeWhenPossible(DataBlock block)
Write the next block when the channel is ready to prevent OOM
|
clear, finalizeInErrorTransferRequest, getLocalFiles, getParams, getParamsInternal, getRemoteFiles, initRequest, prepareKoOutputFormat, prepareKoOutputFormat, prepareOkOutputFormat, prepareSubmitKoOutputFormat, prepareSubmitOkOutputFormat, sendValidPacket, setNormalInfoAsWarn, tryConnect
protected final NetworkTransaction networkTransaction
protected LocalChannelReference localChannelReference
protected DbTaskRunner taskRunner
protected SendThroughClient(R66Future future, String remoteHost, String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, long id, NetworkTransaction networkTransaction)
future
- remoteHost
- filename
- rulename
- fileinfo
- isMD5
- blocksize
- networkTransaction
- id
- public void run()
public boolean initiateRequest()
public void finalizeRequest()
public void transferInError(OpenR66Exception e)
e
- public io.netty.channel.ChannelFuture writeWhenPossible(DataBlock block) throws OpenR66RunnerErrorException, OpenR66ProtocolPacketException, OpenR66ProtocolSystemException
block
- OpenR66RunnerErrorException
OpenR66ProtocolPacketException
OpenR66ProtocolSystemException
public DataBlock transformToDataBlock(byte[] data)
data
- the data byte, if null it is the last blockCopyright © 2009–2020 Waarp. All rights reserved.