forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Azure#34 from rpaquay/dev
Looks good
- Loading branch information
Showing
81 changed files
with
7,733 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.classpath | ||
.project | ||
.settings | ||
target | ||
node_modules |
288 changes: 288 additions & 0 deletions
288
microsoft-azure-api/.settings/org.eclipse.jdt.core.prefs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
#Thu Nov 10 13:35:31 PST 2011 | ||
cleanup.add_default_serial_version_id=true | ||
cleanup.add_generated_serial_version_id=false | ||
cleanup.add_missing_annotations=true | ||
cleanup.add_missing_deprecated_annotations=true | ||
cleanup.add_missing_methods=false | ||
cleanup.add_missing_nls_tags=false | ||
cleanup.add_missing_override_annotations=true | ||
cleanup.add_missing_override_annotations_interface_methods=true | ||
cleanup.add_serial_version_id=false | ||
cleanup.always_use_blocks=true | ||
cleanup.always_use_parentheses_in_expressions=false | ||
cleanup.always_use_this_for_non_static_field_access=false | ||
cleanup.always_use_this_for_non_static_method_access=false | ||
cleanup.convert_to_enhanced_for_loop=false | ||
cleanup.correct_indentation=false | ||
cleanup.format_source_code=false | ||
cleanup.format_source_code_changes_only=false | ||
cleanup.make_local_variable_final=true | ||
cleanup.make_parameters_final=false | ||
cleanup.make_private_fields_final=true | ||
cleanup.make_type_abstract_if_missing_method=false | ||
cleanup.make_variable_declarations_final=false | ||
cleanup.never_use_blocks=false | ||
cleanup.never_use_parentheses_in_expressions=true | ||
cleanup.organize_imports=false | ||
cleanup.qualify_static_field_accesses_with_declaring_class=false | ||
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true | ||
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true | ||
cleanup.qualify_static_member_accesses_with_declaring_class=true | ||
cleanup.qualify_static_method_accesses_with_declaring_class=false | ||
cleanup.remove_private_constructors=true | ||
cleanup.remove_trailing_whitespaces=false | ||
cleanup.remove_trailing_whitespaces_all=true | ||
cleanup.remove_trailing_whitespaces_ignore_empty=false | ||
cleanup.remove_unnecessary_casts=true | ||
cleanup.remove_unnecessary_nls_tags=true | ||
cleanup.remove_unused_imports=true | ||
cleanup.remove_unused_local_variables=false | ||
cleanup.remove_unused_private_fields=true | ||
cleanup.remove_unused_private_members=false | ||
cleanup.remove_unused_private_methods=true | ||
cleanup.remove_unused_private_types=true | ||
cleanup.sort_members=false | ||
cleanup.sort_members_all=false | ||
cleanup.use_blocks=false | ||
cleanup.use_blocks_only_for_return_and_throw=false | ||
cleanup.use_parentheses_in_expressions=false | ||
cleanup.use_this_for_non_static_field_access=false | ||
cleanup.use_this_for_non_static_field_access_only_if_necessary=true | ||
cleanup.use_this_for_non_static_method_access=false | ||
cleanup.use_this_for_non_static_method_access_only_if_necessary=true | ||
cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile | ||
cleanup_settings_version=2 | ||
eclipse.preferences.version=1 | ||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true | ||
formatter_profile=_OneSDK profile | ||
formatter_settings_version=12 | ||
org.eclipse.jdt.ui.exception.name=e | ||
org.eclipse.jdt.ui.gettersetter.use.is=true | ||
org.eclipse.jdt.ui.keywordthis=false | ||
org.eclipse.jdt.ui.overrideannotation=true | ||
sp_cleanup.add_default_serial_version_id=true | ||
sp_cleanup.add_generated_serial_version_id=false | ||
sp_cleanup.add_missing_annotations=true | ||
sp_cleanup.add_missing_deprecated_annotations=true | ||
sp_cleanup.add_missing_methods=false | ||
sp_cleanup.add_missing_nls_tags=false | ||
sp_cleanup.add_missing_override_annotations=true | ||
sp_cleanup.add_missing_override_annotations_interface_methods=true | ||
sp_cleanup.add_serial_version_id=false | ||
sp_cleanup.always_use_blocks=true | ||
sp_cleanup.always_use_parentheses_in_expressions=false | ||
sp_cleanup.always_use_this_for_non_static_field_access=false | ||
sp_cleanup.always_use_this_for_non_static_method_access=false | ||
sp_cleanup.convert_to_enhanced_for_loop=false | ||
sp_cleanup.correct_indentation=true | ||
sp_cleanup.format_source_code=true | ||
sp_cleanup.format_source_code_changes_only=false | ||
sp_cleanup.make_local_variable_final=false | ||
sp_cleanup.make_parameters_final=false | ||
sp_cleanup.make_private_fields_final=true | ||
sp_cleanup.make_type_abstract_if_missing_method=false | ||
sp_cleanup.make_variable_declarations_final=true | ||
sp_cleanup.never_use_blocks=false | ||
sp_cleanup.never_use_parentheses_in_expressions=true | ||
sp_cleanup.on_save_use_additional_actions=true | ||
sp_cleanup.organize_imports=true | ||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false | ||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true | ||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true | ||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false | ||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false | ||
sp_cleanup.remove_private_constructors=true | ||
sp_cleanup.remove_trailing_whitespaces=true | ||
sp_cleanup.remove_trailing_whitespaces_all=true | ||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false | ||
sp_cleanup.remove_unnecessary_casts=true | ||
sp_cleanup.remove_unnecessary_nls_tags=false | ||
sp_cleanup.remove_unused_imports=true | ||
sp_cleanup.remove_unused_local_variables=false | ||
sp_cleanup.remove_unused_private_fields=true | ||
sp_cleanup.remove_unused_private_members=false | ||
sp_cleanup.remove_unused_private_methods=true | ||
sp_cleanup.remove_unused_private_types=true | ||
sp_cleanup.sort_members=false | ||
sp_cleanup.sort_members_all=false | ||
sp_cleanup.use_blocks=false | ||
sp_cleanup.use_blocks_only_for_return_and_throw=false | ||
sp_cleanup.use_parentheses_in_expressions=false | ||
sp_cleanup.use_this_for_non_static_field_access=false | ||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true | ||
sp_cleanup.use_this_for_non_static_method_access=false | ||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#Tue Oct 18 09:29:27 PDT 2011 | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
94 changes: 94 additions & 0 deletions
94
...soft-azure-api/src/main/java/com/microsoft/azure/common/ExponentialRetryPolicyFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package com.microsoft.azure.common; | ||
|
||
import java.util.Arrays; | ||
import java.util.Random; | ||
|
||
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
|
||
import com.microsoft.azure.http.ServiceFilter; | ||
|
||
public class ExponentialRetryPolicyFilter implements ServiceFilter { | ||
private static final Log log = LogFactory.getLog(ExponentialRetryPolicyFilter.class); | ||
|
||
public static final int DEFAULT_CLIENT_BACKOFF = 1000 * 30; | ||
public static final int DEFAULT_CLIENT_RETRY_COUNT = 3; | ||
public static final int DEFAULT_MAX_BACKOFF = 1000 * 90; | ||
public static final int DEFAULT_MIN_BACKOFF = 1000 * 3; | ||
|
||
private final int deltaBackoffIntervalInMs; | ||
private final int maximumAttempts; | ||
private final Random randRef = new Random(); | ||
private final int resolvedMaxBackoff = DEFAULT_MAX_BACKOFF; | ||
private final int resolvedMinBackoff = DEFAULT_MIN_BACKOFF; | ||
private final int[] retryableStatusCodes; | ||
|
||
public ExponentialRetryPolicyFilter(int[] retryableStatusCodes) { | ||
this(DEFAULT_CLIENT_BACKOFF, DEFAULT_CLIENT_RETRY_COUNT, retryableStatusCodes); | ||
} | ||
|
||
public ExponentialRetryPolicyFilter(int deltaBackoff, int maximumAttempts, int[] retryableStatusCodes) { | ||
this.deltaBackoffIntervalInMs = deltaBackoff; | ||
this.maximumAttempts = maximumAttempts; | ||
this.retryableStatusCodes = Arrays.copyOf(retryableStatusCodes, retryableStatusCodes.length); | ||
Arrays.sort(this.retryableStatusCodes); | ||
} | ||
|
||
public Response handle(Request request, Next next) { | ||
// Only the last added retry policy should be active | ||
if (request.getProperties().containsKey("RetryPolicy")) | ||
return next.handle(request); | ||
request.getProperties().put("RetryPolicy", this); | ||
|
||
// Retry the operation up to "getMaximumAttempts" | ||
for (int retryCount = 0;; ++retryCount) { | ||
Response response = next.handle(request); | ||
|
||
boolean shouldRetry = shouldRetry(retryCount, response); | ||
if (!shouldRetry) | ||
return response; | ||
|
||
int backoffTime = calculateBackoff(retryCount); | ||
log.info(String.format("Request failed. Backing off for %1s milliseconds before retrying (retryCount=%2d)", backoffTime, retryCount)); | ||
backoff(backoffTime); | ||
} | ||
} | ||
|
||
private void backoff(int milliseconds) { | ||
try { | ||
Thread.sleep(milliseconds); | ||
} | ||
catch (InterruptedException e) { | ||
// Restore the interrupted status | ||
Thread.currentThread().interrupt(); | ||
} | ||
} | ||
|
||
private int calculateBackoff(int currentRetryCount) { | ||
// Calculate backoff Interval between 80% and 120% of the desired | ||
// backoff, multiply by 2^n -1 for | ||
// exponential | ||
int incrementDelta = (int) (Math.pow(2, currentRetryCount) - 1); | ||
int boundedRandDelta = (int) (this.deltaBackoffIntervalInMs * 0.8) | ||
+ this.randRef.nextInt((int) (this.deltaBackoffIntervalInMs * 1.2) - (int) (this.deltaBackoffIntervalInMs * 0.8)); | ||
incrementDelta *= boundedRandDelta; | ||
|
||
// Enforce max / min backoffs | ||
return Math.min(this.resolvedMinBackoff + incrementDelta, this.resolvedMaxBackoff); | ||
} | ||
|
||
private boolean shouldRetry(int retryCount, Response response) { | ||
if (retryCount >= getMaximumAttempts()) | ||
return false; | ||
|
||
// Don't retry if not retryable status code | ||
if (Arrays.binarySearch(this.retryableStatusCodes, response.getStatus()) < 0) | ||
return false; | ||
|
||
return true; | ||
} | ||
|
||
private int getMaximumAttempts() { | ||
return this.maximumAttempts; | ||
} | ||
} |
116 changes: 116 additions & 0 deletions
116
microsoft-azure-api/src/main/java/com/microsoft/azure/http/ClientFilterAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package com.microsoft.azure.http; | ||
|
||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
|
||
import com.microsoft.azure.http.ServiceFilter.Request; | ||
import com.microsoft.azure.http.ServiceFilter.Response; | ||
import com.sun.jersey.api.client.ClientHandlerException; | ||
import com.sun.jersey.api.client.ClientRequest; | ||
import com.sun.jersey.api.client.ClientResponse; | ||
import com.sun.jersey.api.client.filter.ClientFilter; | ||
|
||
public class ClientFilterAdapter extends ClientFilter { | ||
ServiceFilter filter; | ||
|
||
public ClientFilterAdapter(ServiceFilter filter) { | ||
this.filter = filter; | ||
} | ||
|
||
@Override | ||
public ClientResponse handle(ClientRequest clientRequest) throws ClientHandlerException { | ||
|
||
final ClientRequest cr = clientRequest; | ||
Response resp = filter.handle(new ServiceFilterRequest(clientRequest), new ServiceFilter.Next() { | ||
public Response handle(Request request) { | ||
return new ServiceFilterResponse(getNext().handle(cr)); | ||
} | ||
}); | ||
|
||
return ((ServiceFilterResponse) resp).clientResponse; | ||
} | ||
} | ||
|
||
class ServiceFilterRequest implements ServiceFilter.Request { | ||
ClientRequest clientRequest; | ||
|
||
public ServiceFilterRequest(ClientRequest clientRequest) { | ||
this.clientRequest = clientRequest; | ||
} | ||
|
||
public Map<String, Object> getProperties() { | ||
return clientRequest.getProperties(); | ||
} | ||
|
||
public void setProperties(Map<String, Object> properties) { | ||
clientRequest.setProperties(properties); | ||
} | ||
|
||
public URI getURI() { | ||
return clientRequest.getURI(); | ||
} | ||
|
||
public void setURI(URI uri) { | ||
clientRequest.setURI(uri); | ||
} | ||
|
||
public String getMethod() { | ||
return clientRequest.getMethod(); | ||
} | ||
|
||
public void setMethod(String method) { | ||
clientRequest.setMethod(method); | ||
} | ||
|
||
public Object getEntity() { | ||
return clientRequest.getEntity(); | ||
} | ||
|
||
public void setEntity(Object entity) { | ||
clientRequest.setEntity(entity); | ||
} | ||
|
||
public MultivaluedMap<String, Object> getHeaders() { | ||
return clientRequest.getHeaders(); | ||
} | ||
|
||
} | ||
|
||
class ServiceFilterResponse implements ServiceFilter.Response { | ||
ClientResponse clientResponse; | ||
|
||
public ServiceFilterResponse(ClientResponse clientResponse) { | ||
this.clientResponse = clientResponse; | ||
} | ||
|
||
public Map<String, Object> getProperties() { | ||
return clientResponse.getProperties(); | ||
} | ||
|
||
public int getStatus() { | ||
return clientResponse.getStatus(); | ||
} | ||
|
||
public void setStatus(int status) { | ||
clientResponse.setStatus(status); | ||
} | ||
|
||
public MultivaluedMap<String, String> getHeaders() { | ||
return clientResponse.getHeaders(); | ||
} | ||
|
||
public boolean hasEntity() { | ||
return clientResponse.hasEntity(); | ||
} | ||
|
||
public InputStream getEntityInputStream() { | ||
return clientResponse.getEntityInputStream(); | ||
} | ||
|
||
public void setEntityInputStream(InputStream entity) { | ||
clientResponse.setEntityInputStream(entity); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
microsoft-azure-api/src/main/java/com/microsoft/azure/http/ServiceFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.microsoft.azure.http; | ||
|
||
import java.io.InputStream; | ||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import javax.ws.rs.core.MultivaluedMap; | ||
|
||
|
||
public interface ServiceFilter { | ||
Response handle(Request request, Next next); | ||
|
||
public interface Next { | ||
Response handle(Request request); | ||
} | ||
|
||
public interface Request { | ||
public String getMethod(); | ||
public void setMethod(String method); | ||
|
||
public URI getURI(); | ||
public void setURI(URI uri); | ||
|
||
public MultivaluedMap<String, Object> getHeaders(); | ||
|
||
public Object getEntity(); | ||
public void setEntity(Object entity); | ||
|
||
public Map<String, Object> getProperties(); | ||
public void setProperties(Map<String, Object> properties); | ||
} | ||
|
||
public interface Response { | ||
int getStatus(); | ||
void setStatus(int status); | ||
|
||
MultivaluedMap<String, String> getHeaders(); | ||
|
||
boolean hasEntity(); | ||
|
||
InputStream getEntityInputStream(); | ||
void setEntityInputStream(InputStream entity); | ||
|
||
Map<String, Object> getProperties(); | ||
} | ||
} |
Oops, something went wrong.