-
Notifications
You must be signed in to change notification settings - Fork 21
feat(java): retry strategy APIC-261 #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
103 changes: 0 additions & 103 deletions
103
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/ApiException.java
This file was deleted.
Oops, something went wrong.
30 changes: 30 additions & 0 deletions
30
...iasearch-client-java-2/algoliasearch-core/com/algolia/exceptions/AlgoliaApiException.java
This file contains hidden or 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,30 @@ | ||
package com.algolia.exceptions; | ||
|
||
/** Exception thrown in case of API failure such as 4XX, 5XX error. */ | ||
public class AlgoliaApiException extends AlgoliaRuntimeException { | ||
|
||
public int getHttpErrorCode() { | ||
return httpErrorCode; | ||
} | ||
|
||
private final int httpErrorCode; | ||
|
||
public AlgoliaApiException( | ||
String message, | ||
Throwable cause, | ||
int httpErrorCode | ||
) { | ||
super(message, cause); | ||
this.httpErrorCode = httpErrorCode; | ||
} | ||
|
||
public AlgoliaApiException(String message, int httpErrorCode) { | ||
super(message); | ||
this.httpErrorCode = httpErrorCode; | ||
} | ||
|
||
public AlgoliaApiException(Throwable cause, int httpErrorCode) { | ||
super(cause); | ||
this.httpErrorCode = httpErrorCode; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
...search-client-java-2/algoliasearch-core/com/algolia/exceptions/AlgoliaRetryException.java
This file contains hidden or 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,20 @@ | ||
package com.algolia.exceptions; | ||
|
||
/** | ||
* Exception thrown when an error occurs during the retry strategy. For example: All hosts are | ||
* unreachable. | ||
*/ | ||
public class AlgoliaRetryException extends AlgoliaRuntimeException { | ||
|
||
public AlgoliaRetryException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public AlgoliaRetryException(String message) { | ||
super(message); | ||
} | ||
|
||
public AlgoliaRetryException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...arch-client-java-2/algoliasearch-core/com/algolia/exceptions/AlgoliaRuntimeException.java
This file contains hidden or 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,17 @@ | ||
package com.algolia.exceptions; | ||
|
||
/** Exception thrown when an error occurs during the Serialization/Deserialization process */ | ||
public class AlgoliaRuntimeException extends RuntimeException { | ||
|
||
public AlgoliaRuntimeException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
public AlgoliaRuntimeException(String message) { | ||
super(message); | ||
} | ||
|
||
public AlgoliaRuntimeException(Throwable cause) { | ||
super(cause); | ||
} | ||
} |
This file contains hidden or 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
3 changes: 1 addition & 2 deletions
3
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/Requester.java
This file contains hidden or 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
21 changes: 21 additions & 0 deletions
21
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/Utils.java
This file contains hidden or 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,21 @@ | ||
package com.algolia.utils; | ||
|
||
import java.time.Clock; | ||
import java.time.Instant; | ||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.zone.ZoneRules; | ||
|
||
public class Utils { | ||
|
||
private static final ZoneRules ZONE_RULES_UTC = ZoneOffset.UTC.getRules(); | ||
|
||
/** | ||
* Memory optimization for getZoneRules with the same ZoneOffset (UTC). ZoneRules is immutable and | ||
* threadsafe, but getRules method consumes a lot of memory during load testing. | ||
*/ | ||
public static OffsetDateTime nowUTC() { | ||
final Instant now = Clock.system(ZoneOffset.UTC).instant(); | ||
return OffsetDateTime.ofInstant(now, ZONE_RULES_UTC.getOffset(now)); | ||
} | ||
} |
30 changes: 21 additions & 9 deletions
30
.../algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/echo/EchoRequester.java
This file contains hidden or 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,34 +1,46 @@ | ||
package com.algolia.utils.echo; | ||
|
||
import com.algolia.ApiException; | ||
import com.algolia.utils.Requester; | ||
import okhttp3.Request; | ||
|
||
public class EchoRequester implements Requester { | ||
|
||
public CallEcho newCall(Request request) throws ApiException { | ||
private int connectionTimeout, readTimeout, writeTimeout; | ||
|
||
public EchoRequester() { | ||
this.connectionTimeout = 100; | ||
this.readTimeout = 100; | ||
this.writeTimeout = 100; | ||
} | ||
|
||
public CallEcho newCall(Request request) { | ||
return new CallEcho(request); | ||
} | ||
|
||
// NO-OP for now | ||
|
||
public void setDebugging(boolean debugging) {} | ||
|
||
public int getConnectTimeout() { | ||
return 100; | ||
return this.connectionTimeout; | ||
} | ||
|
||
public void setConnectTimeout(int connectionTimeout) {} | ||
public void setConnectTimeout(int connectionTimeout) { | ||
this.connectionTimeout = connectionTimeout; | ||
} | ||
|
||
public int getReadTimeout() { | ||
return 100; | ||
return this.readTimeout; | ||
} | ||
|
||
public void setReadTimeout(int readTimeout) {} | ||
public void setReadTimeout(int readTimeout) { | ||
this.readTimeout = readTimeout; | ||
} | ||
|
||
public int getWriteTimeout() { | ||
return 100; | ||
return this.writeTimeout; | ||
} | ||
|
||
public void setWriteTimeout(int writeTimeout) {} | ||
public void setWriteTimeout(int writeTimeout) { | ||
this.writeTimeout = writeTimeout; | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
clients/algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/retry/CallType.java
This file contains hidden or 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,6 @@ | ||
package com.algolia.utils.retry; | ||
|
||
public enum CallType { | ||
READ, | ||
WRITE, | ||
} |
7 changes: 7 additions & 0 deletions
7
.../algoliasearch-client-java-2/algoliasearch-core/com/algolia/utils/retry/RetryOutcome.java
This file contains hidden or 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,7 @@ | ||
package com.algolia.utils.retry; | ||
|
||
public enum RetryOutcome { | ||
SUCCESS, | ||
RETRY, | ||
FAILURE, | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.