Skip to content

Commit 59d6564

Browse files
all done including tests, just need more tests
1 parent 3fba381 commit 59d6564

14 files changed

+1729
-1515
lines changed

fallback/etc/fallback.urm.puml

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,112 @@
11
@startuml
22
package com.iluwatar {
33
class App {
4-
- MAX_ATTEMPTS : int {static}
5-
- RETRY_DELAY : int {static}
64
- TIMEOUT : int {static}
75
- circuitBreaker : CircuitBreaker
86
- executor : ExecutorService
97
- fallbackService : Service
108
- primaryService : Service
9+
- LOGGER : Logger {static}
1110
+ App()
1211
+ App(primaryService : Service, fallbackService : Service)
1312
+ executeWithFallback() : String
1413
- getFallbackData() : String
1514
+ main(args : String[]) {static}
1615
+ shutdown()
1716
}
17+
18+
interface Service {
19+
+ getData() : String {abstract}
20+
}
21+
1822
interface CircuitBreaker {
1923
+ isOpen() : boolean {abstract}
2024
+ recordFailure() {abstract}
2125
+ recordSuccess() {abstract}
2226
+ reset() {abstract}
2327
}
28+
2429
class DefaultCircuitBreaker {
2530
- RESET_TIMEOUT : long {static}
2631
- failureCount : int
2732
- failureThreshold : int
2833
- lastFailureTime : long
34+
- state : State
2935
+ DefaultCircuitBreaker(failureThreshold : int)
3036
+ isOpen() : boolean
3137
+ recordFailure()
3238
+ recordSuccess()
3339
+ reset()
40+
- enum State
41+
}
42+
43+
class FallbackService {
44+
- MAX_RETRIES : int {static}
45+
- RETRY_DELAY_MS : int {static}
46+
- TIMEOUT_MS : int {static}
47+
- MAX_REQUESTS_PER_MINUTE : int {static}
48+
- LOGGER : Logger {static}
49+
- primaryService : Service
50+
- fallbackService : Service
51+
- circuitBreaker : CircuitBreaker
52+
- executor : ExecutorService
53+
- healthChecker : ScheduledExecutorService
54+
- monitor : ServiceMonitor
55+
- rateLimiter : RateLimiter
56+
- closed : boolean
57+
+ FallbackService(primaryService : Service, fallbackService : Service, circuitBreaker : CircuitBreaker)
58+
+ getData() : String
59+
- executeWithTimeout(task : Callable<String>) : String
60+
- executeFallback() : String
61+
- updateFallbackCache(result : String)
62+
- startHealthChecker()
63+
+ close()
3464
}
65+
3566
class LocalCacheService {
36-
- cache : ConcurrentHashMap<String, String>
67+
- cache : Cache
3768
+ LocalCacheService()
3869
+ getData() : String
3970
+ updateCache(key : String, value : String)
71+
- class Cache
72+
- class CacheEntry
4073
}
74+
4175
class RemoteService {
4276
- HTTP_OK : int {static}
4377
- client : HttpClient
4478
- serviceUrl : String
4579
+ RemoteService(serviceUrl : String)
4680
+ getData() : String
4781
}
48-
interface Service {
49-
+ getData() : String {abstract}
82+
83+
class ServiceMonitor {
84+
- metrics : Queue<ServiceMetric>
85+
+ recordSuccess(responseTime : Duration)
86+
+ recordError()
87+
+ recordFallback()
88+
+ getMetrics() : List<ServiceMetric>
89+
- class ServiceMetric
90+
- enum MetricType
91+
}
92+
93+
class ServiceException {
94+
+ ServiceException(message : String)
5095
}
96+
97+
' Relationships
98+
App --> "-circuitBreaker" CircuitBreaker
99+
App --> "-primaryService" Service
100+
App --> "-fallbackService" Service
101+
DefaultCircuitBreaker ..|> CircuitBreaker
102+
LocalCacheService ..|> Service
103+
RemoteService ..|> Service
104+
FallbackService ..|> Service
105+
FallbackService ..|> AutoCloseable
106+
FallbackService --> "-primaryService" Service
107+
FallbackService --> "-fallbackService" Service
108+
FallbackService --> "-circuitBreaker" CircuitBreaker
109+
FallbackService --> "-monitor" ServiceMonitor
110+
ServiceException --|> Exception
51111
}
52-
App --> "-circuitBreaker" CircuitBreaker
53-
App --> "-primaryService" Service
54-
DefaultCircuitBreaker ..|> CircuitBreaker
55-
LocalCacheService ..|> Service
56-
RemoteService ..|> Service
57112
@enduml

fallback/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@
6767
<version>4.5.1</version>
6868
<scope>test</scope>
6969
</dependency>
70+
7071
</dependencies>
7172
</project>

0 commit comments

Comments
 (0)