forked from iluwatar/java-design-patterns
-
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.
feature: Rate Limiting pattern (iluwatar#2973)
java: java.lang.NoSuchFieldError: Class com.sun.tools.javac.tree.JCTree$JCImport does not have member field 'com.sun.tools.javac.tree.JCTree qualid'
- Loading branch information
Каспшицкий Алексей
committed
Jul 5, 2024
1 parent
00b4aac
commit 2bf43db
Showing
10 changed files
with
206 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
@startuml | ||
package com.iluwatar.controller { | ||
class RateLimitedController { | ||
+ RateLimitedController() | ||
+ getRequest() : DtoClass | ||
} | ||
} | ||
package com.iluwatar.aspect { | ||
interface RateLimited { | ||
+ count() : int {abstract} | ||
+ timeUnit() : TimeUnit {abstract} | ||
} | ||
class RateLimiterAspect { | ||
- LOGGER : Logger {static} | ||
+ RateLimiterAspect() | ||
+ callMethodWithAnnotation() | ||
+ endpointAfterReturning(jp : JoinPoint, returningValue : Object) : Object | ||
+ endpointAfterThrowing(jp : JoinPoint, e : Exception) | ||
+ endpointBeforeInvoke(jp : JoinPoint) | ||
} | ||
} | ||
package com.iluwatar.pattern { | ||
class RateLimiter { | ||
+ RateLimiter() | ||
} | ||
} | ||
package com.iluwatar.model { | ||
class DtoClass { | ||
- id : Long | ||
- name : String | ||
+ DtoClass() | ||
# canEqual(other : Object) : boolean | ||
+ equals(o : Object) : boolean | ||
+ getId() : Long | ||
+ getName() : String | ||
+ hashCode() : int | ||
+ setId(id : Long) | ||
+ setName(name : String) | ||
+ toString() : String | ||
} | ||
} | ||
package com.iluwatar { | ||
class App { | ||
- LOGGER : Logger {static} | ||
+ App() | ||
+ main(args : String[]) {static} | ||
} | ||
} | ||
@enduml |
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
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
34 changes: 31 additions & 3 deletions
34
rate-limiting/src/main/java/com/iluwatar/aspect/RateLimited.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 |
---|---|---|
@@ -1,17 +1,45 @@ | ||
/* | ||
* This project is licensed under the MIT license. Module model-view-viewmodel is using ZK framework licensed under LGPL (see lgpl-3.0.txt). | ||
* | ||
* The MIT License | ||
* Copyright © 2014-2022 Ilkka Seppälä | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
package com.iluwatar.aspect; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* AOP annotation. | ||
* Annotation for rate limiting method invocations. | ||
*/ | ||
public @interface RateLimited { | ||
|
||
/** | ||
* invoke method vialotation for one ip address. | ||
* Specifies the maximum allowed invocations within the rate limiting window. | ||
* Default value is 10. | ||
*/ | ||
int count() default 10; | ||
|
||
/** | ||
* time unit for reset vialotation. | ||
* Specifies the unit of time for the rate limiting window. | ||
* Default time unit is seconds. | ||
*/ | ||
TimeUnit timeUnit() default TimeUnit.SECONDS; | ||
} |
24 changes: 24 additions & 0 deletions
24
rate-limiting/src/main/java/com/iluwatar/aspect/RateLimiterAspect.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
24 changes: 24 additions & 0 deletions
24
rate-limiting/src/main/java/com/iluwatar/controller/RateLimitedController.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
24 changes: 24 additions & 0 deletions
24
rate-limiting/src/main/java/com/iluwatar/model/DtoClass.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
24 changes: 24 additions & 0 deletions
24
rate-limiting/src/main/java/com/iluwatar/pattern/RateLimiter.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
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 @@ | ||
server.port=8081 |
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