use of com.axway.ats.core.filetransfer.model.TransferListener in project ats-framework by Axway.
the class AbstractFileTransferClient method startUploadAndPause.
public void startUploadAndPause(final String localFile, final String remoteDir, final String remoteFile) throws FileTransferException {
checkPausedTransferRunning(false);
// a paused transfer is started.
this.isTransferStartedAndPaused = true;
// get the executor thread.
final Thread currentThread = Thread.currentThread();
final Thread uploadThread = new Thread("Upload Thread") {
private final Logger log = LogManager.getLogger(this.getName());
@Override
public void run() {
synchronized (AbstractFileTransferClient.this) {
// Notify the executor thread that the upload is starting.
// The executor thread will stop waiting for the upload to start
// but will not do anything until it receives the object's monitor.
canResume = true;
AbstractFileTransferClient.this.notifyAll();
// the number of the progress event on which to wait
int progressEventNumber = 0;
if (new File(localFile).length() == 0) {
// if the file is empty no progress events will be fired
progressEventNumber = -1;
}
// Add a listener to notify the executor that the transfer is paused.
TransferListener listener = addListener(progressEventNumber);
try {
// Start the upload.
AbstractFileTransferClient.this.performUploadFile(localFile, remoteDir, remoteFile);
// Notify the executor thread that the upload has finished successfully.
AbstractFileTransferClient.this.notifyAll();
} catch (FileTransferException e) {
log.error("Upload failed.", e);
// Interrupt the executor thread so that an exception can be thrown
// while waiting for the upload to finish.
currentThread.interrupt();
} finally {
// Ensure the listener is removed to prevent deadlocks in further transfers.
removeListener(listener);
}
}
}
};
uploadThread.start();
}
Aggregations