You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+80-1Lines changed: 80 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -18,7 +18,8 @@ A resource is a unique identifier for a rate-limited entity. It is used to track
18
18
A wrapper class that accepts a resource and applies the rate limit to it. It is used to control the rate limit for accessing a specific resource , by calling the `wait()` method before accessing the resource.
19
19
20
20
## Example
21
-
See more in `DoormanClientTest.kt`
21
+
22
+
#### Basic Usage
22
23
```kotlin
23
24
runBlocking {
24
25
val client =DoormanClient.create("example-client")
@@ -46,4 +47,82 @@ runBlocking {
46
47
47
48
scope.cancelAndJoin() // close the tracker coroutine.
48
49
}
50
+
```
51
+
52
+
#### Where it shines
53
+
```kotlin
54
+
55
+
runBlocking {
56
+
/*
57
+
This assumes that there is a resource as defined below in the doorman server
58
+
- identifier_glob: fair
59
+
capacity: 1000
60
+
safe_capacity: 10
61
+
description: fair share example
62
+
algorithm:
63
+
kind: FAIR_SHARE
64
+
lease_length: 60
65
+
refresh_interval: 5 // keeping this small for testing purposes.
66
+
*/
67
+
val small1Client =DoormanClient.create("small1Client-client")
68
+
val small1Resource = small1Client.requestResource("fair",100.0)
69
+
70
+
val small2Client =DoormanClient.create("small2Client-client")
71
+
val small2Resource = small2Client.requestResource("fair",100.0)
72
+
73
+
val small3Client =DoormanClient.create("small3Client-client")
74
+
val small3Resource = small3Client.requestResource("fair",100.0)
75
+
76
+
val small4Client =DoormanClient.create("small4Client-client")
77
+
val small4Resource = small4Client.requestResource("fair",100.0)
78
+
79
+
val bigClient =DoormanClient.create("bigClient-client")
80
+
val bigResource = bigClient.requestResource("fair",1000.0)
81
+
82
+
delay(5000)
83
+
84
+
val biggerClient =DoormanClient.create("biggerClient-client")
85
+
val biggerResource = biggerClient.requestResource("fair",2000.0)
86
+
87
+
println("Initially...")
88
+
println("New Capacity of small1: ${small1Resource.lease?.capacity}")
89
+
println("New Capacity of small2: ${small2Resource.lease?.capacity}")
90
+
println("New Capacity of small3: ${small3Resource.lease?.capacity}")
91
+
println("New Capacity of small4: ${small4Resource.lease?.capacity}")
92
+
println("New Capacity of big: ${bigResource.lease?.capacity}")
93
+
println("New Capacity of bigger: ${biggerResource.lease?.capacity}")
94
+
95
+
delay(8000)
96
+
97
+
println("After 8 seconds...")
98
+
println("New Capacity of small1: ${small1Resource.lease?.capacity}")
99
+
println("New Capacity of small2: ${small2Resource.lease?.capacity}")
100
+
println("New Capacity of small3: ${small3Resource.lease?.capacity}")
101
+
println("New Capacity of small4: ${small4Resource.lease?.capacity}")
102
+
println("New Capacity of big: ${bigResource.lease?.capacity}")
103
+
println("New Capacity of bigger: ${biggerResource.lease?.capacity}")
0 commit comments