This repository has been archived by the owner on Oct 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Using RateLimiter from Guava to avoid triggering GitHub abuse detecti…
…on mechanism
- Loading branch information
Benoit GUERIN
committed
May 23, 2015
1 parent
b40a589
commit a202931
Showing
3 changed files
with
68 additions
and
9 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
52 changes: 52 additions & 0 deletions
52
github-core/src/main/java/com/github/maven/plugins/core/RateLimitedGitHubClient.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,52 @@ | ||
package com.github.maven.plugins.core; | ||
|
||
import com.github.maven.plugins.core.egit.GitHubClientEgit; | ||
import com.google.common.util.concurrent.RateLimiter; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
|
||
public class RateLimitedGitHubClient extends GitHubClientEgit { | ||
|
||
/** | ||
* AS per https://github.com/octokit/octokit.net/issues/638#issuecomment-67795998, | ||
* it seems that GitHub only allow 20 API calls per 1-minute period | ||
*/ | ||
private RateLimiter rateLimiter = RateLimiter.create(20.0/60.0); | ||
|
||
public RateLimitedGitHubClient() { | ||
super(); | ||
} | ||
|
||
public RateLimitedGitHubClient(String hostname) { | ||
super(hostname); | ||
} | ||
|
||
public RateLimitedGitHubClient(String hostname, int port, String scheme) { | ||
super(hostname, port, scheme); | ||
} | ||
|
||
@Override | ||
protected HttpURLConnection createDelete(String uri) throws IOException { | ||
//rateLimiter.acquire(); | ||
return super.createDelete(uri); | ||
} | ||
|
||
@Override | ||
protected HttpURLConnection createGet(String uri) throws IOException { | ||
//rateLimiter.acquire(); | ||
return super.createGet(uri); | ||
} | ||
|
||
@Override | ||
protected HttpURLConnection createPost(String uri) throws IOException { | ||
rateLimiter.acquire(); | ||
return super.createPost(uri); | ||
} | ||
|
||
@Override | ||
protected HttpURLConnection createPut(String uri) throws IOException { | ||
rateLimiter.acquire(); | ||
return super.createPut(uri); | ||
} | ||
} |
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
a202931
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why your code style sometimes c sometimes java is to
Much like me
a202931
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh,this is a pair of nice code!