diff --git a/model-view-presenter/pom.xml b/model-view-presenter/pom.xml
index ec6f570ee..5c91846bf 100644
--- a/model-view-presenter/pom.xml
+++ b/model-view-presenter/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
model-view-presenter
model-view-presenter
diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java
index f5606e638..5952cf5f1 100644
--- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java
+++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileLoader.java
@@ -36,7 +36,7 @@ import org.slf4j.LoggerFactory;
*
* It is responsible for reading and loading the contents of a given file.
*/
-public class FileLoader implements Serializable{
+public class FileLoader implements Serializable {
/**
* Generated serial version UID
diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java
index 560a8d274..233b1dcf7 100644
--- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java
+++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorPresenter.java
@@ -30,7 +30,7 @@ import java.io.Serializable;
*
* It is responsible for reacting to the user's actions and update the View component.
*/
-public class FileSelectorPresenter implements Serializable{
+public class FileSelectorPresenter implements Serializable {
/**
* Generated serial version UID
diff --git a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java
index 5272ea0b7..e6ab93f66 100644
--- a/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java
+++ b/model-view-presenter/src/main/java/com/iluwatar/model/view/presenter/FileSelectorView.java
@@ -28,7 +28,7 @@ import java.io.Serializable;
* This interface represents the View component in the Model-View-Presenter pattern. It can be
* implemented by either the GUI components, or by the Stub.
*/
-public interface FileSelectorView extends Serializable{
+public interface FileSelectorView extends Serializable {
/**
* Opens the view.
diff --git a/module/pom.xml b/module/pom.xml
index b86069b16..1d45a77a5 100644
--- a/module/pom.xml
+++ b/module/pom.xml
@@ -28,7 +28,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
module
diff --git a/monad/pom.xml b/monad/pom.xml
index 23d5e0c0e..26cb21b97 100644
--- a/monad/pom.xml
+++ b/monad/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
monad
diff --git a/monostate/pom.xml b/monostate/pom.xml
index 5343d2094..c4dc213da 100644
--- a/monostate/pom.xml
+++ b/monostate/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
monostate
diff --git a/multiton/pom.xml b/multiton/pom.xml
index 2e5553588..af75e5ebe 100644
--- a/multiton/pom.xml
+++ b/multiton/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
multiton
diff --git a/mute-idiom/pom.xml b/mute-idiom/pom.xml
index 92b36915d..41d660c73 100644
--- a/mute-idiom/pom.xml
+++ b/mute-idiom/pom.xml
@@ -21,7 +21,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
mute-idiom
diff --git a/mutex/pom.xml b/mutex/pom.xml
index 6ba6c74a3..ff938604b 100644
--- a/mutex/pom.xml
+++ b/mutex/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
mutex
diff --git a/mutex/src/test/java/com/iluwatar/mutex/AppTest.java b/mutex/src/test/java/com/iluwatar/mutex/AppTest.java
index f224a56f5..530db835d 100644
--- a/mutex/src/test/java/com/iluwatar/mutex/AppTest.java
+++ b/mutex/src/test/java/com/iluwatar/mutex/AppTest.java
@@ -28,7 +28,7 @@ import java.io.IOException;
/**
* Application Test Entrypoint
*/
-public class AppTest{
+public class AppTest {
@Test
public void test() throws IOException {
String[] args = {};
diff --git a/naked-objects/README.md b/naked-objects/README.md
index 66e6ac2b0..eb1c083b1 100644
--- a/naked-objects/README.md
+++ b/naked-objects/README.md
@@ -29,4 +29,4 @@ Use the Naked Objects pattern when
## Credits
-* [Richard Pawson - Naked Objects](https://isis.apache.org/resources/thesis/Pawson-Naked-Objects-thesis.pdf)
+* [Richard Pawson - Naked Objects](http://downloads.nakedobjects.net/resources/Pawson%20thesis.pdf)
diff --git a/naked-objects/dom/pom.xml b/naked-objects/dom/pom.xml
index f26060fbf..5a6f4e7ba 100644
--- a/naked-objects/dom/pom.xml
+++ b/naked-objects/dom/pom.xml
@@ -16,7 +16,7 @@
com.iluwatar
naked-objects
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
naked-objects-dom
diff --git a/naked-objects/fixture/pom.xml b/naked-objects/fixture/pom.xml
index 0fccbaf56..88c982dfd 100644
--- a/naked-objects/fixture/pom.xml
+++ b/naked-objects/fixture/pom.xml
@@ -16,7 +16,7 @@
com.iluwatar
naked-objects
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
naked-objects-fixture
diff --git a/naked-objects/integtests/pom.xml b/naked-objects/integtests/pom.xml
index ba620c5be..e4006561a 100644
--- a/naked-objects/integtests/pom.xml
+++ b/naked-objects/integtests/pom.xml
@@ -16,7 +16,7 @@
com.iluwatar
naked-objects
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
naked-objects-integtests
diff --git a/naked-objects/pom.xml b/naked-objects/pom.xml
index 4dee87660..f770fe3a0 100644
--- a/naked-objects/pom.xml
+++ b/naked-objects/pom.xml
@@ -15,7 +15,7 @@
java-design-patterns
com.iluwatar
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
naked-objects
@@ -367,17 +367,17 @@
${project.groupId}
naked-objects-dom
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
${project.groupId}
naked-objects-fixture
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
${project.groupId}
naked-objects-webapp
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
diff --git a/naked-objects/webapp/pom.xml b/naked-objects/webapp/pom.xml
index d318da81d..244d1737d 100644
--- a/naked-objects/webapp/pom.xml
+++ b/naked-objects/webapp/pom.xml
@@ -16,7 +16,7 @@
com.iluwatar
naked-objects
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
naked-objects-webapp
diff --git a/null-object/pom.xml b/null-object/pom.xml
index 0d4248dbc..755db259e 100644
--- a/null-object/pom.xml
+++ b/null-object/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
null-object
diff --git a/object-mother/pom.xml b/object-mother/pom.xml
index 7b598ed9a..9b9171888 100644
--- a/object-mother/pom.xml
+++ b/object-mother/pom.xml
@@ -30,7 +30,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
object-mother
diff --git a/object-pool/pom.xml b/object-pool/pom.xml
index 66d694169..4ebb40385 100644
--- a/object-pool/pom.xml
+++ b/object-pool/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
object-pool
diff --git a/observer/pom.xml b/observer/pom.xml
index e1f2cf6bd..7113306f3 100644
--- a/observer/pom.xml
+++ b/observer/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
observer
diff --git a/page-object/pom.xml b/page-object/pom.xml
index ea17c372c..98842b387 100644
--- a/page-object/pom.xml
+++ b/page-object/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
page-object
diff --git a/partial-response/pom.xml b/partial-response/pom.xml
index ed685eb6a..94c583a98 100644
--- a/partial-response/pom.xml
+++ b/partial-response/pom.xml
@@ -29,7 +29,7 @@
java-design-patterns
com.iluwatar
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
4.0.0
diff --git a/poison-pill/pom.xml b/poison-pill/pom.xml
index 8c0935310..3bd0f0967 100644
--- a/poison-pill/pom.xml
+++ b/poison-pill/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
poison-pill
diff --git a/pom.xml b/pom.xml
index 42dc54145..9cd6fc4de 100644
--- a/pom.xml
+++ b/pom.xml
@@ -21,7 +21,7 @@
4.0.0
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
pom
2014
@@ -146,8 +146,10 @@
event-sourcing
data-transfer-object
throttling
+
unit-of-work
partial-response
+ eip-wire-tap
diff --git a/private-class-data/pom.xml b/private-class-data/pom.xml
index 98a60c3c7..3ac0cf532 100644
--- a/private-class-data/pom.xml
+++ b/private-class-data/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
private-class-data
diff --git a/producer-consumer/pom.xml b/producer-consumer/pom.xml
index 2680a973e..893d7a4ff 100644
--- a/producer-consumer/pom.xml
+++ b/producer-consumer/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
producer-consumer
diff --git a/promise/pom.xml b/promise/pom.xml
index 3753e4c25..05fd4c3ee 100644
--- a/promise/pom.xml
+++ b/promise/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
promise
diff --git a/promise/src/main/java/com/iluwatar/promise/App.java b/promise/src/main/java/com/iluwatar/promise/App.java
index df4d0cc79..dd40ec15b 100644
--- a/promise/src/main/java/com/iluwatar/promise/App.java
+++ b/promise/src/main/java/com/iluwatar/promise/App.java
@@ -65,7 +65,7 @@ public class App {
private static final Logger LOGGER = LoggerFactory.getLogger(App.class);
- private static final String DEFAULT_URL = "https://raw.githubusercontent.com/iluwatar/java-design-patterns/Promise/promise/README.md";
+ private static final String DEFAULT_URL = "https://raw.githubusercontent.com/iluwatar/java-design-patterns/master/promise/README.md";
private final ExecutorService executor;
private final CountDownLatch stopLatch;
diff --git a/promise/src/main/java/com/iluwatar/promise/PromiseSupport.java b/promise/src/main/java/com/iluwatar/promise/PromiseSupport.java
index 3629b4b5d..ae90a927e 100644
--- a/promise/src/main/java/com/iluwatar/promise/PromiseSupport.java
+++ b/promise/src/main/java/com/iluwatar/promise/PromiseSupport.java
@@ -27,11 +27,16 @@ import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
/**
* A really simplified implementation of future that allows completing it successfully with a value
* or exceptionally with an exception.
*/
class PromiseSupport implements Future {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(PromiseSupport.class);
private static final int RUNNING = 1;
private static final int FAILED = 2;
@@ -80,40 +85,34 @@ class PromiseSupport implements Future {
@Override
public T get() throws InterruptedException, ExecutionException {
- if (state == COMPLETED) {
- return value;
- } else if (state == FAILED) {
- throw new ExecutionException(exception);
- } else {
- synchronized (lock) {
+ synchronized (lock) {
+ while (state == RUNNING) {
lock.wait();
- if (state == COMPLETED) {
- return value;
- } else {
- throw new ExecutionException(exception);
- }
}
}
+ if (state == COMPLETED) {
+ return value;
+ }
+ throw new ExecutionException(exception);
}
@Override
public T get(long timeout, TimeUnit unit)
- throws InterruptedException, ExecutionException, TimeoutException {
- if (state == COMPLETED) {
- return value;
- } else if (state == FAILED) {
- throw new ExecutionException(exception);
- } else {
- synchronized (lock) {
- lock.wait(unit.toMillis(timeout));
- if (state == COMPLETED) {
- return value;
- } else if (state == FAILED) {
- throw new ExecutionException(exception);
- } else {
- throw new TimeoutException();
+ throws ExecutionException, TimeoutException {
+ synchronized (lock) {
+ while (state == RUNNING) {
+ try {
+ lock.wait(unit.toMillis(timeout));
+ } catch (InterruptedException e) {
+ LOGGER.warn("Interrupted!", e);
+ Thread.currentThread().interrupt();
}
}
}
+
+ if (state == COMPLETED) {
+ return value;
+ }
+ throw new ExecutionException(exception);
}
}
\ No newline at end of file
diff --git a/property/pom.xml b/property/pom.xml
index 8b5d25c87..db2ff8f60 100644
--- a/property/pom.xml
+++ b/property/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
property
diff --git a/prototype/pom.xml b/prototype/pom.xml
index de3571a77..62d4f0eb1 100644
--- a/prototype/pom.xml
+++ b/prototype/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
prototype
diff --git a/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java b/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java
index add5617b1..839f27bc7 100644
--- a/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java
+++ b/prototype/src/test/java/com/iluwatar/prototype/PrototypeTest.java
@@ -56,7 +56,7 @@ public class PrototypeTest {
/**
* The tested prototype instance
*/
- private final Prototype testedPrototype;
+ private final P testedPrototype;
/**
* The expected {@link Prototype#toString()} value
@@ -69,7 +69,7 @@ public class PrototypeTest
{
* @param testedPrototype The tested prototype instance
* @param expectedToString The expected {@link Prototype#toString()} value
*/
- public PrototypeTest(final Prototype testedPrototype, final String expectedToString) {
+ public PrototypeTest(final P testedPrototype, final String expectedToString) {
this.expectedToString = expectedToString;
this.testedPrototype = testedPrototype;
}
diff --git a/proxy/pom.xml b/proxy/pom.xml
index b81611fa4..ea55330b7 100644
--- a/proxy/pom.xml
+++ b/proxy/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
proxy
diff --git a/publish-subscribe/pom.xml b/publish-subscribe/pom.xml
index c9a55a3ff..ebd82f3a7 100644
--- a/publish-subscribe/pom.xml
+++ b/publish-subscribe/pom.xml
@@ -28,7 +28,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
publish-subscribe
diff --git a/queue-load-leveling/pom.xml b/queue-load-leveling/pom.xml
index 0841357b3..57741ed52 100644
--- a/queue-load-leveling/pom.xml
+++ b/queue-load-leveling/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
queue-load-leveling
diff --git a/reactor/pom.xml b/reactor/pom.xml
index 2a50d5934..9ab44d2c0 100644
--- a/reactor/pom.xml
+++ b/reactor/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
reactor
diff --git a/reader-writer-lock/pom.xml b/reader-writer-lock/pom.xml
index 70ff7afc9..d5ea9114c 100644
--- a/reader-writer-lock/pom.xml
+++ b/reader-writer-lock/pom.xml
@@ -30,7 +30,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
reader-writer-lock
diff --git a/repository/pom.xml b/repository/pom.xml
index a167dd58c..f12c40113 100644
--- a/repository/pom.xml
+++ b/repository/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
repository
diff --git a/resource-acquisition-is-initialization/pom.xml b/resource-acquisition-is-initialization/pom.xml
index ae07196b7..7a6716d7b 100644
--- a/resource-acquisition-is-initialization/pom.xml
+++ b/resource-acquisition-is-initialization/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
resource-acquisition-is-initialization
diff --git a/semaphore/pom.xml b/semaphore/pom.xml
index dbab5325e..4fa1733f4 100644
--- a/semaphore/pom.xml
+++ b/semaphore/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
semaphore
diff --git a/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java b/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java
index 26d274262..5eaed3b2e 100644
--- a/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java
+++ b/semaphore/src/test/java/com/iluwatar/semaphore/AppTest.java
@@ -28,7 +28,7 @@ import java.io.IOException;
/**
* Application Test Entrypoint
*/
-public class AppTest{
+public class AppTest {
@Test
public void test() throws IOException {
String[] args = {};
diff --git a/servant/pom.xml b/servant/pom.xml
index 4a0c753de..daa44d223 100644
--- a/servant/pom.xml
+++ b/servant/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
servant
diff --git a/service-layer/pom.xml b/service-layer/pom.xml
index 3174e95ed..6edbeba44 100644
--- a/service-layer/pom.xml
+++ b/service-layer/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
service-layer
diff --git a/service-locator/pom.xml b/service-locator/pom.xml
index 23c54c08d..7cd4028ff 100644
--- a/service-locator/pom.xml
+++ b/service-locator/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
service-locator
diff --git a/singleton/pom.xml b/singleton/pom.xml
index 77226821d..00794e25a 100644
--- a/singleton/pom.xml
+++ b/singleton/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
singleton
diff --git a/specification/pom.xml b/specification/pom.xml
index 3a4fd371b..76732b964 100644
--- a/specification/pom.xml
+++ b/specification/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
specification
diff --git a/state/pom.xml b/state/pom.xml
index 44404d5a9..256a5e9e2 100644
--- a/state/pom.xml
+++ b/state/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
state
diff --git a/step-builder/pom.xml b/step-builder/pom.xml
index fc7c7232e..432d5477a 100644
--- a/step-builder/pom.xml
+++ b/step-builder/pom.xml
@@ -30,7 +30,7 @@
java-design-patterns
com.iluwatar
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
step-builder
diff --git a/strategy/pom.xml b/strategy/pom.xml
index e6fc4cd53..cd2d7e9a0 100644
--- a/strategy/pom.xml
+++ b/strategy/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
strategy
diff --git a/template-method/pom.xml b/template-method/pom.xml
index 0bd5bdc43..916d61b0b 100644
--- a/template-method/pom.xml
+++ b/template-method/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
template-method
diff --git a/thread-pool/pom.xml b/thread-pool/pom.xml
index f34238176..94fce2b16 100644
--- a/thread-pool/pom.xml
+++ b/thread-pool/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
thread-pool
diff --git a/throttling/pom.xml b/throttling/pom.xml
index 2cbd7bf9e..7c2ee8b9a 100644
--- a/throttling/pom.xml
+++ b/throttling/pom.xml
@@ -29,7 +29,7 @@
java-design-patterns
com.iluwatar
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
4.0.0
diff --git a/throttling/src/main/java/com/iluwatar/throttling/B2BService.java b/throttling/src/main/java/com/iluwatar/throttling/B2BService.java
index c9acd4b73..51ed492eb 100644
--- a/throttling/src/main/java/com/iluwatar/throttling/B2BService.java
+++ b/throttling/src/main/java/com/iluwatar/throttling/B2BService.java
@@ -46,7 +46,7 @@ class B2BService {
*/
public int dummyCustomerApi(Tenant tenant) {
String tenantName = tenant.getName();
- int count = CallsCount.getCount(tenantName);
+ long count = CallsCount.getCount(tenantName);
LOGGER.debug("Counter for {} : {} ", tenant.getName(), count);
if (count >= tenant.getAllowedCallsPerSecond()) {
LOGGER.error("API access per second limit reached for: {}", tenantName);
diff --git a/throttling/src/main/java/com/iluwatar/throttling/CallsCount.java b/throttling/src/main/java/com/iluwatar/throttling/CallsCount.java
index 81195b074..9b274849a 100644
--- a/throttling/src/main/java/com/iluwatar/throttling/CallsCount.java
+++ b/throttling/src/main/java/com/iluwatar/throttling/CallsCount.java
@@ -22,9 +22,13 @@
*/
package com.iluwatar.throttling;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicLong;
/**
* A class to keep track of the counter of different Tenants
@@ -32,16 +36,16 @@ import java.util.concurrent.ConcurrentHashMap;
*
*/
public final class CallsCount {
- private static Map tenantCallsCount = new ConcurrentHashMap<>();
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(CallsCount.class);
+ private static Map tenantCallsCount = new ConcurrentHashMap<>();
/**
* Add a new tenant to the map.
* @param tenantName name of the tenant.
*/
public static void addTenant(String tenantName) {
- if (!tenantCallsCount.containsKey(tenantName)) {
- tenantCallsCount.put(tenantName, 0);
- }
+ tenantCallsCount.putIfAbsent(tenantName, new AtomicLong(0));
}
/**
@@ -49,7 +53,7 @@ public final class CallsCount {
* @param tenantName name of the tenant.
*/
public static void incrementCount(String tenantName) {
- tenantCallsCount.put(tenantName, tenantCallsCount.get(tenantName) + 1);
+ tenantCallsCount.get(tenantName).incrementAndGet();
}
/**
@@ -57,16 +61,17 @@ public final class CallsCount {
* @param tenantName name of the tenant.
* @return the count of the tenant.
*/
- public static int getCount(String tenantName) {
- return tenantCallsCount.get(tenantName);
+ public static long getCount(String tenantName) {
+ return tenantCallsCount.get(tenantName).get();
}
/**
* Resets the count of all the tenants in the map.
*/
public static void reset() {
- for (Entry e : tenantCallsCount.entrySet()) {
- tenantCallsCount.put(e.getKey(), 0);
+ LOGGER.debug("Resetting the map.");
+ for (Entry e : tenantCallsCount.entrySet()) {
+ tenantCallsCount.put(e.getKey(), new AtomicLong(0));
}
}
}
diff --git a/throttling/src/main/java/com/iluwatar/throttling/timer/ThrottleTimerImpl.java b/throttling/src/main/java/com/iluwatar/throttling/timer/ThrottleTimerImpl.java
index 51c5e3c28..4ff4ce246 100644
--- a/throttling/src/main/java/com/iluwatar/throttling/timer/ThrottleTimerImpl.java
+++ b/throttling/src/main/java/com/iluwatar/throttling/timer/ThrottleTimerImpl.java
@@ -35,7 +35,7 @@ import com.iluwatar.throttling.CallsCount;
* @author drastogi
*
*/
-public class ThrottleTimerImpl implements Throttler{
+public class ThrottleTimerImpl implements Throttler {
private int throttlePeriod;
diff --git a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java
index b9ca1a1d8..aaab62b3a 100644
--- a/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java
+++ b/throttling/src/test/java/com/iluwatar/throttling/B2BServiceTest.java
@@ -36,14 +36,13 @@ public class B2BServiceTest {
@Test
public void dummyCustomerApiTest() {
Tenant tenant = new Tenant("testTenant", 2);
- Throttler timer = new ThrottleTimerImpl(10);
+ Throttler timer = new ThrottleTimerImpl(100);
B2BService service = new B2BService(timer);
-
+
for (int i = 0; i < 5; i++) {
service.dummyCustomerApi(tenant);
}
-
- int counter = CallsCount.getCount(tenant.getName());
+ long counter = CallsCount.getCount(tenant.getName());
Assert.assertTrue("Counter limit must be reached", counter == 2);
}
}
diff --git a/tls/pom.xml b/tls/pom.xml
index 460c5e7ea..40d6b2b21 100644
--- a/tls/pom.xml
+++ b/tls/pom.xml
@@ -30,7 +30,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
tls
diff --git a/tolerant-reader/pom.xml b/tolerant-reader/pom.xml
index 99a2cf880..7e3561f80 100644
--- a/tolerant-reader/pom.xml
+++ b/tolerant-reader/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
tolerant-reader
diff --git a/twin/pom.xml b/twin/pom.xml
index 013406215..62d138fd9 100644
--- a/twin/pom.xml
+++ b/twin/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
twin
diff --git a/value-object/pom.xml b/value-object/pom.xml
index 2db53f244..fa4c06697 100644
--- a/value-object/pom.xml
+++ b/value-object/pom.xml
@@ -30,7 +30,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
value-object
diff --git a/visitor/pom.xml b/visitor/pom.xml
index 7105f6ba7..5445a94cc 100644
--- a/visitor/pom.xml
+++ b/visitor/pom.xml
@@ -29,7 +29,7 @@
com.iluwatar
java-design-patterns
- 1.17.0-SNAPSHOT
+ 1.18.0-SNAPSHOT
visitor