diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..d57aa4c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,268 @@ +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +max_line_length = 140 +tab_width = 4 +ij_continuation_indent_size = 8 +ij_formatter_off_tag = @formatter:off +ij_formatter_on_tag = @formatter:on +ij_formatter_tags_enabled = true +ij_smart_tabs = false +ij_wrap_on_typing = false +trim_trailing_whitespace = true + +[*.java] +ij_java_align_consecutive_assignments = false +ij_java_align_consecutive_variable_declarations = false +ij_java_align_group_field_declarations = false +ij_java_align_multiline_annotation_parameters = true +ij_java_align_multiline_array_initializer_expression = false +ij_java_align_multiline_assignment = false +ij_java_align_multiline_binary_operation = false +ij_java_align_multiline_chained_methods = false +ij_java_align_multiline_extends_list = true +ij_java_align_multiline_for = false +ij_java_align_multiline_method_parentheses = false +ij_java_align_multiline_parameters = false +ij_java_align_multiline_parameters_in_calls = false +ij_java_align_multiline_parenthesized_expression = false +ij_java_align_multiline_resources = false +ij_java_align_multiline_ternary_operation = false +ij_java_align_multiline_text_blocks = false +ij_java_align_multiline_throws_list = false +ij_java_align_subsequent_simple_methods = false +ij_java_align_throws_keyword = false +ij_java_annotation_parameter_wrap = normal +ij_java_array_initializer_new_line_after_left_brace = false +ij_java_array_initializer_right_brace_on_new_line = false +ij_java_array_initializer_wrap = on_every_item +ij_java_assert_statement_colon_on_next_line = false +ij_java_assert_statement_wrap = off +ij_java_assignment_wrap = off +ij_java_binary_operation_sign_on_next_line = true +ij_java_binary_operation_wrap = normal +ij_java_blank_lines_after_anonymous_class_header = 0 +ij_java_blank_lines_after_class_header = 0 +ij_java_blank_lines_after_imports = 1 +ij_java_blank_lines_after_package = 1 +ij_java_blank_lines_around_class = 1 +ij_java_blank_lines_around_field = 0 +ij_java_blank_lines_around_field_in_interface = 0 +ij_java_blank_lines_around_initializer = 1 +ij_java_blank_lines_around_method = 1 +ij_java_blank_lines_around_method_in_interface = 1 +ij_java_blank_lines_before_class_end = 0 +ij_java_blank_lines_before_imports = 1 +ij_java_blank_lines_before_method_body = 0 +ij_java_blank_lines_before_package = 0 +ij_java_block_brace_style = end_of_line +ij_java_block_comment_at_first_column = true +ij_java_call_parameters_new_line_after_left_paren = false +ij_java_call_parameters_right_paren_on_new_line = false +ij_java_call_parameters_wrap = normal +ij_java_case_statement_on_separate_line = true +ij_java_catch_on_new_line = false +ij_java_class_annotation_wrap = split_into_lines +ij_java_class_brace_style = end_of_line +ij_java_class_count_to_use_import_on_demand = 999999 +ij_java_class_names_in_javadoc = 2 +ij_java_do_not_indent_top_level_class_members = false +ij_java_do_not_wrap_after_single_annotation = false +ij_java_do_while_brace_force = always +ij_java_doc_add_blank_line_after_description = true +ij_java_doc_add_blank_line_after_param_comments = false +ij_java_doc_add_blank_line_after_return = false +ij_java_doc_add_p_tag_on_empty_lines = true +ij_java_doc_align_exception_comments = true +ij_java_doc_align_param_comments = true +ij_java_doc_do_not_wrap_if_one_line = false +ij_java_doc_enable_formatting = true +ij_java_doc_enable_leading_asterisks = true +ij_java_doc_indent_on_continuation = false +ij_java_doc_keep_empty_lines = true +ij_java_doc_keep_empty_parameter_tag = true +ij_java_doc_keep_empty_return_tag = true +ij_java_doc_keep_empty_throws_tag = true +ij_java_doc_keep_invalid_tags = true +ij_java_doc_param_description_on_new_line = true +ij_java_doc_preserve_line_breaks = false +ij_java_doc_use_throws_not_exception_tag = true +ij_java_else_on_new_line = false +ij_java_entity_dd_suffix = EJB +ij_java_entity_eb_suffix = Bean +ij_java_entity_hi_suffix = Home +ij_java_entity_lhi_prefix = Local +ij_java_entity_lhi_suffix = Home +ij_java_entity_li_prefix = Local +ij_java_entity_pk_class = java.lang.String +ij_java_entity_vo_suffix = VO +ij_java_enum_constants_wrap = split_into_lines +ij_java_extends_keyword_wrap = off +ij_java_extends_list_wrap = normal +ij_java_field_annotation_wrap = split_into_lines +ij_java_finally_on_new_line = false +ij_java_for_brace_force = always +ij_java_for_statement_new_line_after_left_paren = false +ij_java_for_statement_right_paren_on_new_line = false +ij_java_for_statement_wrap = normal +ij_java_generate_final_locals = true +ij_java_generate_final_parameters = true +ij_java_if_brace_force = always +ij_java_imports_layout = *, |, javax.**, java.**, |, $* +ij_java_indent_case_from_switch = true +ij_java_insert_inner_class_imports = false +ij_java_insert_override_annotation = true +ij_java_keep_blank_lines_before_right_brace = 1 +ij_java_keep_blank_lines_between_package_declaration_and_header = 2 +ij_java_keep_blank_lines_in_code = 1 +ij_java_keep_blank_lines_in_declarations = 1 +ij_java_keep_control_statement_in_one_line = false +ij_java_keep_first_column_comment = true +ij_java_keep_indents_on_empty_lines = false +ij_java_keep_line_breaks = false +ij_java_keep_multiple_expressions_in_one_line = false +ij_java_keep_simple_blocks_in_one_line = false +ij_java_keep_simple_classes_in_one_line = false +ij_java_keep_simple_lambdas_in_one_line = false +ij_java_keep_simple_methods_in_one_line = false +ij_java_label_indent_absolute = false +ij_java_label_indent_size = 0 +ij_java_lambda_brace_style = end_of_line +ij_java_layout_static_imports_separately = true +ij_java_line_comment_add_space = false +ij_java_line_comment_at_first_column = true +ij_java_message_dd_suffix = EJB +ij_java_message_eb_suffix = Bean +ij_java_method_annotation_wrap = split_into_lines +ij_java_method_brace_style = end_of_line +ij_java_method_call_chain_wrap = normal +ij_java_method_parameters_new_line_after_left_paren = false +ij_java_method_parameters_right_paren_on_new_line = false +ij_java_method_parameters_wrap = normal +ij_java_modifier_list_wrap = false +ij_java_names_count_to_use_import_on_demand = 999999 +ij_java_parameter_annotation_wrap = off +ij_java_parameter_name_prefix = p +ij_java_parentheses_expression_new_line_after_left_paren = false +ij_java_parentheses_expression_right_paren_on_new_line = false +ij_java_place_assignment_sign_on_next_line = false +ij_java_prefer_longer_names = true +ij_java_prefer_parameters_wrap = false +ij_java_repeat_synchronized = true +ij_java_replace_instanceof_and_cast = false +ij_java_replace_null_check = true +ij_java_replace_sum_lambda_with_method_ref = true +ij_java_resource_list_new_line_after_left_paren = false +ij_java_resource_list_right_paren_on_new_line = false +ij_java_resource_list_wrap = off +ij_java_session_dd_suffix = EJB +ij_java_session_eb_suffix = Bean +ij_java_session_hi_suffix = Home +ij_java_session_lhi_prefix = Local +ij_java_session_lhi_suffix = Home +ij_java_session_li_prefix = Local +ij_java_session_si_suffix = Service +ij_java_space_after_closing_angle_bracket_in_type_argument = false +ij_java_space_after_colon = true +ij_java_space_after_comma = true +ij_java_space_after_comma_in_type_arguments = true +ij_java_space_after_for_semicolon = true +ij_java_space_after_quest = true +ij_java_space_after_type_cast = true +ij_java_space_before_annotation_array_initializer_left_brace = false +ij_java_space_before_annotation_parameter_list = false +ij_java_space_before_array_initializer_left_brace = false +ij_java_space_before_catch_keyword = true +ij_java_space_before_catch_left_brace = true +ij_java_space_before_catch_parentheses = true +ij_java_space_before_class_left_brace = true +ij_java_space_before_colon = true +ij_java_space_before_colon_in_foreach = true +ij_java_space_before_comma = false +ij_java_space_before_do_left_brace = true +ij_java_space_before_else_keyword = true +ij_java_space_before_else_left_brace = true +ij_java_space_before_finally_keyword = true +ij_java_space_before_finally_left_brace = true +ij_java_space_before_for_left_brace = true +ij_java_space_before_for_parentheses = true +ij_java_space_before_for_semicolon = false +ij_java_space_before_if_left_brace = true +ij_java_space_before_if_parentheses = true +ij_java_space_before_method_call_parentheses = false +ij_java_space_before_method_left_brace = true +ij_java_space_before_method_parentheses = false +ij_java_space_before_opening_angle_bracket_in_type_parameter = false +ij_java_space_before_quest = true +ij_java_space_before_switch_left_brace = true +ij_java_space_before_switch_parentheses = true +ij_java_space_before_synchronized_left_brace = true +ij_java_space_before_synchronized_parentheses = true +ij_java_space_before_try_left_brace = true +ij_java_space_before_try_parentheses = true +ij_java_space_before_type_parameter_list = false +ij_java_space_before_while_keyword = true +ij_java_space_before_while_left_brace = true +ij_java_space_before_while_parentheses = true +ij_java_space_inside_one_line_enum_braces = false +ij_java_space_within_empty_array_initializer_braces = false +ij_java_space_within_empty_method_call_parentheses = false +ij_java_space_within_empty_method_parentheses = false +ij_java_spaces_around_additive_operators = true +ij_java_spaces_around_assignment_operators = true +ij_java_spaces_around_bitwise_operators = true +ij_java_spaces_around_equality_operators = true +ij_java_spaces_around_lambda_arrow = true +ij_java_spaces_around_logical_operators = true +ij_java_spaces_around_method_ref_dbl_colon = false +ij_java_spaces_around_multiplicative_operators = true +ij_java_spaces_around_relational_operators = true +ij_java_spaces_around_shift_operators = true +ij_java_spaces_around_type_bounds_in_type_parameters = true +ij_java_spaces_around_unary_operator = false +ij_java_spaces_within_angle_brackets = false +ij_java_spaces_within_annotation_parentheses = false +ij_java_spaces_within_array_initializer_braces = false +ij_java_spaces_within_braces = false +ij_java_spaces_within_brackets = false +ij_java_spaces_within_cast_parentheses = false +ij_java_spaces_within_catch_parentheses = false +ij_java_spaces_within_for_parentheses = false +ij_java_spaces_within_if_parentheses = false +ij_java_spaces_within_method_call_parentheses = false +ij_java_spaces_within_method_parentheses = false +ij_java_spaces_within_parentheses = false +ij_java_spaces_within_switch_parentheses = false +ij_java_spaces_within_synchronized_parentheses = false +ij_java_spaces_within_try_parentheses = false +ij_java_spaces_within_while_parentheses = false +ij_java_special_else_if_treatment = true +ij_java_subclass_name_suffix = Impl +ij_java_ternary_operation_signs_on_next_line = false +ij_java_ternary_operation_wrap = normal +ij_java_test_name_suffix = TestCase +ij_java_throws_keyword_wrap = normal +ij_java_throws_list_wrap = normal +ij_java_use_external_annotations = false +ij_java_use_fq_class_names = false +ij_java_use_relative_indents = false +ij_java_use_single_class_imports = true +ij_java_variable_annotation_wrap = off +ij_java_visibility = public +ij_java_while_brace_force = always +ij_java_while_on_new_line = true +ij_java_wrap_comments = false +ij_java_wrap_first_method_in_call_chain = false +ij_java_wrap_long_lines = true + +[.editorconfig] +ij_editorconfig_align_group_field_declarations = false +ij_editorconfig_space_after_colon = false +ij_editorconfig_space_after_comma = true +ij_editorconfig_space_before_colon = false +ij_editorconfig_space_before_comma = false +ij_editorconfig_spaces_around_assignment_operators = true + diff --git a/src/main/java/io/github/grrolland/hcshm/Configuration.java b/src/main/java/io/github/grrolland/hcshm/Configuration.java index 2e3a1a8..469a2e0 100644 --- a/src/main/java/io/github/grrolland/hcshm/Configuration.java +++ b/src/main/java/io/github/grrolland/hcshm/Configuration.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -19,7 +19,7 @@ /** * Configuration Class - * + *

* Get system properties for configuring server * * @author grrolland @@ -38,44 +38,35 @@ public class Configuration { */ public static final int DEFAULT_WORKERS = 1; - /** - * Private default constructor - */ - private Configuration(){ - } - /** * Get the bind port of the server with the ngx-distributed-shm.port system property + * * @return the bind port (4321 by default) */ public static int getPort() { - try - { + try { return Integer.parseInt(System.getProperty("ngx-distributed-shm.port", Integer.toString(DEFAULT_PORT))); - } - catch (NumberFormatException e) - { + } catch (NumberFormatException e) { return DEFAULT_PORT; } } /** * Get the bind port of the server with the ngx-distributed-shm.port system property + * * @return the bind port (4321 by default) */ public static int getWorkers() { - try - { + try { return Integer.parseInt(System.getProperty("ngx-distributed-shm.workers", Integer.toString(DEFAULT_WORKERS))); - } - catch (NumberFormatException e) - { + } catch (NumberFormatException e) { return DEFAULT_WORKERS; } } /** * Get the bind port of the server with the ngx-distributed-shm.port system property + * * @return the bind port (4321 by default) */ public static boolean getEnableJMXCounter() { @@ -84,10 +75,17 @@ public static boolean getEnableJMXCounter() { /** * Get the bind address with the ngx-distributed-shm.bind_address system property + * * @return return th bind address (127.0.0.1 by default) */ public static String getBindAddress() { return System.getProperty("ngx-distributed-shm.bind_address", DEFAULT_BIND_ADDRESS); } + /** + * Private default constructor + */ + private Configuration() { + } + } diff --git a/src/main/java/io/github/grrolland/hcshm/HazelcastInstanceHandler.java b/src/main/java/io/github/grrolland/hcshm/HazelcastInstanceHandler.java index 241b3ec..27f2263 100644 --- a/src/main/java/io/github/grrolland/hcshm/HazelcastInstanceHandler.java +++ b/src/main/java/io/github/grrolland/hcshm/HazelcastInstanceHandler.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -29,15 +29,9 @@ public class HazelcastInstanceHandler { */ private static HazelcastInstance instance = null; - /** - * Private Constructor (utility class) - */ - private HazelcastInstanceHandler() { - - } - /** * Hazelcast instance getter + * * @return the unique hazelcast instance */ public static synchronized HazelcastInstance getInstance() { @@ -47,4 +41,11 @@ public static synchronized HazelcastInstance getInstance() { return instance; } + /** + * Private Constructor (utility class) + */ + private HazelcastInstanceHandler() { + + } + } diff --git a/src/main/java/io/github/grrolland/hcshm/Main.java b/src/main/java/io/github/grrolland/hcshm/Main.java index 7f0a9ac..7454490 100644 --- a/src/main/java/io/github/grrolland/hcshm/Main.java +++ b/src/main/java/io/github/grrolland/hcshm/Main.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -28,7 +28,9 @@ public class Main { /** * Main Method - * @param args command line arguments + * + * @param args + * command line arguments */ public static void main(String[] args) { @@ -36,34 +38,25 @@ public static void main(String[] args) { System.setProperty("vertx.logger-delegate-factory-class-name", "io.vertx.core.logging.SLF4JLogDelegateFactory"); System.setProperty("hazelcast.logging.type", "slf4j"); - final VertxOptions vertxOptions = new VertxOptions() - .setWorkerPoolSize(Configuration.getWorkers()); + final VertxOptions vertxOptions = new VertxOptions().setWorkerPoolSize(Configuration.getWorkers()); if (Configuration.getEnableJMXCounter()) { - vertxOptions.setMetricsOptions( - new DropwizardMetricsOptions(). - setJmxEnabled(true). - setJmxDomain("vertx-metrics") - ); + vertxOptions.setMetricsOptions(new DropwizardMetricsOptions().setJmxEnabled(true).setJmxDomain("vertx-metrics")); } Vertx vertx = Vertx.vertx(vertxOptions); DeploymentOptions options = new DeploymentOptions().setWorker(true).setInstances(Configuration.getWorkers()); - vertx.deployVerticle(ShmTcpServer.class, options, stringAsyncResult -> - Runtime.getRuntime().addShutdownHook(new Thread() - { - /** - * Shutdown Hook : stop hazelcast and vertx - */ - @Override - public void run() - { - HazelcastInstanceHandler.getInstance().shutdown(); - vertx.close(); - } - }) - ); + vertx.deployVerticle(ShmTcpServer.class, options, stringAsyncResult -> Runtime.getRuntime().addShutdownHook(new Thread() { + /** + * Shutdown Hook : stop hazelcast and vertx + */ + @Override + public void run() { + HazelcastInstanceHandler.getInstance().shutdown(); + vertx.close(); + } + })); } } diff --git a/src/main/java/io/github/grrolland/hcshm/ProtocolException.java b/src/main/java/io/github/grrolland/hcshm/ProtocolException.java index 79667bf..5cf5d43 100644 --- a/src/main/java/io/github/grrolland/hcshm/ProtocolException.java +++ b/src/main/java/io/github/grrolland/hcshm/ProtocolException.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ diff --git a/src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java b/src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java index 1e10cba..4382a9e 100644 --- a/src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java +++ b/src/main/java/io/github/grrolland/hcshm/ShmProtocolHandler.java @@ -1,31 +1,30 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package io.github.grrolland.hcshm; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import io.github.grrolland.hcshm.commands.Command; import io.github.grrolland.hcshm.commands.CommandFactory; import io.vertx.core.Handler; import io.vertx.core.buffer.Buffer; import io.vertx.core.net.NetSocket; import io.vertx.core.parsetools.RecordParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Vertx Protocol Handler @@ -33,7 +32,6 @@ * @author grrolland */ public class ShmProtocolHandler implements Handler { - Logger logger = LoggerFactory.getLogger(ShmProtocolHandler.class); /** * Protocol Encoding */ @@ -46,18 +44,23 @@ public class ShmProtocolHandler implements Handler { * Protocol Command Line Delimiter */ public static final String COMMAND_LINE_DELIMITER = " "; + /** - * Vertx NetSocket + * Logger */ - private NetSocket socket = null; + private final Logger logger = LoggerFactory.getLogger(ShmProtocolHandler.class); /** - * Command Factory + * Vertx NetSocket */ - private CommandFactory commandFactory = null; + private final NetSocket socket; /** * Vertx record Parser */ - private RecordParser parser = null; + private final RecordParser parser; + /** + * Command Factory + */ + private CommandFactory commandFactory = null; /** * Expected Protocol Decoding Mode */ @@ -67,33 +70,39 @@ public class ShmProtocolHandler implements Handler { */ private Command currentCommand; - /** - * Protocol Handler Instance Factory Method - * @param socket vertx socket - * @param service shm service - */ - public static void create(NetSocket socket, ShmService service) { - new ShmProtocolHandler(socket,service); - } - /** * Public Constructor - * @param socket vertx socket - * @param service shm service + * + * @param socket + * vertx socket + * @param service + * shm service */ public ShmProtocolHandler(NetSocket socket, ShmService service) { this.socket = socket; this.parser = RecordParser.newDelimited(PROTOCOL_DELIMITER, socket); - this.parser.endHandler(v -> socket.close()) - .exceptionHandler(t -> socket.close()) - .handler(this); + this.parser.endHandler(v -> socket.close()).exceptionHandler(t -> socket.close()).handler(this); this.commandFactory = new CommandFactory(); this.commandFactory.setService(service); } + /** + * Protocol Handler Instance Factory Method + * + * @param socket + * vertx socket + * @param service + * shm service + */ + public static void create(NetSocket socket, ShmService service) { + new ShmProtocolHandler(socket, service); + } + /** * Protocol Handler implementation - * @param buffer vertx buffer + * + * @param buffer + * vertx buffer */ @Override public void handle(Buffer buffer) { diff --git a/src/main/java/io/github/grrolland/hcshm/ShmRegionLocator.java b/src/main/java/io/github/grrolland/hcshm/ShmRegionLocator.java index 9716c9e..8329dcd 100644 --- a/src/main/java/io/github/grrolland/hcshm/ShmRegionLocator.java +++ b/src/main/java/io/github/grrolland/hcshm/ShmRegionLocator.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -28,8 +28,11 @@ public class ShmRegionLocator implements Serializable { /** * Get the map form the key name - * @param key the key - * @param hazelcast hazelcast instance + * + * @param key + * the key + * @param hazelcast + * hazelcast instance * @return return the named IMap, if no region in the key return the default IMap */ public IMap getMap(final HazelcastInstance hazelcast, final String key) { @@ -38,22 +41,26 @@ public IMap getMap(final HazelcastInstance hazelcast, final St /** * Get the map form the region name - * @param region the key - * @param hazelcast hazelcast instance + * + * @param region + * the key + * @param hazelcast + * hazelcast instance * @return return the named IMap, if no region return the default IMap */ public IMap getMapRegion(final HazelcastInstance hazelcast, final String region) { if (null != region) { return hazelcast.getMap(region); - } - else { + } else { return hazelcast.getMap("shmmap"); } } /** * Get the region from the key - * @param key the key + * + * @param key + * the key * @return the region or null if no region */ private String getRegion(String key) { diff --git a/src/main/java/io/github/grrolland/hcshm/ShmTcpServer.java b/src/main/java/io/github/grrolland/hcshm/ShmTcpServer.java index 0e5fd13..ca2a88a 100644 --- a/src/main/java/io/github/grrolland/hcshm/ShmTcpServer.java +++ b/src/main/java/io/github/grrolland/hcshm/ShmTcpServer.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -23,8 +23,8 @@ /** * SHM TCP Server - * @author grrolland * + * @author grrolland */ public class ShmTcpServer extends AbstractVerticle { @@ -32,7 +32,7 @@ public class ShmTcpServer extends AbstractVerticle { * The Shared Memory * Service */ - private ShmService service = null; + private final ShmService service; /** * Public Constructor diff --git a/src/main/java/io/github/grrolland/hcshm/commands/CommandFactory.java b/src/main/java/io/github/grrolland/hcshm/commands/CommandFactory.java index d9353a6..6b227d0 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/CommandFactory.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/CommandFactory.java @@ -1,23 +1,22 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package io.github.grrolland.hcshm.commands; - import io.github.grrolland.hcshm.ShmService; /** @@ -32,7 +31,9 @@ public class CommandFactory { /** * Set the SHM Service - * @param service the service + * + * @param service + * the service */ public void setService(ShmService service) { this.service = service; @@ -40,7 +41,9 @@ public void setService(ShmService service) { /** * Get the command from the protocol verb - * @param commandTokens the command tokens + * + * @param commandTokens + * the command tokens * @return the corresponding command */ public Command get(String[] commandTokens) { @@ -74,18 +77,17 @@ public Command get(String[] commandTokens) { return command; } - /** * Get Command from command token - * @param commandTokens the command tokens + * + * @param commandTokens + * the command tokens * @return the command */ private CommandVerb getCommand(String[] commandTokens) { try { return CommandVerb.valueOf(commandTokens[0].toUpperCase()); - } - catch (IllegalArgumentException e) - { + } catch (IllegalArgumentException e) { return CommandVerb.UNKNOWN; } } diff --git a/src/main/java/io/github/grrolland/hcshm/commands/CommandVerb.java b/src/main/java/io/github/grrolland/hcshm/commands/CommandVerb.java index db98cad..e298310 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/CommandVerb.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/CommandVerb.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -53,4 +53,4 @@ public enum CommandVerb { * Unknown Command */ UNKNOWN -} \ No newline at end of file +} diff --git a/src/main/java/io/github/grrolland/hcshm/commands/DeleteCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/DeleteCommand.java index c40cdc4..cf8e878 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/DeleteCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/DeleteCommand.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -27,7 +27,9 @@ public class DeleteCommand extends Command { /** * Default Constructor - * @param service the shm service + * + * @param service + * the shm service */ DeleteCommand(ShmService service) { super(service); @@ -35,20 +37,19 @@ public class DeleteCommand extends Command { /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) { final StringBuilder response = new StringBuilder(); - try - { + try { assertTokens(commandTokens, 2); String key = getKey(commandTokens[1]); getService().delete(key); writeDone(response); - } - catch (ProtocolException e) - { + } catch (ProtocolException e) { writeMalformedRequest(response); } return response.toString(); diff --git a/src/main/java/io/github/grrolland/hcshm/commands/FlushAllCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/FlushAllCommand.java index c185a91..030c44a 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/FlushAllCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/FlushAllCommand.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -27,7 +27,9 @@ public class FlushAllCommand extends Command { /** * Default Constructor - * @param service the shm service + * + * @param service + * the shm service */ FlushAllCommand(ShmService service) { super(service); @@ -35,20 +37,19 @@ public class FlushAllCommand extends Command { /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) { final StringBuilder response = new StringBuilder(); - try - { + try { assertTokens(commandTokens, 1, 2); String region = getKey(commandTokens.length == 1 ? null : commandTokens[1]); getService().flushall(region); writeDone(response); - } - catch (ProtocolException e) - { + } catch (ProtocolException e) { writeMalformedRequest(response); } return response.toString(); diff --git a/src/main/java/io/github/grrolland/hcshm/commands/GetCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/GetCommand.java index ebbaccf..84633b3 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/GetCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/GetCommand.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -27,7 +27,9 @@ public class GetCommand extends Command { /** * Default Constructor - * @param service the shm service + * + * @param service + * the shm service */ GetCommand(ShmService service) { super(service); @@ -35,13 +37,14 @@ public class GetCommand extends Command { /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) { final StringBuilder response = new StringBuilder(); - try - { + try { assertTokens(commandTokens, 2); String key = getKey(commandTokens[1]); String value = getService().get(key); @@ -49,14 +52,10 @@ public String execute(String[] commandTokens) { writeLen(response, value); writeValue(response, value); writeDone(response); - } - else - { + } else { writeNotFound(response); } - } - catch (ProtocolException e) - { + } catch (ProtocolException e) { writeMalformedRequest(response); } return response.toString(); diff --git a/src/main/java/io/github/grrolland/hcshm/commands/QuitCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/QuitCommand.java index be7d06c..5b4c5b8 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/QuitCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/QuitCommand.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -31,27 +31,28 @@ public class QuitCommand extends Command { private boolean isTermination = true; /** - * Default Constructor - * @param service the shm service + * Get if this command is a termination command and the socket must be closed after the execution + * + * @return true if this is a termination command */ - QuitCommand(ShmService service) { - super(service); + @Override + public boolean isTerminationCommand() { + return isTermination; } /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) { final StringBuilder response = new StringBuilder(); - try - { + try { assertTokens(commandTokens, 1); writeDone(response); - } - catch (ProtocolException e) - { + } catch (ProtocolException e) { writeMalformedRequest(response); isTermination = false; } @@ -59,11 +60,12 @@ public String execute(String[] commandTokens) { } /** - * Get if this command is a termination command and the socket must be closed after the execution - * @return true if this is a termination command + * Default Constructor + * + * @param service + * the shm service */ - @Override - public boolean isTerminationCommand() { - return isTermination; + QuitCommand(ShmService service) { + super(service); } } diff --git a/src/main/java/io/github/grrolland/hcshm/commands/TouchCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/TouchCommand.java index 17b3c67..1814c48 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/TouchCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/TouchCommand.java @@ -27,7 +27,9 @@ public class TouchCommand extends Command { /** * Default Constructor - * @param service the shm service + * + * @param service + * the shm service */ TouchCommand(ShmService service) { super(service); @@ -35,7 +37,9 @@ public class TouchCommand extends Command { /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) { diff --git a/src/main/java/io/github/grrolland/hcshm/commands/UnknownCommand.java b/src/main/java/io/github/grrolland/hcshm/commands/UnknownCommand.java index 61c12a4..853d376 100644 --- a/src/main/java/io/github/grrolland/hcshm/commands/UnknownCommand.java +++ b/src/main/java/io/github/grrolland/hcshm/commands/UnknownCommand.java @@ -1,17 +1,17 @@ /** * ngx-distributed-shm * Copyright (C) 2018 Flu.Tech - * + *

* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + *

* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + *

* You should have received a copy of the GNU General Public License * along with this program. If not, see . */ @@ -26,7 +26,9 @@ public class UnknownCommand extends Command { /** * Default Constructor - * @param service the shm service + * + * @param service + * the shm service */ UnknownCommand(ShmService service) { super(service); @@ -34,7 +36,9 @@ public class UnknownCommand extends Command { /** * Execute the command - * @param commandTokens the protocol tokens argument of the command + * + * @param commandTokens + * the protocol tokens argument of the command * @return the result of the command 'protocol encoded' */ public String execute(String[] commandTokens) {