diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f350a..d410b77 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Turn on checkstyle JavaDocs module. - Add updates to the protocol, like new `ControlMessage`. - Add Spring Boot support. -- Remove non blocking queues, because it doesn't guarantee the order. + +## [1.5.0](https://github.com/appulse-projects/encon-java/releases/tag/1.5.0) - 2018-07-07 + +Remove non blocking queues, because it doesn't guarantee the order. + +### Changed + +- Replaced non-blocking queue to blocking. +- Edit docs. + +### Removed + +- Non-blocking queues. ## [1.4.0](https://github.com/appulse-projects/encon-java/releases/tag/1.4.0) - 2018-07-07 diff --git a/encon-common/pom.xml b/encon-common/pom.xml index ca09251..e782a31 100644 --- a/encon-common/pom.xml +++ b/encon-common/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon-common diff --git a/encon-config/README.md b/encon-config/README.md index 4c5537b..40c006e 100644 --- a/encon-config/README.md +++ b/encon-config/README.md @@ -14,7 +14,7 @@ First of all, add config's dependency: io.appulse.encon encon-config - 1.4.0 + 1.5.0 ... @@ -23,7 +23,7 @@ First of all, add config's dependency: **Gradle**: ```groovy -compile 'io.appulse.encon.java:encon-config:1.4.0' +compile 'io.appulse.encon.java:encon-config:1.5.0' ``` ### File based configuration @@ -57,8 +57,6 @@ defaults: distribution-flags: - MAP_TAG - BIG_CREATION - mailbox: - blocking: false server: boss-threads: 2 worker-threads: 4 @@ -87,9 +85,7 @@ nodes: - BIG_CREATION mailboxes: - name: net_kernel - blocking: false - name: another - blocking: true - name: another_one server: port: 8971 @@ -101,7 +97,6 @@ nodes: cookie: popa mailboxes: - name: net_kernel - blocking: false ``` @@ -123,9 +118,6 @@ Config config = Config.builder() MAP_TAG, BIG_CREATION ))) - .mailbox(MailboxConfig.builder() - .blocking(false) - .build()) .server(ServerConfig.builder() .bossThreads(2) .workerThreads(4) @@ -150,11 +142,9 @@ Config config = Config.builder() .distributionFlag(BIG_CREATION) .mailbox(MailboxConfig.builder() .name("net_kernel") - .blocking(false) .build()) .mailbox(MailboxConfig.builder() .name("another") - .blocking(true) .build()) .mailbox(MailboxConfig.builder() .name("another") @@ -171,7 +161,6 @@ Config config = Config.builder() .cookie("popa") .mailbox(MailboxConfig.builder() .name("net_kernel") - .blocking(false) .build()) .build() ) diff --git a/encon-config/pom.xml b/encon-config/pom.xml index 43942dd..3387191 100644 --- a/encon-config/pom.xml +++ b/encon-config/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon-config diff --git a/encon-config/src/main/java/io/appulse/encon/config/CompressionConfig.java b/encon-config/src/main/java/io/appulse/encon/config/CompressionConfig.java index 7291562..8b0dee6 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/CompressionConfig.java +++ b/encon-config/src/main/java/io/appulse/encon/config/CompressionConfig.java @@ -61,6 +61,11 @@ static CompressionConfig newInstance (@NonNull Map map) { Integer level; + /** + * Copy constructor. + * + * @param compressionConfig config to copy + */ public CompressionConfig (CompressionConfig compressionConfig) { enabled = compressionConfig.getEnabled(); level = compressionConfig.getLevel(); diff --git a/encon-config/src/main/java/io/appulse/encon/config/Config.java b/encon-config/src/main/java/io/appulse/encon/config/Config.java index 66d6780..a4a846d 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/Config.java +++ b/encon-config/src/main/java/io/appulse/encon/config/Config.java @@ -117,6 +117,11 @@ private static Map> parseYaml (@NonNull File file) { Map nodes; + /** + * Copy constructor. + * + * @param config config to copy + */ public Config (Config config) { defaults = ofNullable(config.getDefaults()) .map(Defaults::new) diff --git a/encon-config/src/main/java/io/appulse/encon/config/Defaults.java b/encon-config/src/main/java/io/appulse/encon/config/Defaults.java index 6f5fc00..1de614b 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/Defaults.java +++ b/encon-config/src/main/java/io/appulse/encon/config/Defaults.java @@ -29,7 +29,6 @@ import static io.appulse.epmd.java.core.model.Protocol.TCP; import static io.appulse.epmd.java.core.model.Version.R6; import static java.lang.Boolean.FALSE; -import static java.lang.Boolean.TRUE; import static java.util.Arrays.asList; import static java.util.Locale.ENGLISH; import static java.util.Optional.ofNullable; @@ -223,7 +222,6 @@ static Defaults newInstance (@NonNull Map map) { @Builder.Default MailboxConfig mailbox = MailboxConfig.builder() - .blocking(TRUE) .build(); @Builder.Default @@ -238,6 +236,11 @@ static Defaults newInstance (@NonNull Map map) { .level(-1) .build(); + /** + * Copy constructor. + * + * @param defaults config to copy + */ public Defaults (Defaults defaults) { epmdPort = defaults.getEpmdPort(); type = defaults.getType(); diff --git a/encon-config/src/main/java/io/appulse/encon/config/MailboxConfig.java b/encon-config/src/main/java/io/appulse/encon/config/MailboxConfig.java index 6400f1d..77ee25c 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/MailboxConfig.java +++ b/encon-config/src/main/java/io/appulse/encon/config/MailboxConfig.java @@ -48,21 +48,18 @@ static MailboxConfig newInstance (@NonNull Map map) { .map(Object::toString) .ifPresent(builder::name); - ofNullable(map.get("blocking")) - .map(Object::toString) - .map(Boolean::valueOf) - .ifPresent(builder::blocking); - return builder.build(); } String name; - Boolean blocking; - + /** + * Copy constructor. + * + * @param mailboxConfig config for copying + */ public MailboxConfig (MailboxConfig mailboxConfig) { name = mailboxConfig.getName(); - blocking = mailboxConfig.getBlocking(); } /** @@ -73,9 +70,6 @@ public MailboxConfig (MailboxConfig mailboxConfig) { * @return reference to this object (for chain calls) */ public MailboxConfig withDefaultsFrom (@NonNull MailboxConfig defaults) { - blocking = ofNullable(blocking) - .orElse(defaults.getBlocking()); - return this; } } diff --git a/encon-config/src/main/java/io/appulse/encon/config/NodeConfig.java b/encon-config/src/main/java/io/appulse/encon/config/NodeConfig.java index 25e78cd..d2ff14c 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/NodeConfig.java +++ b/encon-config/src/main/java/io/appulse/encon/config/NodeConfig.java @@ -155,6 +155,11 @@ static NodeConfig newInstance (@NonNull Map map) { CompressionConfig compression; + /** + * Copy constructor. + * + * @param nodeConfig config to copy + */ public NodeConfig (NodeConfig nodeConfig) { epmdPort = nodeConfig.getEpmdPort(); type = nodeConfig.getType(); diff --git a/encon-config/src/main/java/io/appulse/encon/config/ServerConfig.java b/encon-config/src/main/java/io/appulse/encon/config/ServerConfig.java index 5acc533..3512585 100644 --- a/encon-config/src/main/java/io/appulse/encon/config/ServerConfig.java +++ b/encon-config/src/main/java/io/appulse/encon/config/ServerConfig.java @@ -68,6 +68,11 @@ static ServerConfig newInstance (@NonNull Map map) { Integer workerThreads; + /** + * Copy constructor. + * + * @param serverConfig config to copy + */ public ServerConfig (ServerConfig serverConfig) { port = serverConfig.getPort(); bossThreads = serverConfig.getBossThreads(); diff --git a/encon-config/src/test/java/io/appulse/encon/config/ConfigTest.java b/encon-config/src/test/java/io/appulse/encon/config/ConfigTest.java index a9e496d..c33abd2 100644 --- a/encon-config/src/test/java/io/appulse/encon/config/ConfigTest.java +++ b/encon-config/src/test/java/io/appulse/encon/config/ConfigTest.java @@ -102,9 +102,6 @@ public void defaultDefaults () { softly.assertThat(defaults.getMailbox()) .isNotNull(); - softly.assertThat(defaults.getMailbox().getBlocking()) - .isTrue(); - softly.assertThat(defaults.getServer()) .isNotNull(); @@ -141,7 +138,6 @@ public void nonDefaultDefaults () { .high(high) .distributionFlags(distributionFlags) .mailbox(MailboxConfig.builder() - .blocking(false) .build()) .server(ServerConfig.builder() .bossThreads(bossThreads) @@ -181,9 +177,6 @@ public void nonDefaultDefaults () { softly.assertThat(defaults.getMailbox()) .isNotNull(); - softly.assertThat(defaults.getMailbox().getBlocking()) - .isFalse(); - softly.assertThat(defaults.getServer()) .isNotNull(); @@ -282,12 +275,6 @@ public void load () { softly.assertThat(defaults.getDistributionFlags()) .contains(MAP_TAG, BIG_CREATION); - softly.assertThat(defaults.getMailbox()) - .isNotNull(); - - softly.assertThat(defaults.getMailbox().getBlocking()) - .isFalse(); - softly.assertThat(defaults.getServer()) .isNotNull(); @@ -350,8 +337,6 @@ public void load () { .findFirst() .orElse(null); assertThat(mailbox1).isNotNull(); - softly.assertThat(mailbox1.getBlocking()) - .isFalse(); MailboxConfig mailbox2 = node1.getMailboxes() .stream() @@ -359,8 +344,6 @@ public void load () { .findFirst() .orElse(null); assertThat(mailbox2).isNotNull(); - softly.assertThat(mailbox2.getBlocking()) - .isTrue(); MailboxConfig mailbox3 = node1.getMailboxes() .stream() @@ -368,8 +351,6 @@ public void load () { .findFirst() .orElse(null); assertThat(mailbox3).isNotNull(); - softly.assertThat(mailbox3.getBlocking()) - .isFalse(); softly.assertThat(node1.getServer()) .isNotNull(); @@ -423,8 +404,6 @@ public void load () { .findFirst() .orElse(null); assertThat(mailbox1).isNotNull(); - softly.assertThat(mailbox1.getBlocking()) - .isFalse(); softly.assertThat(node2.getServer()) .isNotNull(); @@ -456,7 +435,6 @@ public void manual () { BIG_CREATION ))) .mailbox(MailboxConfig.builder() - .blocking(false) .build()) .server(ServerConfig.builder() .bossThreads(2) @@ -485,11 +463,9 @@ public void manual () { .name("net_kernel") .build()) .mailbox(MailboxConfig.builder() - .blocking(true) .build()) .mailbox(MailboxConfig.builder() .name("another") - .blocking(false) .build()) .server(ServerConfig.builder() .port(8971) @@ -502,7 +478,6 @@ public void manual () { .cookie("popa") .mailbox(MailboxConfig.builder() .name("net_kernel") - .blocking(false) .build()) .build() ) @@ -541,9 +516,6 @@ public void manual () { softly.assertThat(defaults.getMailbox()) .isNotNull(); - softly.assertThat(defaults.getMailbox().getBlocking()) - .isFalse(); - softly.assertThat(defaults.getServer()) .isNotNull(); @@ -606,8 +578,6 @@ public void manual () { .findFirst() .orElse(null); assertThat(mailbox1).isNotNull(); - softly.assertThat(mailbox1.getBlocking()) - .isFalse(); MailboxConfig mailbox2 = node1.getMailboxes() .stream() @@ -615,8 +585,6 @@ public void manual () { .findFirst() .orElse(null); assertThat(mailbox2).isNotNull(); - softly.assertThat(mailbox2.getBlocking()) - .isTrue(); MailboxConfig mailbox3 = node1.getMailboxes() .stream() @@ -624,8 +592,6 @@ public void manual () { .findFirst() .orElse(null); assertThat(mailbox3).isNotNull(); - softly.assertThat(mailbox3.getBlocking()) - .isFalse(); softly.assertThat(node1.getServer()) .isNotNull(); @@ -679,8 +645,6 @@ public void manual () { .findFirst() .orElse(null); assertThat(mailbox1).isNotNull(); - softly.assertThat(mailbox1.getBlocking()) - .isFalse(); softly.assertThat(node2.getServer()) .isNotNull(); diff --git a/encon-config/src/test/resources/connector.yml b/encon-config/src/test/resources/connector.yml index d98b633..f038851 100644 --- a/encon-config/src/test/resources/connector.yml +++ b/encon-config/src/test/resources/connector.yml @@ -11,8 +11,6 @@ defaults: distribution-flags: - MAP_TAG - BIG_CREATION - mailbox: - blocking: false server: boss-threads: 2 worker-threads: 4 @@ -38,9 +36,7 @@ nodes: - BIG_CREATION mailboxes: - name: net_kernel - blocking: false - name: another - blocking: true - name: another_one server: port: 8971 @@ -52,4 +48,3 @@ nodes: cookie: popa mailboxes: - name: net_kernel - blocking: false diff --git a/encon-databind/README.md b/encon-databind/README.md index 914803a..68fbdce 100644 --- a/encon-databind/README.md +++ b/encon-databind/README.md @@ -14,7 +14,7 @@ First of all, add databind's dependency: io.appulse.encon encon-databind - 1.4.0 + 1.5.0 ... @@ -23,7 +23,7 @@ First of all, add databind's dependency: **Gradle**: ```groovy -compile 'io.appulse.encon.java:encon-databind:1.4.0' +compile 'io.appulse.encon.java:encon-databind:1.5.0' ``` Let's imagine, you have POJO like this: diff --git a/encon-databind/pom.xml b/encon-databind/pom.xml index 287a78f..77d228e 100644 --- a/encon-databind/pom.xml +++ b/encon-databind/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon-databind diff --git a/encon-handler/README.md b/encon-handler/README.md index 9f91b74..55eeda1 100644 --- a/encon-handler/README.md +++ b/encon-handler/README.md @@ -14,7 +14,7 @@ First of all, add dependency: io.appulse.encon encon-handler - 1.4.0 + 1.5.0 ... @@ -23,7 +23,7 @@ First of all, add dependency: **Gradle**: ```groovy -compile 'io.appulse.encon.java:encon-handler:1.4.0' +compile 'io.appulse.encon.java:encon-handler:1.5.0' ``` ### Basics diff --git a/encon-handler/pom.xml b/encon-handler/pom.xml index 99cfbe7..b43015f 100644 --- a/encon-handler/pom.xml +++ b/encon-handler/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon-handler diff --git a/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/BlockingMailboxHandler.java b/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/DefaultMailboxHandler.java similarity index 72% rename from encon-handler/src/main/java/io/appulse/encon/handler/mailbox/BlockingMailboxHandler.java rename to encon-handler/src/main/java/io/appulse/encon/handler/mailbox/DefaultMailboxHandler.java index 95efd89..053a0d5 100644 --- a/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/BlockingMailboxHandler.java +++ b/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/DefaultMailboxHandler.java @@ -16,7 +16,6 @@ package io.appulse.encon.handler.mailbox; -import static io.appulse.encon.mailbox.MailboxQueueType.BLOCKING; import static lombok.AccessLevel.PRIVATE; import io.appulse.encon.connection.regular.Message; @@ -27,13 +26,13 @@ import lombok.experimental.FieldDefaults; /** - * {@link AbstractMailboxHandler} implementation for blocking queue mailboxes. + * Default {@link AbstractMailboxHandler} implementation. * - * @since 1.4.0 + * @since 1.5.0 * @author alabazin */ @FieldDefaults(level = PRIVATE, makeFinal = true) -public class BlockingMailboxHandler extends AbstractMailboxHandler { +public class DefaultMailboxHandler extends AbstractMailboxHandler { Mailbox mailbox; @@ -45,15 +44,11 @@ public class BlockingMailboxHandler extends AbstractMailboxHandler { * @param mailbox mailbox */ @Builder - public BlockingMailboxHandler (MessageHandler messageHandler, - Mailbox mailbox + public DefaultMailboxHandler (MessageHandler messageHandler, + Mailbox mailbox ) { super(messageHandler, mailbox); this.mailbox = mailbox; - - if (mailbox.getQueueType() != BLOCKING) { - throw new IllegalArgumentException("Blocking mailbox handler works only with blocking queues"); - } } @Override diff --git a/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/NonBlockingMailboxHandler.java b/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/NonBlockingMailboxHandler.java deleted file mode 100644 index e988f2d..0000000 --- a/encon-handler/src/main/java/io/appulse/encon/handler/mailbox/NonBlockingMailboxHandler.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.appulse.encon.handler.mailbox; - -import static io.appulse.encon.mailbox.MailboxQueueType.NON_BLOCKING; -import static lombok.AccessLevel.PRIVATE; - -import io.appulse.encon.connection.regular.Message; -import io.appulse.encon.handler.message.MessageHandler; -import io.appulse.encon.mailbox.Mailbox; - -import lombok.Builder; -import lombok.experimental.FieldDefaults; - -/** - * {@link AbstractMailboxHandler} implementation for non-blocking queue mailboxes. - * - * @since 1.4.0 - * @author alabazin - */ -@FieldDefaults(level = PRIVATE, makeFinal = true) -public class NonBlockingMailboxHandler extends AbstractMailboxHandler { - - Mailbox mailbox; - - /** - * Constructor. - * - * @param messageHandler received messages handler - * - * @param mailbox mailbox - */ - @Builder - public NonBlockingMailboxHandler (MessageHandler messageHandler, - Mailbox mailbox - ) { - super(messageHandler, mailbox); - this.mailbox = mailbox; - - if (mailbox.getQueueType() != NON_BLOCKING) { - throw new IllegalArgumentException("Non-blocking mailbox handler works only with non-blocking queues"); - } - } - - @Override - protected Message getMessage () { - while (Thread.interrupted()) { - Message message = mailbox.receive(); - if (message != null) { - return message; - } - } - return null; - } -} diff --git a/encon-terms/pom.xml b/encon-terms/pom.xml index c840dda..f7b7408 100644 --- a/encon-terms/pom.xml +++ b/encon-terms/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon-terms diff --git a/encon/README.md b/encon/README.md index 5a3c132..1b7a1f0 100644 --- a/encon/README.md +++ b/encon/README.md @@ -14,7 +14,7 @@ First of all, add encon's dependency: io.appulse.encon encon - 1.4.0 + 1.5.0 ... @@ -23,7 +23,7 @@ First of all, add encon's dependency: **Gradle**: ```groovy -compile 'io.appulse.encon.java:encon:1.4.0' +compile 'io.appulse.encon.java:encon:1.5.0' ``` Let's create a new `Erlang` node: @@ -57,7 +57,6 @@ After `node` creation, we could register several mailboxes: ```java -import static io.appulse.encon.mailbox.MailboxQueueType.NON_BLOCKING; import static io.appulse.encon.java.terms.Erlang.tuple; import io.appulse.encon.connection.regular.Message; @@ -67,7 +66,7 @@ import io.appulse.encon.terms.ErlangTerm; // Mailbox #1 // ---------- -// Default mailbox's type is `MailboxQueueType.BLOCKING`, +// Mailbox's type is `MailboxQueueType.BLOCKING`, by default // it uses `java.util.concurrent.LinkedBlockingQueue` under the hood. // Mailbox mailbox1 = node.mailbox() @@ -75,7 +74,7 @@ Mailbox mailbox1 = node.mailbox() .build(); for (int count = 0; count < 3; count++) { - // Mailbox.receive() is a blocking operation in that case + // Mailbox.receive() is a blocking operation Message message = mailbox.receive(); ErlangTerm body = message.getBody(); @@ -87,46 +86,17 @@ for (int count = 0; count < 3; count++) { // Mailbox #2 // ---------- -// Specify `MailboxQueueType.NON_BLOCKING` type, in this case -// it uses `java.util.concurrent.ConcurrentLinkedQueue` under the hood. -// -Mailbox mailbox2 = node.mailbox() - .name("echo-mailbox-2") - .type(NON_BLOCKING) - .build(); - -while (true) { - // Mailbox.receive() is a non-blocking operation in this case, - // that is why we have `if` clause. - Message message = mailbox2.receive(); - if (message == null) { - continue; - } - ErlangTerm body = message.getBody(); - mailbox2.send("another-node", "another-mailbox", tuple( - mailbox2.getPid(), body.getUnsafe(1) - )); -} - - -// Mailbox #3 -// ---------- -// Specify `MailboxQueueType.NON_BLOCKING` type and -// set our own `java.util.Queue` instance. +// Set your own `java.util.concurrent.BlockingQueue` instance. +// `java.util.concurrent.SynchronousQueue` instance in that case. // Mailbox mailbox3 = node.mailbox() .name("echo-mailbox-2") - .type(NON_BLOCKING) - .queue(new LinkedBlockingQueue<>()) + .queue(new SynchronousQueue<>()) .build(); while (true) { - // Mailbox.receive() is a non-blocking operation in this case, - // that is why we have `if` clause. Message message = mailbox3.receive(); - if (message == null) { - continue; - } + ErlangTerm body = message.getBody(); mailbox3.send("another-node", "another-mailbox", tuple( mailbox3.getPid(), body.getUnsafe(1) diff --git a/encon/pom.xml b/encon/pom.xml index dcb4e30..daf49df 100644 --- a/encon/pom.xml +++ b/encon/pom.xml @@ -25,7 +25,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 encon diff --git a/encon/src/main/java/io/appulse/encon/Node.java b/encon/src/main/java/io/appulse/encon/Node.java index 999b4e3..86bfab4 100644 --- a/encon/src/main/java/io/appulse/encon/Node.java +++ b/encon/src/main/java/io/appulse/encon/Node.java @@ -16,8 +16,6 @@ package io.appulse.encon; -import static io.appulse.encon.mailbox.MailboxQueueType.BLOCKING; -import static io.appulse.encon.mailbox.MailboxQueueType.NON_BLOCKING; import static lombok.AccessLevel.PACKAGE; import java.io.Closeable; @@ -99,9 +97,6 @@ static Node newInstance (@NonNull String name, @NonNull NodeConfig config) { config.getMailboxes().forEach(it -> { node.mailbox() .name(it.getName()) - .type(it.getBlocking() - ? BLOCKING - : NON_BLOCKING) .build(); }); diff --git a/encon/src/main/java/io/appulse/encon/mailbox/BlockingMailboxQueue.java b/encon/src/main/java/io/appulse/encon/mailbox/BlockingMailboxQueue.java deleted file mode 100644 index 0f1617e..0000000 --- a/encon/src/main/java/io/appulse/encon/mailbox/BlockingMailboxQueue.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.appulse.encon.mailbox; - -import static io.appulse.encon.mailbox.MailboxQueueType.BLOCKING; -import static lombok.AccessLevel.PRIVATE; - -import java.util.concurrent.BlockingQueue; - -import io.appulse.encon.connection.regular.Message; - -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import lombok.experimental.FieldDefaults; - -/** - * - * @since 1.2.0 - * @author Artem Labazin - */ -@RequiredArgsConstructor -@FieldDefaults(level = PRIVATE, makeFinal = true) -class BlockingMailboxQueue implements MailboxQueue { - - BlockingQueue queue; - - @Override - public void add (Message message) { - queue.add(message); - } - - @Override - @SneakyThrows - public Message get () { - return queue.take(); - } - - @Override - public int size () { - return queue.size(); - } - - @Override - public MailboxQueueType type () { - return BLOCKING; - } -} diff --git a/encon/src/main/java/io/appulse/encon/mailbox/Mailbox.java b/encon/src/main/java/io/appulse/encon/mailbox/Mailbox.java index e7d0d01..a421d2e 100644 --- a/encon/src/main/java/io/appulse/encon/mailbox/Mailbox.java +++ b/encon/src/main/java/io/appulse/encon/mailbox/Mailbox.java @@ -21,6 +21,7 @@ import java.io.Closeable; import java.util.Set; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; @@ -48,6 +49,7 @@ import lombok.Getter; import lombok.NonNull; import lombok.Setter; +import lombok.SneakyThrows; import lombok.ToString; import lombok.experimental.FieldDefaults; import lombok.experimental.NonFinal; @@ -85,7 +87,7 @@ public class Mailbox implements Closeable { ErlangPid pid; @NonNull - MailboxQueue queue; + BlockingQueue queue; @Getter Set links = ConcurrentHashMap.newKeySet(); @@ -99,8 +101,9 @@ public class Mailbox implements Closeable { * * @throws ReceivedExitException someone exits */ + @SneakyThrows public Message receive () { - Message message = queue.get(); + Message message = queue.take(); if (message == null) { return message; } @@ -138,15 +141,6 @@ public int size () { return queue.size(); } - /** - * Returns a mailbox queue type. - * - * @return a mailbox queue type - */ - public MailboxQueueType getQueueType () { - return queue.type(); - } - /** * Sends a message to local or remote mailbox. * diff --git a/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueue.java b/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueue.java deleted file mode 100644 index 9a3c134..0000000 --- a/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueue.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.appulse.encon.mailbox; - -import static io.appulse.encon.mailbox.MailboxQueueType.BLOCKING; - -import java.util.Queue; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.LinkedBlockingQueue; - -import io.appulse.encon.connection.regular.Message; - -/** - * - * @since 1.2.0 - * @author Artem Labazin - */ -interface MailboxQueue { - - static MailboxQueue from (Queue queue, MailboxQueueType type) { - if (queue == null && type == null) { - return new BlockingMailboxQueue(new LinkedBlockingQueue<>()); - } - - if (type == null) { - return queue instanceof BlockingQueue - ? new BlockingMailboxQueue((BlockingQueue) queue) - : new NonBlockingMailboxQueue(queue); - } - - if (queue == null) { - return type == BLOCKING - ? new BlockingMailboxQueue(new LinkedBlockingQueue<>()) - : new NonBlockingMailboxQueue(new ConcurrentLinkedQueue<>()); - } - - if (type == BLOCKING && !(queue instanceof BlockingQueue)) { - throw new IllegalArgumentException(); - } - - return type == BLOCKING - ? new BlockingMailboxQueue((BlockingQueue) queue) - : new NonBlockingMailboxQueue(queue); - } - - void add (Message message); - - Message get (); - - int size (); - - MailboxQueueType type (); -} diff --git a/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueueType.java b/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueueType.java deleted file mode 100644 index 9143654..0000000 --- a/encon/src/main/java/io/appulse/encon/mailbox/MailboxQueueType.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.appulse.encon.mailbox; - -/** - * - * @since 1.2.0 - * @author Artem Labazin - */ -public enum MailboxQueueType { - - NON_BLOCKING, - BLOCKING; -} diff --git a/encon/src/main/java/io/appulse/encon/mailbox/ModuleMailbox.java b/encon/src/main/java/io/appulse/encon/mailbox/ModuleMailbox.java index 975adf6..25a1164 100644 --- a/encon/src/main/java/io/appulse/encon/mailbox/ModuleMailbox.java +++ b/encon/src/main/java/io/appulse/encon/mailbox/ModuleMailbox.java @@ -21,8 +21,9 @@ import java.io.Closeable; import java.util.Map; -import java.util.Queue; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.LinkedBlockingQueue; import java.util.function.Supplier; import io.appulse.encon.Node; @@ -136,21 +137,14 @@ public final class NewMailboxBuilder { String name; - MailboxQueueType type; - - Queue queue; + BlockingQueue queue = new LinkedBlockingQueue<>(); public NewMailboxBuilder name (String mailboxName) { this.name = mailboxName; return this; } - public NewMailboxBuilder type (MailboxQueueType mailboxType) { - this.type = mailboxType; - return this; - } - - public NewMailboxBuilder queue (Queue mailboxQueue) { + public NewMailboxBuilder queue (BlockingQueue mailboxQueue) { this.queue = mailboxQueue; return this; } @@ -160,7 +154,7 @@ public Mailbox build () { Mailbox mailbox = Mailbox.builder() .name(name) .node(node) - .queue(MailboxQueue.from(queue, type)) + .queue(queue) .pid(pid) .build(); diff --git a/encon/src/main/java/io/appulse/encon/mailbox/NetKernelMailbox.java b/encon/src/main/java/io/appulse/encon/mailbox/NetKernelMailbox.java index b6765e9..833c46d 100644 --- a/encon/src/main/java/io/appulse/encon/mailbox/NetKernelMailbox.java +++ b/encon/src/main/java/io/appulse/encon/mailbox/NetKernelMailbox.java @@ -38,7 +38,7 @@ class NetKernelMailbox extends Mailbox { NetKernelMailbox (Node node, ErlangPid pid) { - super(null, node, pid, new BlockingMailboxQueue(new SynchronousQueue<>())); + super(null, node, pid, new SynchronousQueue<>()); } @Override diff --git a/encon/src/main/java/io/appulse/encon/mailbox/NonBlockingMailboxQueue.java b/encon/src/main/java/io/appulse/encon/mailbox/NonBlockingMailboxQueue.java deleted file mode 100644 index 000ec02..0000000 --- a/encon/src/main/java/io/appulse/encon/mailbox/NonBlockingMailboxQueue.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2018 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package io.appulse.encon.mailbox; - -import static io.appulse.encon.mailbox.MailboxQueueType.NON_BLOCKING; -import static lombok.AccessLevel.PRIVATE; - -import java.util.Queue; - -import io.appulse.encon.connection.regular.Message; - -import lombok.RequiredArgsConstructor; -import lombok.experimental.FieldDefaults; - -/** - * - * @since 1.2.0 - * @author Artem Labazin - */ -@RequiredArgsConstructor -@FieldDefaults(level = PRIVATE, makeFinal = true) -class NonBlockingMailboxQueue implements MailboxQueue { - - Queue queue; - - @Override - public void add (Message message) { - queue.add(message); - } - - @Override - public Message get () { - return queue.poll(); - } - - @Override - public int size () { - return queue.size(); - } - - @Override - public MailboxQueueType type () { - return NON_BLOCKING; - } -} diff --git a/pom.xml b/pom.xml index 3c69dc5..11b0b0d 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,7 @@ limitations under the License. io.appulse.encon encon-parent - 1.4.0 + 1.5.0 pom @@ -71,7 +71,7 @@ limitations under the License. https://github.com/appulse-projects/encon-java scm:git:https://github.com/appulse-projects/encon-java.git scm:git:https://github.com/appulse-projects/encon-java.git - 1.4.0 + 1.5.0