diff --git a/abstract-document/pom.xml b/abstract-document/pom.xml index 42d439afd..cf49544cd 100644 --- a/abstract-document/pom.xml +++ b/abstract-document/pom.xml @@ -29,7 +29,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT abstract-document diff --git a/abstract-factory/pom.xml b/abstract-factory/pom.xml index 4c7e51be2..f3a266f8e 100644 --- a/abstract-factory/pom.xml +++ b/abstract-factory/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT abstract-factory diff --git a/adapter/pom.xml b/adapter/pom.xml index 44259f1c6..24245fad7 100644 --- a/adapter/pom.xml +++ b/adapter/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT adapter diff --git a/aggregator-microservices/aggregator-service/pom.xml b/aggregator-microservices/aggregator-service/pom.xml index 078e38d30..32d5caa3f 100644 --- a/aggregator-microservices/aggregator-service/pom.xml +++ b/aggregator-microservices/aggregator-service/pom.xml @@ -29,7 +29,7 @@ aggregator-microservices com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/aggregator-microservices/information-microservice/pom.xml b/aggregator-microservices/information-microservice/pom.xml index f379afa27..8b24cdcc0 100644 --- a/aggregator-microservices/information-microservice/pom.xml +++ b/aggregator-microservices/information-microservice/pom.xml @@ -29,7 +29,7 @@ aggregator-microservices com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/aggregator-microservices/inventory-microservice/pom.xml b/aggregator-microservices/inventory-microservice/pom.xml index 8db0814c9..06804343c 100644 --- a/aggregator-microservices/inventory-microservice/pom.xml +++ b/aggregator-microservices/inventory-microservice/pom.xml @@ -29,7 +29,7 @@ aggregator-microservices com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/aggregator-microservices/pom.xml b/aggregator-microservices/pom.xml index caf600e86..aae6b88d5 100644 --- a/aggregator-microservices/pom.xml +++ b/aggregator-microservices/pom.xml @@ -29,7 +29,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 aggregator-microservices diff --git a/api-gateway/api-gateway-service/pom.xml b/api-gateway/api-gateway-service/pom.xml index 372c4d0dd..a97c25cfc 100644 --- a/api-gateway/api-gateway-service/pom.xml +++ b/api-gateway/api-gateway-service/pom.xml @@ -29,7 +29,7 @@ api-gateway com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 api-gateway-service diff --git a/api-gateway/image-microservice/pom.xml b/api-gateway/image-microservice/pom.xml index 50fc12886..574623b3a 100644 --- a/api-gateway/image-microservice/pom.xml +++ b/api-gateway/image-microservice/pom.xml @@ -29,7 +29,7 @@ api-gateway com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/api-gateway/pom.xml b/api-gateway/pom.xml index f474ba66a..124b3cf24 100644 --- a/api-gateway/pom.xml +++ b/api-gateway/pom.xml @@ -29,7 +29,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 api-gateway diff --git a/api-gateway/price-microservice/pom.xml b/api-gateway/price-microservice/pom.xml index ec6799674..aed9fb38b 100644 --- a/api-gateway/price-microservice/pom.xml +++ b/api-gateway/price-microservice/pom.xml @@ -29,7 +29,7 @@ api-gateway com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/async-method-invocation/pom.xml b/async-method-invocation/pom.xml index af169c14f..7e15aff73 100644 --- a/async-method-invocation/pom.xml +++ b/async-method-invocation/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT async-method-invocation diff --git a/balking/README.md b/balking/README.md index f720c0d02..fb5c83d5b 100644 --- a/balking/README.md +++ b/balking/README.md @@ -18,10 +18,10 @@ incomplete or inappropriate state ## Applicability Use the Balking pattern when -*you want to invoke an action on an object only when it is in a particular state -*objects are generally only in a state that is prone to balking temporarily +* you want to invoke an action on an object only when it is in a particular state +* objects are generally only in a state that is prone to balking temporarily but for an unknown amount of time ## Related patterns * Guarded Suspension Pattern -* Double Checked Locking Pattern \ No newline at end of file +* Double Checked Locking Pattern diff --git a/balking/pom.xml b/balking/pom.xml index a924eae43..28fa0db61 100644 --- a/balking/pom.xml +++ b/balking/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/bridge/pom.xml b/bridge/pom.xml index 5a807bbdd..be0f5439c 100644 --- a/bridge/pom.xml +++ b/bridge/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT bridge diff --git a/bridge/src/test/java/com/iluwatar/bridge/WeaponTest.java b/bridge/src/test/java/com/iluwatar/bridge/WeaponTest.java index daec1014a..0e62374be 100644 --- a/bridge/src/test/java/com/iluwatar/bridge/WeaponTest.java +++ b/bridge/src/test/java/com/iluwatar/bridge/WeaponTest.java @@ -44,15 +44,15 @@ public abstract class WeaponTest { assertNotNull(weapon.getEnchantment()); weapon.swing(); - verify(enchantment, times(1)).apply(); + verify(enchantment).apply(); verifyNoMoreInteractions(enchantment); weapon.wield(); - verify(enchantment, times(1)).onActivate(); + verify(enchantment).onActivate(); verifyNoMoreInteractions(enchantment); weapon.unwield(); - verify(enchantment, times(1)).onDeactivate(); + verify(enchantment).onDeactivate(); verifyNoMoreInteractions(enchantment); } diff --git a/builder/pom.xml b/builder/pom.xml index 0c4d44bdc..0f70791e4 100644 --- a/builder/pom.xml +++ b/builder/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT builder diff --git a/business-delegate/pom.xml b/business-delegate/pom.xml index db04484a4..c6ceb7e43 100644 --- a/business-delegate/pom.xml +++ b/business-delegate/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT business-delegate diff --git a/caching/pom.xml b/caching/pom.xml index 1da9a33d3..cd1784539 100644 --- a/caching/pom.xml +++ b/caching/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT caching diff --git a/callback/pom.xml b/callback/pom.xml index b4ece4579..c87e58f63 100644 --- a/callback/pom.xml +++ b/callback/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT callback diff --git a/chain/pom.xml b/chain/pom.xml index f35faf468..ffdb13821 100644 --- a/chain/pom.xml +++ b/chain/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT chain diff --git a/checkstyle.xml b/checkstyle.xml index 37db7e711..b3fbf19a8 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -85,9 +85,7 @@ value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/> - - - + diff --git a/command/pom.xml b/command/pom.xml index 3612dd8aa..397818f5c 100644 --- a/command/pom.xml +++ b/command/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT command diff --git a/command/src/main/java/com/iluwatar/command/Size.java b/command/src/main/java/com/iluwatar/command/Size.java index 1e72474cc..25f94a101 100644 --- a/command/src/main/java/com/iluwatar/command/Size.java +++ b/command/src/main/java/com/iluwatar/command/Size.java @@ -29,7 +29,7 @@ package com.iluwatar.command; */ public enum Size { - SMALL("small"), NORMAL("normal"), LARGE("large"), UNDEFINED(""); + SMALL("small"), NORMAL("normal"); private String title; diff --git a/command/src/main/java/com/iluwatar/command/Visibility.java b/command/src/main/java/com/iluwatar/command/Visibility.java index 802927b9d..8c360d534 100644 --- a/command/src/main/java/com/iluwatar/command/Visibility.java +++ b/command/src/main/java/com/iluwatar/command/Visibility.java @@ -29,7 +29,7 @@ package com.iluwatar.command; */ public enum Visibility { - VISIBLE("visible"), INVISIBLE("invisible"), UNDEFINED(""); + VISIBLE("visible"), INVISIBLE("invisible"); private String title; diff --git a/command/src/main/java/com/iluwatar/command/Wizard.java b/command/src/main/java/com/iluwatar/command/Wizard.java index 501676984..866ea0e0f 100644 --- a/command/src/main/java/com/iluwatar/command/Wizard.java +++ b/command/src/main/java/com/iluwatar/command/Wizard.java @@ -40,7 +40,9 @@ public class Wizard { private Deque undoStack = new LinkedList<>(); private Deque redoStack = new LinkedList<>(); - public Wizard() {} + public Wizard() { + // comment to ignore sonar issue: LEVEL critical + } /** * Cast spell diff --git a/composite/pom.xml b/composite/pom.xml index 62f07c8d5..913db6989 100644 --- a/composite/pom.xml +++ b/composite/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT composite diff --git a/converter/pom.xml b/converter/pom.xml index 6bd1c5c16..923b0e43c 100644 --- a/converter/pom.xml +++ b/converter/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/cqrs/pom.xml b/cqrs/pom.xml index 6c036a933..2e5644bb6 100644 --- a/cqrs/pom.xml +++ b/cqrs/pom.xml @@ -21,7 +21,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT cqrs diff --git a/dao/pom.xml b/dao/pom.xml index e61eaba3c..4c4c8500d 100644 --- a/dao/pom.xml +++ b/dao/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT dao diff --git a/data-bus/pom.xml b/data-bus/pom.xml index a77b59106..318caf89a 100644 --- a/data-bus/pom.xml +++ b/data-bus/pom.xml @@ -33,7 +33,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT data-bus diff --git a/data-mapper/pom.xml b/data-mapper/pom.xml index 2d39ed042..66a0e469e 100644 --- a/data-mapper/pom.xml +++ b/data-mapper/pom.xml @@ -28,7 +28,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT data-mapper diff --git a/data-transfer-object/pom.xml b/data-transfer-object/pom.xml index 2f4871cb6..b0fd66da3 100644 --- a/data-transfer-object/pom.xml +++ b/data-transfer-object/pom.xml @@ -28,7 +28,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT data-transfer-object diff --git a/decorator/pom.xml b/decorator/pom.xml index 99a7b14c0..8319c7a8f 100644 --- a/decorator/pom.xml +++ b/decorator/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT decorator diff --git a/delegation/pom.xml b/delegation/pom.xml index 67b1e599f..f2cb95dc1 100644 --- a/delegation/pom.xml +++ b/delegation/pom.xml @@ -30,7 +30,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/dependency-injection/pom.xml b/dependency-injection/pom.xml index e4e7765a3..e01d5b68d 100644 --- a/dependency-injection/pom.xml +++ b/dependency-injection/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT dependency-injection diff --git a/double-checked-locking/pom.xml b/double-checked-locking/pom.xml index e82dcd559..f32a45d37 100644 --- a/double-checked-locking/pom.xml +++ b/double-checked-locking/pom.xml @@ -27,7 +27,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT double-checked-locking diff --git a/double-dispatch/pom.xml b/double-dispatch/pom.xml index 90ea0a66d..44107f474 100644 --- a/double-dispatch/pom.xml +++ b/double-dispatch/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT double-dispatch diff --git a/eip-wire-tap/README.md b/eip-wire-tap/README.md new file mode 100644 index 000000000..d2742aa31 --- /dev/null +++ b/eip-wire-tap/README.md @@ -0,0 +1,29 @@ +--- +layout: pattern +title: EIP Wire Tap +folder: eip-wire-tap +permalink: /patterns/eip-wire-tap/ +categories: Enterprise integration +tags: + - Java + - Difficulty-Intermittent + - Enterprise integration +--- + +## Intent +In most integration cases there is a need to monitor the messages flowing through the system. It is usually achieved +by intercepting the message and redirecting it to a different location like console, filesystem or the database. +It is important that such functionality should not modify the original message and influence the processing path. + +![alt text](./etc/wiretap.gif "Wire Tap") + +## Applicability +Use the Wire Tap pattern when + +* You need to monitor messages flowing through the system +* You need to redirect the same, unchanged message to two different endpoints/paths + +## Credits + +* [Gregor Hohpe, Bobby Woolf - Enterprise Integration Patterns](http://www.enterpriseintegrationpatterns.com/patterns/messaging/WireTap.html) +* [Apache Camel - Documentation](http://camel.apache.org/wire-tap.html) diff --git a/eip-wire-tap/etc/wiretap.gif b/eip-wire-tap/etc/wiretap.gif new file mode 100644 index 000000000..414173716 Binary files /dev/null and b/eip-wire-tap/etc/wiretap.gif differ diff --git a/eip-wire-tap/pom.xml b/eip-wire-tap/pom.xml new file mode 100644 index 000000000..b3bc678b0 --- /dev/null +++ b/eip-wire-tap/pom.xml @@ -0,0 +1,63 @@ + + + + 4.0.0 + eip-wire-tap + + com.iluwatar + java-design-patterns + 1.18.0-SNAPSHOT + + + + + org.springframework.boot + spring-boot-starter-web + + + + org.apache.camel + camel-core + ${camel.version} + + + + org.apache.camel + camel-spring-boot + ${camel.version} + + + + + org.springframework.boot + spring-boot-starter-test + + + + org.apache.camel + camel-test-spring + ${camel.version} + + + + \ No newline at end of file diff --git a/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/App.java b/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/App.java new file mode 100644 index 000000000..7bf4ce0d4 --- /dev/null +++ b/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/App.java @@ -0,0 +1,51 @@ +package com.iluwatar.eip.wiretap; + +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.ConfigurableApplicationContext; + +/** + * In most integration cases there is a need to monitor the messages flowing through the system. It is usually achieved + * by intercepting the message and redirecting it to a different location like console, filesystem or the database. + * It is important that such functionality should not modify the original message and influence the processing path. + * + *

+ * Wire Tap allows you to route messages to a separate location while they are being forwarded to the ultimate + * destination. It basically consumes messages of the input channel and publishes the unmodified message to both + * output channels. + *

+ */ +@SpringBootApplication +public class App { + + /** + * Program entry point. It starts Spring Boot application and using Apache Camel it auto-configures routes. + * + * @param args command line args + */ + public static void main(String[] args) throws Exception { + // Run Spring Boot application and obtain ApplicationContext + ConfigurableApplicationContext context = SpringApplication.run(App.class, args); + + // Get CamelContext from ApplicationContext + CamelContext camelContext = (CamelContext) context.getBean("camelContext"); + + // Add a new routes that will handle endpoints form WireTapRoute class. + camelContext.addRoutes(new RouteBuilder() { + + @Override + public void configure() throws Exception { + from("{{endpoint}}").log("ENDPOINT: ${body}"); + from("{{wireTapEndpoint}}").log("WIRETAPPED ENDPOINT: ${body}"); + } + + }); + + // Add producer that will send test message to an entry point in WireTapRoute + camelContext.createProducerTemplate().sendBody("{{entry}}", "Test message"); + + SpringApplication.exit(context); + } +} diff --git a/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/routes/WireTapRoute.java b/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/routes/WireTapRoute.java new file mode 100644 index 000000000..c744295ee --- /dev/null +++ b/eip-wire-tap/src/main/java/com/iluwatar/eip/wiretap/routes/WireTapRoute.java @@ -0,0 +1,32 @@ +package com.iluwatar.eip.wiretap.routes; + +import org.apache.camel.builder.RouteBuilder; +import org.springframework.stereotype.Component; + +/** + * Sample wire tap route definition. + * + *

+ * It consumes messages out of the direct:entry entry point and forwards them to direct:endpoint. + * Wire Tap intercepts the message and sends it to direct:wireTap, which in turn forwards it to + * direct:wireTapEndpoint. + *

+ * + * In this example input/output endpoints names are stored in application.properties file. + */ +@Component +public class WireTapRoute extends RouteBuilder { + + /** + * Configures the route + * @throws Exception in case of exception during configuration + */ + @Override + public void configure() throws Exception { + // Main route + from("{{entry}}").wireTap("direct:wireTap").to("{{endpoint}}"); + + // Wire tap route + from("direct:wireTap").log("Message: ${body}").to("{{wireTapEndpoint}}"); + } +} diff --git a/eip-wire-tap/src/main/resources/application.properties b/eip-wire-tap/src/main/resources/application.properties new file mode 100644 index 000000000..6dabe6ccc --- /dev/null +++ b/eip-wire-tap/src/main/resources/application.properties @@ -0,0 +1,3 @@ +entry=direct:entry +endpoint=direct:endpoint +wireTapEndpoint=direct:wireTapEndpoint \ No newline at end of file diff --git a/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/AppTest.java b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/AppTest.java new file mode 100644 index 000000000..25b9d8550 --- /dev/null +++ b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/AppTest.java @@ -0,0 +1,15 @@ +package com.iluwatar.eip.wiretap; + +import org.junit.Test; + +/** + * Test for App class + */ +public class AppTest { + + @Test + public void testMain() throws Exception { + String[] args = {}; + App.main(args); + } +} diff --git a/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java new file mode 100644 index 000000000..a7b15f45e --- /dev/null +++ b/eip-wire-tap/src/test/java/com/iluwatar/eip/wiretap/routes/WireTapRouteTest.java @@ -0,0 +1,62 @@ +package com.iluwatar.eip.wiretap.routes; + +import org.apache.camel.EndpointInject; +import org.apache.camel.Message; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import static org.junit.Assert.assertEquals; + +/** + * Test class for WireTapRoute. + *

+ * In order for it to work we have to mock endpoints we want to read/write to. To mock those we need to substitute + * original endpoint names to mocks. + *

+ */ +@RunWith(SpringJUnit4ClassRunner.class) +@SpringApplicationConfiguration(classes = WireTapRouteTest.class) +@ActiveProfiles("test") +@EnableAutoConfiguration +@ComponentScan +public class WireTapRouteTest { + + @EndpointInject(uri = "{{entry}}") + private ProducerTemplate entry; + + @EndpointInject(uri = "{{endpoint}}") + private MockEndpoint endpoint; + + @EndpointInject(uri = "{{wireTapEndpoint}}") + private MockEndpoint wireTapEndpoint; + + /** + * Test if both endpoints receive exactly one message containing the same, unchanged body. + * @throws Exception in case of en exception during the test + */ + @Test + @DirtiesContext + public void testWireTap() throws Exception { + entry.sendBody("TEST"); + + endpoint.expectedMessageCount(1); + wireTapEndpoint.expectedMessageCount(1); + + endpoint.assertIsSatisfied(); + wireTapEndpoint.assertIsSatisfied(); + + Message endpointIn = endpoint.getExchanges().get(0).getIn(); + Message wireTapEndpointIn = wireTapEndpoint.getExchanges().get(0).getIn(); + + assertEquals("TEST", endpointIn.getBody()); + assertEquals("TEST", wireTapEndpointIn.getBody()); + } +} diff --git a/eip-wire-tap/src/test/resources/application-test.properties b/eip-wire-tap/src/test/resources/application-test.properties new file mode 100644 index 000000000..1719c8ca4 --- /dev/null +++ b/eip-wire-tap/src/test/resources/application-test.properties @@ -0,0 +1,3 @@ +entry=direct:entry +endpoint=mock:endpoint +wireTapEndpoint=mock:wireTapEndpoint \ No newline at end of file diff --git a/event-aggregator/pom.xml b/event-aggregator/pom.xml index 19e76af84..a3e7f96cf 100644 --- a/event-aggregator/pom.xml +++ b/event-aggregator/pom.xml @@ -28,7 +28,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT event-aggregator diff --git a/event-asynchronous/pom.xml b/event-asynchronous/pom.xml index 5a2d65bfe..afb3213f1 100644 --- a/event-asynchronous/pom.xml +++ b/event-asynchronous/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT event-asynchronous diff --git a/event-driven-architecture/pom.xml b/event-driven-architecture/pom.xml index 4f2c34b5e..4db6b6c0c 100644 --- a/event-driven-architecture/pom.xml +++ b/event-driven-architecture/pom.xml @@ -31,7 +31,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT event-driven-architecture diff --git a/event-queue/pom.xml b/event-queue/pom.xml index 59dfa9119..cbfc0976d 100644 --- a/event-queue/pom.xml +++ b/event-queue/pom.xml @@ -30,7 +30,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT event-queue diff --git a/event-sourcing/pom.xml b/event-sourcing/pom.xml index 35d462cb1..ac7745fbe 100644 --- a/event-sourcing/pom.xml +++ b/event-sourcing/pom.xml @@ -30,7 +30,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT event-sourcing diff --git a/execute-around/pom.xml b/execute-around/pom.xml index c4b3ac504..3da4dc440 100644 --- a/execute-around/pom.xml +++ b/execute-around/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT execute-around diff --git a/extension-objects/pom.xml b/extension-objects/pom.xml index c5ee535fe..2215834d7 100644 --- a/extension-objects/pom.xml +++ b/extension-objects/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/facade/pom.xml b/facade/pom.xml index d699ac8fe..7a6021530 100644 --- a/facade/pom.xml +++ b/facade/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT facade diff --git a/factory-kit/pom.xml b/factory-kit/pom.xml index 50942b3a0..eee0cd734 100644 --- a/factory-kit/pom.xml +++ b/factory-kit/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT factory-kit diff --git a/factory-method/pom.xml b/factory-method/pom.xml index 61d0058ae..8c54f63a1 100644 --- a/factory-method/pom.xml +++ b/factory-method/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT factory-method diff --git a/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java b/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java index 4f3a5930d..69736855c 100644 --- a/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java +++ b/factory-method/src/test/java/com/iluwatar/factory/method/FactoryMethodTest.java @@ -95,7 +95,7 @@ public class FactoryMethodTest { */ private void verifyWeapon(Weapon weapon, WeaponType expectedWeaponType, Class clazz) { assertTrue("Weapon must be an object of: " + clazz.getName(), clazz.isInstance(weapon)); - assertEquals("Weapon must be of weaponType: " + clazz.getName(), expectedWeaponType, + assertEquals("Weapon must be of weaponType: " + expectedWeaponType, expectedWeaponType, weapon.getWeaponType()); } } diff --git a/feature-toggle/pom.xml b/feature-toggle/pom.xml index b8201aa4f..6536710ba 100644 --- a/feature-toggle/pom.xml +++ b/feature-toggle/pom.xml @@ -30,7 +30,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/fluentinterface/pom.xml b/fluentinterface/pom.xml index 9c352f1a9..11318e295 100644 --- a/fluentinterface/pom.xml +++ b/fluentinterface/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/flux/pom.xml b/flux/pom.xml index 01e3c4a90..779bd3e97 100644 --- a/flux/pom.xml +++ b/flux/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT flux diff --git a/flyweight/pom.xml b/flyweight/pom.xml index d93f66681..9814dc2df 100644 --- a/flyweight/pom.xml +++ b/flyweight/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT flyweight diff --git a/front-controller/pom.xml b/front-controller/pom.xml index 720f6d2ee..b9080bda7 100644 --- a/front-controller/pom.xml +++ b/front-controller/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT front-controller diff --git a/guarded-suspension/pom.xml b/guarded-suspension/pom.xml index 9b6d70ef8..bcc9ead06 100644 --- a/guarded-suspension/pom.xml +++ b/guarded-suspension/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT jar guarded-suspension diff --git a/half-sync-half-async/pom.xml b/half-sync-half-async/pom.xml index 16940cefa..ac8464d75 100644 --- a/half-sync-half-async/pom.xml +++ b/half-sync-half-async/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT half-sync-half-async diff --git a/hexagonal/pom.xml b/hexagonal/pom.xml index b18127f4b..940a7fc61 100644 --- a/hexagonal/pom.xml +++ b/hexagonal/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT hexagonal diff --git a/intercepting-filter/pom.xml b/intercepting-filter/pom.xml index 91f61489c..40888b7f3 100644 --- a/intercepting-filter/pom.xml +++ b/intercepting-filter/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT intercepting-filter diff --git a/interpreter/pom.xml b/interpreter/pom.xml index 2fda838ea..8c0ab09a0 100644 --- a/interpreter/pom.xml +++ b/interpreter/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT interpreter diff --git a/iterator/pom.xml b/iterator/pom.xml index 5a751db9c..2233e0b32 100644 --- a/iterator/pom.xml +++ b/iterator/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT iterator diff --git a/layers/pom.xml b/layers/pom.xml index 084795acd..d15b524de 100644 --- a/layers/pom.xml +++ b/layers/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT com.iluwatar.layers layers diff --git a/lazy-loading/pom.xml b/lazy-loading/pom.xml index 0e54e6869..9d3652feb 100644 --- a/lazy-loading/pom.xml +++ b/lazy-loading/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT lazy-loading diff --git a/marker/pom.xml b/marker/pom.xml index ba68b825b..91cf2c48a 100644 --- a/marker/pom.xml +++ b/marker/pom.xml @@ -24,7 +24,7 @@ java-design-patterns com.iluwatar - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT 4.0.0 diff --git a/mediator/pom.xml b/mediator/pom.xml index a15134368..978aa7da6 100644 --- a/mediator/pom.xml +++ b/mediator/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT mediator diff --git a/memento/pom.xml b/memento/pom.xml index 8d95f32bb..858b75544 100644 --- a/memento/pom.xml +++ b/memento/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT memento diff --git a/message-channel/pom.xml b/message-channel/pom.xml index f73214855..091c35f85 100644 --- a/message-channel/pom.xml +++ b/message-channel/pom.xml @@ -30,7 +30,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT message-channel diff --git a/model-view-controller/pom.xml b/model-view-controller/pom.xml index 4aeb69715..385953d0a 100644 --- a/model-view-controller/pom.xml +++ b/model-view-controller/pom.xml @@ -29,7 +29,7 @@ com.iluwatar java-design-patterns - 1.17.0-SNAPSHOT + 1.18.0-SNAPSHOT model-view-controller 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