diff --git a/throttling/README.md b/throttling/README.md index adb067200..f31779573 100644 --- a/throttling/README.md +++ b/throttling/README.md @@ -9,6 +9,10 @@ tags: - Throttling --- +## Intent +Ensure that a given tenant is not able to access resources more than the assigned limit. +![alt text](./etc/throttling-patern.png "Throttling pattern") + ## Applicability The Throttling pattern should be used: diff --git a/throttling/etc/throttling-class-diag.ucls b/throttling/etc/throttling-class-diag.ucls deleted file mode 100644 index deb3723fd..000000000 --- a/throttling/etc/throttling-class-diag.ucls +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/throttling/etc/throttling-patern.png b/throttling/etc/throttling-patern.png new file mode 100644 index 000000000..baa03816d Binary files /dev/null and b/throttling/etc/throttling-patern.png differ diff --git a/throttling/etc/throttling.urm.puml b/throttling/etc/throttling.urm.puml index 02af47ddf..8c97da50a 100644 --- a/throttling/etc/throttling.urm.puml +++ b/throttling/etc/throttling.urm.puml @@ -1,2 +1,29 @@ @startuml +package com.iluwatar.tls { + class App { + - LOGGER : Logger {static} + + App() + + main(args : String[]) {static} + - makeServiceCalls(service : B2BService) {static} + } + ~class B2BService { + - LOGGER : Logger {static} + - callsCounter : int + - tenant : Tenant + + B2BService(tenant : Tenant) + + dummyCustomerApi() : int + + getCurrentCallsCount() : int + - getRandomCustomerId() : int + } + class Tenant { + - allowedCallsPerSecond : int + - name : String + + Tenant(name : String, allowedCallsPerSecond : int) + + getAllowedCallsPerSecond() : int + + getName() : String + + setAllowedCallsPerSecond(allowedCallsPerSecond : int) + + setName(name : String) + } +} +B2BService --> "-tenant" Tenant @enduml \ No newline at end of file diff --git a/throttling/pom.xml b/throttling/pom.xml index 60517c8de..2cbd7bf9e 100644 --- a/throttling/pom.xml +++ b/throttling/pom.xml @@ -1,4 +1,28 @@ + diff --git a/throttling/src/main/java/com/iluwatar/tls/B2BService.java b/throttling/src/main/java/com/iluwatar/tls/B2BService.java index 832e24f1f..e05a50583 100644 --- a/throttling/src/main/java/com/iluwatar/tls/B2BService.java +++ b/throttling/src/main/java/com/iluwatar/tls/B2BService.java @@ -1,3 +1,25 @@ +/** + * The MIT License + * Copyright (c) 2014 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.tls; import org.slf4j.Logger; diff --git a/throttling/src/main/java/com/iluwatar/tls/Tenant.java b/throttling/src/main/java/com/iluwatar/tls/Tenant.java index 6ef9bd28b..33d97a51e 100644 --- a/throttling/src/main/java/com/iluwatar/tls/Tenant.java +++ b/throttling/src/main/java/com/iluwatar/tls/Tenant.java @@ -1,3 +1,25 @@ +/** + * The MIT License + * Copyright (c) 2014 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.tls; import java.security.InvalidParameterException; diff --git a/throttling/src/test/java/com/iluwatar/tls/B2BServiceTest.java b/throttling/src/test/java/com/iluwatar/tls/B2BServiceTest.java index 13921f1c9..a9e043a95 100644 --- a/throttling/src/test/java/com/iluwatar/tls/B2BServiceTest.java +++ b/throttling/src/test/java/com/iluwatar/tls/B2BServiceTest.java @@ -1,3 +1,25 @@ +/** + * The MIT License + * Copyright (c) 2014 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.tls; import org.junit.Assert; diff --git a/throttling/src/test/java/com/iluwatar/tls/TenantTest.java b/throttling/src/test/java/com/iluwatar/tls/TenantTest.java index 17853c7d6..d29152e83 100644 --- a/throttling/src/test/java/com/iluwatar/tls/TenantTest.java +++ b/throttling/src/test/java/com/iluwatar/tls/TenantTest.java @@ -1,3 +1,25 @@ +/** + * The MIT License + * Copyright (c) 2014 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.tls; import org.junit.Test;