Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
GLIS Client
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Genesys PGR
GLIS Client
Commits
b1840bef
Commit
b1840bef
authored
Oct 26, 2017
by
Matija Obreza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GLIS Rate Limiter aspect (fixes
#29
)
parent
556351b0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
common/pom.xml
common/pom.xml
+11
-1
common/src/main/java/org/genesys/glis/v1/GlisRateLimiter.java
...on/src/main/java/org/genesys/glis/v1/GlisRateLimiter.java
+35
-0
No files found.
common/pom.xml
View file @
b1840bef
...
...
@@ -16,6 +16,12 @@
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-aspects
</artifactId>
<version>
4.3.2.RELEASE
</version>
<scope>
provided
</scope>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>
junit
</groupId>
...
...
@@ -35,7 +41,6 @@
<groupId>
org.slf4j
</groupId>
<artifactId>
slf4j-api
</artifactId>
<version>
${org.slf4j.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.slf4j
</groupId>
...
...
@@ -49,6 +54,11 @@
<version>
${org.slf4j.version}
</version>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
com.google.guava
</groupId>
<artifactId>
guava
</artifactId>
<version>
23.2-jre
</version>
</dependency>
</dependencies>
<build>
...
...
common/src/main/java/org/genesys/glis/v1/GlisRateLimiter.java
0 → 100644
View file @
b1840bef
package
org.genesys.glis.v1
;
import
com.google.common.util.concurrent.RateLimiter
;
import
org.aspectj.lang.JoinPoint
;
import
org.aspectj.lang.annotation.Aspect
;
import
org.aspectj.lang.annotation.Before
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
/**
* Aspect to control the rate of calls to GLIS API
*/
@Aspect
public
class
GlisRateLimiter
{
private
static
final
Logger
LOG
=
LoggerFactory
.
getLogger
(
GlisRateLimiter
.
class
);
private
RateLimiter
limiter
=
RateLimiter
.
create
(
20
);
public
GlisRateLimiter
(
double
permitsPerSecond
)
{
setPermitsPerSecond
(
permitsPerSecond
);
}
public
void
setPermitsPerSecond
(
double
permitsPerSecond
)
{
limiter
=
RateLimiter
.
create
(
permitsPerSecond
);
}
@Before
(
"execution(* org.genesys.glis.v1.api.*.*(..))"
)
public
void
rateLimit
(
JoinPoint
jp
)
{
double
delay
=
limiter
.
acquire
();
LOG
.
debug
(
"Acquired rate limit permission ({} qps) in {} seconds for {}"
,
limiter
.
getRate
(),
delay
,
jp
.
toLongString
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment