openr66.client
Class SendThroughClient

java.lang.Object
  extended by openr66.client.AbstractTransfer
      extended by openr66.client.SendThroughClient
All Implemented Interfaces:
Runnable
Direct Known Subclasses:
TestSendThroughClient, TestSendThroughForward

public abstract class SendThroughClient
extends AbstractTransfer

Class for Send Through client 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:
transaction.transferInError(openR66Exception);

Author:
Frederic Bregier
See Also:
{@link TestSendThroughClient} Class as example of usage

Field Summary
protected  LocalChannelReference localChannelReference
           
protected  NetworkTransaction networkTransaction
           
protected  DbTaskRunner taskRunner
           
 
Fields inherited from class openr66.client.AbstractTransfer
block, blocksize, dateFormat, fileinfo, fileInfo, filename, future, id, idt, ismd5, isMD5, localFilename, logger, nolog, remoteHost, rhost, rule, rulename, startTime, ttimestart
 
Constructor Summary
SendThroughClient(R66Future future, String remoteHost, String filename, String rulename, String fileinfo, boolean isMD5, int blocksize, long id, NetworkTransaction networkTransaction)
           
 
Method Summary
 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
 goldengate.common.file.DataBlock transformToDataBlock(byte[] data)
          Utility method for send through mode
 org.jboss.netty.channel.ChannelFuture writeWhenPossible(goldengate.common.file.DataBlock block)
          Write the next block when the channel is ready to prevent OOM
 
Methods inherited from class openr66.client.AbstractTransfer
getParams, initRequest
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

networkTransaction

protected final NetworkTransaction networkTransaction

localChannelReference

protected LocalChannelReference localChannelReference

taskRunner

protected DbTaskRunner taskRunner
Constructor Detail

SendThroughClient

public SendThroughClient(R66Future future,
                         String remoteHost,
                         String filename,
                         String rulename,
                         String fileinfo,
                         boolean isMD5,
                         int blocksize,
                         long id,
                         NetworkTransaction networkTransaction)
Parameters:
future -
remoteHost -
filename -
rulename -
fileinfo -
isMD5 -
blocksize -
networkTransaction -
id -
Method Detail

run

public void run()
DO NOT CALL THIS!


initiateRequest

public boolean initiateRequest()
Prior to call this method, the pipeline and NetworkTransaction must have been initialized. It is the responsibility of the caller to finish all network resources. Note that this is only the first part of the execution for this client.

Returns:
True if the initiate of the request is OK, else False

finalizeRequest

public void finalizeRequest()
Finalize the request


transferInError

public void transferInError(OpenR66Exception e)
To be used in case of error after a correct initiate of the request

Parameters:
e -

writeWhenPossible

public org.jboss.netty.channel.ChannelFuture writeWhenPossible(goldengate.common.file.DataBlock block)
                                                        throws OpenR66RunnerErrorException,
                                                               OpenR66ProtocolPacketException,
                                                               OpenR66ProtocolSystemException
Write the next block when the channel is ready to prevent OOM

Parameters:
block -
Returns:
the ChannelFuture on the write operation
Throws:
OpenR66RunnerErrorException
OpenR66ProtocolPacketException
OpenR66ProtocolSystemException

transformToDataBlock

public goldengate.common.file.DataBlock transformToDataBlock(byte[] data)
Utility method for send through mode

Parameters:
data - the data byte, if null it is the last block
Returns:
the DataBlock associated to the data


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.