Skip to content

Commit

Permalink
Version 1.6.0 of the AWS Java SDK
Browse files Browse the repository at this point in the history
This release introduces a new type of POJO attribute - S3Link for DynamoDBMapper, and also updates the Amazon CloudFront client with support for customizing error responses.
  • Loading branch information
hanshuo-aws committed Sep 27, 2013
1 parent d26ff1f commit e38176c
Show file tree
Hide file tree
Showing 217 changed files with 11,770 additions and 2,727 deletions.
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AWS SDK for Java
Bundle-SymbolicName: com.amazonaws.sdk;singleton:=true
Bundle-Version: 1.5.8
Bundle-Version: 1.6.0
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>aws-java-sdk</artifactId>
<packaging>jar</packaging>
<name>AWS SDK for Java</name>
<version>1.5.8</version>
<version>1.6.0</version>
<description>The Amazon Web Services SDK for Java provides Java APIs for building software on AWS’ cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).</description>
<url>https://aws.amazon.com/sdkforjava</url>

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/amazonaws/auth/CloudFrontSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public void sign(Request<?> request, AWSCredentials credentials) throws AmazonCl
addSessionCredentials(request, (AWSSessionCredentials) sanitizedCredentials);
}

String date = new DateUtils().formatRfc822Date(new Date());
Date signDate = getSignatureDate(getTimeOffset(request));
String date = new DateUtils().formatRfc822Date(signDate);
request.addHeader("Date", date);
String canonicalString = date;
log.debug("Calculated string to sign:\n\"" + canonicalString + "\"");
Expand Down
6 changes: 6 additions & 0 deletions src/main/java/com/amazonaws/event/ProgressEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
* Notification of a progress change on a transfer. Typically this means notice
* that another chunk of bytes was transferred, but it also signals other types
* of progress events such as a transfer starting, or failing.
* <p>
* This class could be used for both Amazon S3 and Amazon Glacier clients. The
* legacy Amazon S3 progress event
* {@link com.amazonaws.services.s3.model.ProgressEvent} is deprecated in favor
* of this new class.
* </p>
*/
public class ProgressEvent {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,31 @@
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.util;

import com.amazonaws.event.ProgressEvent;
package com.amazonaws.event;

/**
* Listener interface for transfer progress events.
*
* <p>
* This class could be used for both Amazon S3 and Amazon Glacier clients. The
* legacy Amazon S3 progress listener
* {@link com.amazonaws.services.s3.model.ProgressListener} is deprecated in
* favor of this new class.
* </p>
*
* @see ProgressEvent
*/
public interface ProgressListener {

/**
* Called when progress has changed, such as additional bytes transferred,
* transfer failed, etc. Be aware that do *NOT* do any long running
* operations in the call which will ultimately slow down their transfer,
* because in our current SDK the call back is done in the main transfer
* thread.
* transfer failed, etc. The execution of the callback of this listener is managed
* by {@link ProgressListenerCallbackExecutor} class, which maintains a single thread
* to sequentially execute all progressChanged callbacks.
*
* @param progressEvent
* The event describing the progress change.
*
* @see ProgressListenerCallbackExecutor
*/
public void progressChanged(ProgressEvent progressEvent);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.event;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
* This class wraps a ProgressListener object, and manages all its callback
* execution. Callbacks are executed sequentially in a separate single thread.
*/
public class ProgressListenerCallbackExecutor {

/** The wrapped ProgressListener **/
private final ProgressListener listener;

/** A single thread pool for executing ProgressListener callback. **/
private ExecutorService executor;

public ProgressListenerCallbackExecutor(ProgressListener listener) {
this.listener = listener;
}

public void progressChanged(final ProgressEvent progressEvent) {
if (listener == null) return;

synchronized (this) {
if (executor == null) {
executor = Executors.newSingleThreadExecutor();
}
executor.submit(new Runnable() {

@Override
public void run() {
listener.progressChanged(progressEvent);
}
});
}

}

public synchronized void shutDown() {
if (executor != null) {
executor.shutdown();
}
}

/**
* Returns a new ProgressListenerCallbackExecutor instance that wraps the
* specified ProgressListener if it is not null, otherwise directly returns
* null.
*/
public static ProgressListenerCallbackExecutor wrapListener(ProgressListener listener) {
return listener == null ?
null : new ProgressListenerCallbackExecutor(listener);
}
}
61 changes: 61 additions & 0 deletions src/main/java/com/amazonaws/event/ProgressListenerChain.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2010-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
package com.amazonaws.event;

import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
* An implementation of ProgressListener interface that delegates
* progressChanged callback to multiple listeners.
* <p>
* This class could be used for both Amazon S3 and Amazon Glacier clients. The
* legacy Amazon S3 progress listener chain
* {@link com.amazonaws.services.s3.transfer.internal.ProgressListenerChain} is
* deprecated in favor of this new class.
* </p>
*/
public class ProgressListenerChain implements ProgressListener {
private final List<ProgressListener> listeners = new CopyOnWriteArrayList<ProgressListener>();

private static final Log log = LogFactory.getLog(ProgressListenerChain.class);

public ProgressListenerChain(ProgressListener... listeners) {
for (ProgressListener listener : listeners) addProgressListener(listener);
}

public synchronized void addProgressListener(ProgressListener listener) {
if (listener == null) return;
this.listeners.add(listener);
}

public synchronized void removeProgressListener(ProgressListener listener) {
if (listener == null) return;
this.listeners.remove(listener);
}

public void progressChanged(final ProgressEvent progressEvent) {
for ( ProgressListener listener : listeners ) {
try {
listener.progressChanged(progressEvent);
} catch ( RuntimeException e ) {
log.warn("Couldn't update progress listener", e);
}
}
}
}
34 changes: 19 additions & 15 deletions src/main/java/com/amazonaws/event/ProgressReportingInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,23 @@
import java.io.IOException;
import java.io.InputStream;

import com.amazonaws.util.ProgressListener;

/**
* Simple InputStream wrapper that occasionally notifies a progress listener
* about the number of bytes transferred.
* <p>
* This class could be used for both Amazon S3 and Amazon Glacier clients. The
* legacy Amazon Amazon S3 ProgressReportingInputStream
* {@link com.amazonaws.services.s3.internal.ProgressReportingInputStream} is
* deprecated in favor of this new class.
* </p>
*/
public class ProgressReportingInputStream extends FilterInputStream {

/** The threshold of bytes between notifications. */
private static final int NOTIFICATION_THRESHOLD = 8 * 1024;

/** The listener to notify. */
private final ProgressListener listener;
/** The listener callback executor */
private final ProgressListenerCallbackExecutor listenerCallbackExecutor;

/** The number of bytes read that the listener hasn't been notified about yet. */
private int unnotifiedByteCount;
Expand All @@ -40,17 +44,17 @@ public class ProgressReportingInputStream extends FilterInputStream {

/**
* Creates a new progress reporting input stream that simply wraps the
* specified input stream and notifies the specified listener occasionally
* about the number of bytes transferred.
*
* specified input stream and uses the specified listener callback executor to
* asynchronously notify the listener about the number of bytes transferred.
*
* @param in
* The input stream to wrap.
* @param listener
* The listener to notify about progress.
* @param listenerCallbackExecutor
* The listener callback executor that wraps the listener to notify about progress.
*/
public ProgressReportingInputStream(final InputStream in, final ProgressListener listener) {
public ProgressReportingInputStream(final InputStream in, final ProgressListenerCallbackExecutor listenerCallbackExecutor) {
super(in);
this.listener = listener;
this.listenerCallbackExecutor = listenerCallbackExecutor;
}

/**
Expand Down Expand Up @@ -94,7 +98,7 @@ public void reset() throws IOException {
super.reset();
ProgressEvent event = new ProgressEvent(unnotifiedByteCount);
event.setEventCode(ProgressEvent.RESET_EVENT_CODE);
listener.progressChanged(event);
listenerCallbackExecutor.progressChanged(event);
unnotifiedByteCount = 0;
}

Expand All @@ -109,7 +113,7 @@ public int read(byte[] b, int off, int len) throws IOException {
@Override
public void close() throws IOException {
if (unnotifiedByteCount > 0) {
listener.progressChanged(new ProgressEvent(unnotifiedByteCount));
listenerCallbackExecutor.progressChanged(new ProgressEvent(unnotifiedByteCount));
unnotifiedByteCount = 0;
}
super.close();
Expand All @@ -121,13 +125,13 @@ private void notifyCompleted() {
ProgressEvent event = new ProgressEvent(unnotifiedByteCount);
event.setEventCode(ProgressEvent.COMPLETED_EVENT_CODE);
unnotifiedByteCount = 0;
listener.progressChanged(event);
listenerCallbackExecutor.progressChanged(event);
}

private void notify(int bytesRead) {
unnotifiedByteCount += bytesRead;
if (unnotifiedByteCount >= NOTIFICATION_THRESHOLD) {
listener.progressChanged(new ProgressEvent(unnotifiedByteCount));
listenerCallbackExecutor.progressChanged(new ProgressEvent(unnotifiedByteCount));
unnotifiedByteCount = 0;
}
}
Expand Down
Loading

0 comments on commit e38176c

Please sign in to comment.