Example usage for com.amazonaws.event ProgressEvent toString

List of usage examples for com.amazonaws.event ProgressEvent toString

Introduction

In this page you can find the example usage for com.amazonaws.event ProgressEvent toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:msv_upload_tool.FXMLDocumentController.java

private void uploadObject() {

    final Long max = file.length();

    task = new Task<Void>() {
        @Override//from   w  w w . j av  a  2 s . co m
        protected Void call() {

            boolean doLoop = true;
            long total = 0;

            while (doLoop) {

                lock.readLock().lock();

                try {
                    total = totalBytes;
                } finally {
                    lock.readLock().unlock();
                }

                updateProgress(total, max);
                if (total == max)
                    doLoop = false;

                try {
                    Thread.sleep(50); //1000 milliseconds is one second.
                } catch (InterruptedException ex) {
                    Thread.currentThread().interrupt();
                }

            }

            updateProgress(-1, max);

            this.succeeded();
            return null;

        }
    };

    uploadProgress.progressProperty().bind(task.progressProperty());
    task.setOnSucceeded(new EventHandler() {

        @Override
        public void handle(Event event) {

            label.setText("");

            label2.setText("");
            button.setDisable(true);
            button2.setDisable(false);

        }

    });

    Thread th = new Thread(task);

    th.setDaemon(true);

    //disable the buttons
    button.setDisable(true);
    button2.setDisable(true);

    th.start();

    String existingBucketName = "mstargeneralfiles";
    String keyName = "duh/" + file.getName();
    String filePath = file.getAbsolutePath();

    TransferManager tm = new TransferManager(new ProfileCredentialsProvider());

    // For more advanced uploads, you can create a request object 
    // and supply additional request parameters (ex: progress listeners,
    // canned ACLs, etc.)
    PutObjectRequest request = new PutObjectRequest(existingBucketName, keyName, new File(filePath));

    // You can ask the upload for its progress, or you can 
    // add a ProgressListener to your request to receive notifications 
    // when bytes are transferred.
    request.setGeneralProgressListener(new ProgressListener() {

        @Override
        public void progressChanged(ProgressEvent progressEvent) {

            System.out.println(progressEvent.toString());

            lock.writeLock().lock();

            try {
                totalBytes += progressEvent.getBytesTransferred();
            } finally {
                lock.writeLock().unlock();
            }

        }
    });

    // TransferManager processes all transfers asynchronously, 
    // so this call will return immediately.
    Upload upload = tm.upload(request);

}

From source file:org.anhonesteffort.p25.wav.WaveFileS3Sender.java

License:Open Source License

@Override
public void progressChanged(ProgressEvent event) {
    switch (event.getEventType()) {
    case TRANSFER_COMPLETED_EVENT:
        ImbeefMetrics.getInstance().wavPutSuccess();
        log.info(proto.toString(channelId) + " wave file successfully put to s3");
        chunks.forEach(CheckpointingAudioChunk::checkpoint);
        break;/*from   w  ww . j  a  va  2s . c  o  m*/

    case TRANSFER_CANCELED_EVENT:
    case TRANSFER_FAILED_EVENT:
    case TRANSFER_PART_FAILED_EVENT:
        ImbeefMetrics.getInstance().wavPutFailure();
        log.error(proto.toString(channelId) + " error sending wave file " + event.toString());
        break;
    }
}