Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
f727b25
Move BatchOptions into models package.
conniey Jul 23, 2019
6a6e38f
Move tests into their respective folders.
conniey Jul 23, 2019
f0553dc
Add RetryOptions and RetryMode.
conniey Jul 23, 2019
88237af
Add test for RetryOptions.
conniey Jul 24, 2019
2917b48
Rename Retry -> RetryPolicy
conniey Jul 25, 2019
7017142
Update names for RetryOptions.
conniey Jul 25, 2019
b77deaf
Update RetryPolicy and ExponentialRetryPolicy to use new interface.
conniey Jul 25, 2019
5209b38
Add test cases for equality. And fixing ExponentialRetryPolicy tests.
conniey Jul 25, 2019
5579ef3
Fixing documentation error.
conniey Jul 25, 2019
3e40f85
Fix SpotBugs issue.
conniey Jul 25, 2019
1c61e79
Add @inheritDocs
conniey Jul 26, 2019
efe958b
Updating RetryPolicy, adding FixedRetry and ExponentialRetry.
conniey Jul 26, 2019
a605954
Adding documentation to RetryPolicy.
conniey Jul 26, 2019
c983b51
Fix test cases for ExponentialRetryPolicy
conniey Jul 27, 2019
5b879b3
Adding documentation for RetryPolicy.
conniey Jul 27, 2019
045b61c
Add final
conniey Jul 27, 2019
9a136ab
Remove RemainingTime from RetryPolicy. Only works in Send, but not ge…
conniey Jul 29, 2019
c4bad4c
Adding tests for FixedRetryPolicy.
conniey Jul 30, 2019
9d6e66e
Add RetryOptionsUtil and TimeoutHandler.
conniey Jul 30, 2019
7894261
Update tests to use RetryOptions and RetryUtil for retry with timeouts.
conniey Jul 30, 2019
8614786
Fixing test.
conniey Jul 30, 2019
48828a2
Remove unneeded logging.
conniey Jul 30, 2019
b56d79e
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-java …
conniey Jul 30, 2019
4a4b368
Fix import.
conniey Jul 30, 2019
6a54a8c
Fixing imports
conniey Jul 30, 2019
119adeb
Fixing tests.
conniey Jul 31, 2019
96127d4
Removing Cloneable interface and replacing with concrete implementation.
conniey Jul 31, 2019
64f3fab
If Retry is longer than maximum duration, return that.
conniey Jul 31, 2019
d1a1db2
Replacing Cloneable interface.
conniey Jul 31, 2019
5f69a00
Naming changes.
conniey Jul 31, 2019
cf1b86c
Add test case for RetryOptionsTest
conniey Jul 31, 2019
f3d6b66
Fixing warnings.
conniey Jul 31, 2019
b3871f5
Adding RetryUtilTests.
conniey Jul 31, 2019
87bb014
Move into core package.
conniey Aug 1, 2019
6757e0b
Using parallel scheduler. Remove redundant casts.
conniey Aug 1, 2019
05b8ee8
Fix checkstyle error.
conniey Aug 1, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ public interface AmqpSession extends EndpointStateNotifier, Closeable {
* @param linkName Name of the link.
* @param entityPath The entity path this link connects to when producing events.
* @param timeout Timeout required for creating and opening AMQP link.
* @param retry The retry policy to use when sending messages.
* @param retryPolicy The retry policy to use when sending messages.
* @return A newly created AMQP link.
*/
Mono<AmqpLink> createProducer(String linkName, String entityPath, Duration timeout, Retry retry);
Mono<AmqpLink> createProducer(String linkName, String entityPath, Duration timeout, RetryPolicy retryPolicy);

/**
* Creates a new AMQP link that consumes events from the message broker.
*
* @param linkName Name of the link.
* @param entityPath The entity path this link connects to, so that it may read events from the message broker.
* @param timeout Timeout required for creating and opening an AMQP link.
* @param retry The retry policy to use when consuming messages.
* @param retryPolicy The retry policy to use when consuming messages.
* @return A newly created AMQP link.
*/
Mono<AmqpLink> createConsumer(String linkName, String entityPath, Duration timeout, Retry retry);
Mono<AmqpLink> createConsumer(String linkName, String entityPath, Duration timeout, RetryPolicy retryPolicy);

/**
* Removes an {@link AmqpLink} with the given {@code linkName}.
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.amqp;

import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;

/**
* A policy to govern retrying of messaging operations in which the delay between retries will grow in an exponential
* manner, allowing more time to recover as the number of retries increases.
*/
public final class ExponentialRetryPolicy extends RetryPolicy {
private final double retryFactor;

/**
* Creates a new instance with a minimum and maximum retry period in addition to maximum number of retry attempts.
*
* @param retryOptions The options to apply to this retry policy.
* @throws NullPointerException if {@code retryOptions} is {@code null}.
*/
public ExponentialRetryPolicy(RetryOptions retryOptions) {
super(retryOptions);

this.retryFactor = computeRetryFactor();
}

/**
* Calculates the retry delay using exponential backoff.
*
* @param retryCount The number of attempts that have been made, including the initial attempt before any
* retries.
* @param baseDelay The delay to use for the basis of the exponential backoff.
* @param baseJitter The duration to use for the basis of the random jitter value.
* @param random The random number generator used to calculate the jitter.
* @return The duration to delay before retrying a request.
*/
@Override
protected Duration calculateRetryDelay(int retryCount, Duration baseDelay, Duration baseJitter,
ThreadLocalRandom random) {
final double jitterSeconds = random.nextDouble() * baseJitter.getSeconds();
final double nextRetrySeconds = Math.pow(retryFactor, (double) retryCount);
final Double nextRetryNanos = (jitterSeconds + nextRetrySeconds) * NANOS_PER_SECOND;

return baseDelay.plus(Duration.ofNanos(nextRetryNanos.longValue()));
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return super.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

return obj instanceof ExponentialRetryPolicy
&& super.equals(obj);
}

/**
* Creates a clone of this instance.
*
* @return A clone of the {@link ExponentialRetryPolicy} instance.
*/
@Override
public RetryPolicy clone() {
final RetryOptions cloned = getRetryOptions().clone();
return new ExponentialRetryPolicy(cloned);
}

private double computeRetryFactor() {
final RetryOptions options = getRetryOptions();
final Duration maxBackoff = options.maxDelay();
final Duration minBackoff = options.delay();
final int maximumRetries = options.maxRetries();
final long deltaBackoff = maxBackoff.minus(minBackoff).getSeconds();

if (deltaBackoff <= 0 || maximumRetries <= 0) {
return 0;
}

return Math.log(deltaBackoff) / Math.log(maximumRetries);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.amqp;

import java.time.Duration;
import java.util.concurrent.ThreadLocalRandom;

/**
* A policy to govern retrying of messaging operations in which the base delay between retries remains the same.
*/
public final class FixedRetryPolicy extends RetryPolicy {
/**
* Creates an instance with the given retry options.
*
* @param retryOptions The options to set on this retry policy.
*/
public FixedRetryPolicy(RetryOptions retryOptions) {
super(retryOptions);
}

/**
* Calculates the delay for a fixed backoff.
*
* @param retryCount The number of attempts that have been made, including the initial attempt before any
* retries.
* @param baseDelay The delay to use for the fixed backoff.
* @param baseJitter The duration to use for the basis of the random jitter value.
* @param random The random number generator used to calculate the jitter.
* @return The duration to delay before retrying a request.
*/
@Override
protected Duration calculateRetryDelay(int retryCount, Duration baseDelay, Duration baseJitter, ThreadLocalRandom random) {
final Double jitterNanos = random.nextDouble() * baseJitter.getSeconds() * RetryPolicy.NANOS_PER_SECOND;
final Duration jitter = Duration.ofNanos(jitterNanos.longValue());

return baseDelay.plus(jitter);
}

/**
* {@inheritDoc}
*/
@Override
public int hashCode() {
return super.hashCode();
}

/**
* {@inheritDoc}
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}

return obj instanceof FixedRetryPolicy
&& super.equals(obj);
}

/**
* Creates a clone of this instance.
*
* @return A clone of the {@link FixedRetryPolicy} instance.
*/
@Override
public RetryPolicy clone() {
final RetryOptions cloned = getRetryOptions().clone();
return new FixedRetryPolicy(cloned);
}
}
Loading