diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index b846bef..ec3a5b6 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,281 +1,5 @@ -#Fri Dec 09 21:12:08 JST 2011 -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.6 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.6 -org.eclipse.jdt.core.formatter.align_type_members_on_columns=false -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_assignment=0 -org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16 -org.eclipse.jdt.core.formatter.alignment_for_compact_if=16 -org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80 -org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 -org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 -org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 -org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16 -org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16 -org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16 -org.eclipse.jdt.core.formatter.blank_lines_after_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_after_package=1 -org.eclipse.jdt.core.formatter.blank_lines_before_field=0 -org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0 -org.eclipse.jdt.core.formatter.blank_lines_before_imports=1 -org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1 -org.eclipse.jdt.core.formatter.blank_lines_before_method=1 -org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1 -org.eclipse.jdt.core.formatter.blank_lines_before_package=0 -org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1 -org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1 -org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line -org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false -org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false -org.eclipse.jdt.core.formatter.comment.format_block_comments=true -org.eclipse.jdt.core.formatter.comment.format_header=false -org.eclipse.jdt.core.formatter.comment.format_html=true -org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=true -org.eclipse.jdt.core.formatter.comment.format_source_code=true -org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true -org.eclipse.jdt.core.formatter.comment.indent_root_tags=true -org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert -org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert -org.eclipse.jdt.core.formatter.comment.line_length=80 -org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries=true -org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries=true -org.eclipse.jdt.core.formatter.compact_else_if=true -org.eclipse.jdt.core.formatter.continuation_indentation=2 -org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2 -org.eclipse.jdt.core.formatter.disabling_tag=@formatter\:off -org.eclipse.jdt.core.formatter.enabling_tag=@formatter\:on -org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false -org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true -org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true -org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_empty_lines=false -org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true -org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false -org.eclipse.jdt.core.formatter.indentation.size=8 -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert -org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_after_label=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert -org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert -org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert -org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert -org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert -org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert -org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert -org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert -org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert -org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert -org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert -org.eclipse.jdt.core.formatter.join_lines_in_comments=true -org.eclipse.jdt.core.formatter.join_wrapped_lines=true -org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false -org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false -org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false -org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=80 -org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false -org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false -org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 -org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1 -org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true -org.eclipse.jdt.core.formatter.tabulation.char=space -org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_on_off_tags=false -org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false -org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true -org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested=true +#Wed Mar 05 17:28:34 JST 2014 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.source=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 diff --git a/src/main/java/org/msgpack/rpc/Client.java b/src/main/java/org/msgpack/rpc/Client.java index 7864756..0496eec 100644 --- a/src/main/java/org/msgpack/rpc/Client.java +++ b/src/main/java/org/msgpack/rpc/Client.java @@ -45,9 +45,10 @@ public Client(String host, int port, EventLoop loop) throws UnknownHostException { this(new IPAddress(host, port), new TcpClientConfig(), loop); } - public Client(String host, int port, EventLoop loop,Reflect reflect) + + public Client(String host, int port, EventLoop loop, Reflect reflect) throws UnknownHostException { - this(new IPAddress(host, port), new TcpClientConfig(), loop,reflect); + this(new IPAddress(host, port), new TcpClientConfig(), loop, reflect); } public Client(String host, int port, ClientConfig config, EventLoop loop) @@ -70,16 +71,18 @@ public Client(InetSocketAddress address, EventLoop loop) { public Client(InetSocketAddress address, ClientConfig config, EventLoop loop) { this(new IPAddress(address), config, loop); } - public Client(InetSocketAddress address, ClientConfig config, EventLoop loop,Reflect reflect) { - this(new IPAddress(address), config, loop,reflect); + + public Client(InetSocketAddress address, ClientConfig config, EventLoop loop, Reflect reflect) { + this(new IPAddress(address), config, loop, reflect); } Client(Address address, ClientConfig config, EventLoop loop) { super(address, config, loop); startTimer(); } + Client(Address address, ClientConfig config, EventLoop loop, Reflect reflect) { - super(address, config, loop,reflect); + super(address, config, loop, reflect); startTimer(); } diff --git a/src/main/java/org/msgpack/rpc/Server.java b/src/main/java/org/msgpack/rpc/Server.java index ba027d5..e0ddb10 100644 --- a/src/main/java/org/msgpack/rpc/Server.java +++ b/src/main/java/org/msgpack/rpc/Server.java @@ -23,12 +23,9 @@ import org.msgpack.rpc.builder.DefaultDispatcherBuilder; import org.msgpack.rpc.builder.DispatcherBuilder; -import org.msgpack.rpc.reflect.Reflect; -import org.msgpack.type.NilValue; import org.msgpack.type.Value; import org.msgpack.rpc.address.IPAddress; import org.msgpack.rpc.dispatcher.Dispatcher; -import org.msgpack.rpc.dispatcher.MethodDispatcher; import org.msgpack.rpc.config.ClientConfig; import org.msgpack.rpc.config.ServerConfig; import org.msgpack.rpc.config.TcpServerConfig; @@ -76,7 +73,7 @@ public void serve(Dispatcher dp) { } public void serve(Object handler) { - this.dp = dispatcherBuilder.build(handler,this.getEventLoop().getMessagePack()); + this.dp = dispatcherBuilder.build(handler, this.getEventLoop().getMessagePack()); } public void listen(String host, int port) throws UnknownHostException, IOException { @@ -112,10 +109,10 @@ public void onRequest(MessageSendable channel, int msgid, String method, Value a } catch (Exception e) { logger.error("Unexpected error occured while calling " + method, e); // FIXME request.sendError("RemoteError", e.getMessage()); - if(e.getMessage() == null) + if (e.getMessage() == null) { request.sendError(""); - }else{ + } else { request.sendError(e.getMessage()); } } diff --git a/src/main/java/org/msgpack/rpc/Session.java b/src/main/java/org/msgpack/rpc/Session.java index b3cf986..4a6be80 100644 --- a/src/main/java/org/msgpack/rpc/Session.java +++ b/src/main/java/org/msgpack/rpc/Session.java @@ -46,10 +46,10 @@ public class Session { private Map reqtable = new HashMap(); Session(Address address, ClientConfig config, EventLoop loop) { - this(address,config,loop,new Reflect(loop.getMessagePack())); + this(address, config, loop, new Reflect(loop.getMessagePack())); } - Session(Address address, ClientConfig config, EventLoop loop,Reflect reflect) { + Session(Address address, ClientConfig config, EventLoop loop, Reflect reflect) { this.address = address; this.loop = loop; this.requestTimeout = config.getRequestTimeout(); @@ -87,16 +87,16 @@ public Value callApply(String method, Object[] args) { Future f = sendRequest(method, args); while (true) { try { - if(requestTimeout <= 0){ + if (requestTimeout <= 0) { return f.get(); - }else{ + } else { return f.get(requestTimeout, TimeUnit.SECONDS); } } catch (InterruptedException e) { // FIXME } catch (TimeoutException e) { // FIXME - throw new RuntimeException("Time out to call method:" + method,e); + throw new RuntimeException("Time out to call method:" + method, e); } } diff --git a/src/main/java/org/msgpack/rpc/builder/DefaultDispatcherBuilder.java b/src/main/java/org/msgpack/rpc/builder/DefaultDispatcherBuilder.java index dc2d0b1..abddeae 100644 --- a/src/main/java/org/msgpack/rpc/builder/DefaultDispatcherBuilder.java +++ b/src/main/java/org/msgpack/rpc/builder/DefaultDispatcherBuilder.java @@ -16,4 +16,3 @@ public Dispatcher build(Object handler, MessagePack messagePack) { new Reflect(messagePack), handler); } } - diff --git a/src/main/java/org/msgpack/rpc/builder/DispatcherBuilder.java b/src/main/java/org/msgpack/rpc/builder/DispatcherBuilder.java index edfbd9f..32b0df0 100644 --- a/src/main/java/org/msgpack/rpc/builder/DispatcherBuilder.java +++ b/src/main/java/org/msgpack/rpc/builder/DispatcherBuilder.java @@ -9,6 +9,6 @@ */ public interface DispatcherBuilder { - public Dispatcher build(Object handler,MessagePack messagePack) ; + public Dispatcher build(Object handler, MessagePack messagePack); } diff --git a/src/main/java/org/msgpack/rpc/builder/StopWatchDispatcherBuilder.java b/src/main/java/org/msgpack/rpc/builder/StopWatchDispatcherBuilder.java index cdb5521..b436c54 100644 --- a/src/main/java/org/msgpack/rpc/builder/StopWatchDispatcherBuilder.java +++ b/src/main/java/org/msgpack/rpc/builder/StopWatchDispatcherBuilder.java @@ -21,12 +21,12 @@ public void setVerbose(boolean verbose) { this.verbose = verbose; } - public StopWatchDispatcherBuilder withVerboseOutput(boolean verbose){ + public StopWatchDispatcherBuilder withVerboseOutput(boolean verbose) { this.verbose = verbose; return this; } - public StopWatchDispatcherBuilder(DispatcherBuilder baseBuilder){ + public StopWatchDispatcherBuilder(DispatcherBuilder baseBuilder) { this.baseBuilder = baseBuilder; } @@ -37,6 +37,6 @@ public Dispatcher decorate(Dispatcher innerDispatcher) { } public Dispatcher build(Object handler, MessagePack messagePack) { - return decorate(baseBuilder.build(handler,messagePack)); + return decorate(baseBuilder.build(handler, messagePack)); } } diff --git a/src/main/java/org/msgpack/rpc/dispatcher/StopWatchDispatcher.java b/src/main/java/org/msgpack/rpc/dispatcher/StopWatchDispatcher.java index 39ff87f..ac5b1f5 100644 --- a/src/main/java/org/msgpack/rpc/dispatcher/StopWatchDispatcher.java +++ b/src/main/java/org/msgpack/rpc/dispatcher/StopWatchDispatcher.java @@ -32,17 +32,17 @@ public StopWatchDispatcher(Dispatcher inner) { } public void dispatch(Request request) throws Exception { - if(verbose){ - logger.info(String.format( "Begin dispatching %s with args %s",request.getMethodName(),request.getArguments().toString())); + if (verbose) { + logger.info(String.format("Begin dispatching %s with args %s", request.getMethodName(), request.getArguments().toString())); } long start = System.currentTimeMillis(); - try{ + try { innerDispatcher.dispatch(request); long diff = System.currentTimeMillis() - start; - logger.info(String.format("Dispatch %s in %s msecs",request.getMethodName(),diff)); - }catch(Exception e){ + logger.info(String.format("Dispatch %s in %s msecs", request.getMethodName(), diff)); + } catch (Exception e) { long diff = System.currentTimeMillis() - start; - logger.info(String.format("%s : %s while dispatching %s,(in %s msecs)",e.getClass().getSimpleName(), e.getMessage(), request.getMethodName(),diff)); + logger.info(String.format("%s : %s while dispatching %s,(in %s msecs)", e.getClass().getSimpleName(), e.getMessage(), request.getMethodName(), diff)); throw e; } } diff --git a/src/main/java/org/msgpack/rpc/loop/netty/MessagePackStreamDecoder.java b/src/main/java/org/msgpack/rpc/loop/netty/MessagePackStreamDecoder.java index edfdb7e..9d119b1 100644 --- a/src/main/java/org/msgpack/rpc/loop/netty/MessagePackStreamDecoder.java +++ b/src/main/java/org/msgpack/rpc/loop/netty/MessagePackStreamDecoder.java @@ -52,12 +52,12 @@ protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteArrayInputStream stream = new ByteArrayInputStream(bytes, offset, length); int startAvailable = stream.available(); - try{ + try { Unpacker unpacker = msgpack.createUnpacker(stream); Value v = unpacker.readValue(); source.skipBytes(startAvailable - stream.available()); return v; - }catch( EOFException e ){ + } catch (EOFException e) { // not enough buffers. // So retry reading source.resetReaderIndex(); diff --git a/src/main/java/org/msgpack/rpc/message/NotifyMessage.java b/src/main/java/org/msgpack/rpc/message/NotifyMessage.java index c786d51..7d33e61 100644 --- a/src/main/java/org/msgpack/rpc/message/NotifyMessage.java +++ b/src/main/java/org/msgpack/rpc/message/NotifyMessage.java @@ -20,8 +20,6 @@ import java.io.IOException; import org.msgpack.MessagePackable; import org.msgpack.packer.Packer; -import org.msgpack.type.Value; -import org.msgpack.MessageTypeException; import org.msgpack.unpacker.Unpacker; public class NotifyMessage implements MessagePackable { diff --git a/src/main/java/org/msgpack/rpc/message/RequestMessage.java b/src/main/java/org/msgpack/rpc/message/RequestMessage.java index 4d9d437..fbda611 100644 --- a/src/main/java/org/msgpack/rpc/message/RequestMessage.java +++ b/src/main/java/org/msgpack/rpc/message/RequestMessage.java @@ -20,8 +20,6 @@ import java.io.IOException; import org.msgpack.MessagePackable; import org.msgpack.packer.Packer; -import org.msgpack.type.Value; -import org.msgpack.MessageTypeException; import org.msgpack.unpacker.Unpacker; public class RequestMessage implements MessagePackable { diff --git a/src/main/java/org/msgpack/rpc/message/ResponseMessage.java b/src/main/java/org/msgpack/rpc/message/ResponseMessage.java index d333619..3d9ef09 100644 --- a/src/main/java/org/msgpack/rpc/message/ResponseMessage.java +++ b/src/main/java/org/msgpack/rpc/message/ResponseMessage.java @@ -20,9 +20,6 @@ import java.io.IOException; import org.msgpack.*; import org.msgpack.packer.Packer; -import org.msgpack.template.Template; -import org.msgpack.type.Value; -import org.msgpack.type.ValueFactory; import org.msgpack.unpacker.Unpacker; public class ResponseMessage implements MessagePackable { diff --git a/src/main/java/org/msgpack/rpc/reflect/InvokerBuilder.java b/src/main/java/org/msgpack/rpc/reflect/InvokerBuilder.java index d53a7f0..e272688 100644 --- a/src/main/java/org/msgpack/rpc/reflect/InvokerBuilder.java +++ b/src/main/java/org/msgpack/rpc/reflect/InvokerBuilder.java @@ -25,7 +25,6 @@ import org.msgpack.*; import org.msgpack.template.*; import org.msgpack.rpc.Callback; -import org.msgpack.rpc.Request; public abstract class InvokerBuilder { public static class ArgumentEntry { @@ -181,14 +180,11 @@ static ArgumentEntry[] readArgumentEntries(Method targetMethod, /* * index: * - * @Index(0) int field_a; // 0 - * int field_b; // 1 + * @Index(0) int field_a; // 0 int field_b; // 1 * - * @Index(3) int field_c; // 3 - * int field_d; // 4 + * @Index(3) int field_c; // 3 int field_d; // 4 * - * @Index(2) int field_e; // 2 - * int field_f; // 5 + * @Index(2) int field_e; // 2 int field_f; // 5 */ List indexed = new ArrayList(); int maxIndex = -1; diff --git a/src/main/java/org/msgpack/rpc/reflect/JavassistInvokerBuilder.java b/src/main/java/org/msgpack/rpc/reflect/JavassistInvokerBuilder.java index 2a32e21..1d84fad 100644 --- a/src/main/java/org/msgpack/rpc/reflect/JavassistInvokerBuilder.java +++ b/src/main/java/org/msgpack/rpc/reflect/JavassistInvokerBuilder.java @@ -37,15 +37,13 @@ import org.msgpack.template.Template; import org.msgpack.rpc.Request; import org.msgpack.rpc.reflect.ReflectionInvokerBuilder.ReflectionArgumentEntry; -import org.msgpack.template.TemplateRegistry; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class JavassistInvokerBuilder extends InvokerBuilder { private static Logger LOG = LoggerFactory.getLogger(JavassistInvokerBuilder.class); - - protected abstract static class AbstractInvoker implements Invoker { + protected abstract static class AbstractInvoker implements Invoker { protected Method method; protected int parameterLength; protected ReflectionArgumentEntry[] entries; @@ -58,17 +56,17 @@ public AbstractInvoker(Method method, ReflectionArgumentEntry[] entries, boolean this.entries = entries; this.async = async; this.minimumArrayLength = 0; - for(int i=0; i < entries.length; i++) { + for (int i = 0; i < entries.length; i++) { ReflectionArgumentEntry e = entries[i]; - if(!e.isOptional()){//e.isRequired() || e.isNullable()) { - this.minimumArrayLength = i+1; + if (!e.isOptional()) {// e.isRequired() || e.isNullable()) { + this.minimumArrayLength = i + 1; } } } public void invoke(Object target, Request request) throws Exception { Object[] params = new Object[parameterLength]; - if(async) { + if (async) { params[0] = request; } @@ -79,42 +77,42 @@ public void invoke(Object target, Request request) throws Exception { Value[] array = args.asArrayValue().getElementArray(); int length = array.length; - if(length < minimumArrayLength) { + if (length < minimumArrayLength) { throw new MessageTypeException(); } int i; - for(i = 0; i < minimumArrayLength; i++) { + for (i = 0; i < minimumArrayLength; i++) { ReflectionArgumentEntry e = entries[i]; - if(!e.isAvailable()) { + if (!e.isAvailable()) { continue; } Value obj = array[i]; - if(obj.isNilValue()) { - if(e.isRequired()) { + if (obj.isNilValue()) { + if (e.isRequired()) { // Required + nil => exception throw new MessageTypeException(); - } else if(e.isOptional()) { + } else if (e.isOptional()) { // Optional + nil => keep default value - } else { // Nullable + } else { // Nullable // Nullable + nil => set null e.setNull(params); } } else { - e.convert(params, obj); + e.convert(params, obj); } } int max = length < entries.length ? length : entries.length; - for(; i < max; i++) { + for (; i < max; i++) { ReflectionArgumentEntry e = entries[i]; - if(!e.isAvailable()) { + if (!e.isAvailable()) { continue; } Value obj = array[i]; - if(obj.isNilValue()) { + if (obj.isNilValue()) { // this is Optional field becaue i >= minimumArrayLength // Optional + nil => keep default value } else { @@ -125,14 +123,14 @@ public void invoke(Object target, Request request) throws Exception { // latter entries are all Optional + nil => keep default value } catch (MessageTypeException e) { - LOG.error("Fail to invoke",e); + LOG.error("Fail to invoke", e); } catch (Exception e) { - LOG.error("Fail to invoke",e); + LOG.error("Fail to invoke", e); } try { Object result = invoke0(target, params); - if(!async) { + if (!async) { request.sendResult(result); } } catch (Throwable t) { @@ -141,7 +139,7 @@ public void invoke(Object target, Request request) throws Exception { } protected abstract Object invoke0(Object target, Object[] params) throws Throwable; - } + } protected ClassPool pool; @@ -161,38 +159,38 @@ void addClassLoader(ClassLoader cl) { } public Invoker buildInvoker(Method m, ArgumentEntry[] entries, boolean async) { - ReflectionArgumentEntry[] res = new ReflectionArgumentEntry[entries.length]; - for(int i=0; i < entries.length; i++) { - ArgumentEntry e = entries[i]; - Class type = e.getType(); - if(!e.isAvailable()) { - res[i] = new ReflectionInvokerBuilder.NullArgumentEntry(e); - } else if(type.equals(boolean.class)) { - res[i] = new ReflectionInvokerBuilder.BooleanArgumentEntry(e); - } else if(type.equals(byte.class)) { - res[i] = new ReflectionInvokerBuilder.ByteArgumentEntry(e); - } else if(type.equals(short.class)) { - res[i] = new ReflectionInvokerBuilder.ShortArgumentEntry(e); - } else if(type.equals(int.class)) { - res[i] = new ReflectionInvokerBuilder.IntArgumentEntry(e); - } else if(type.equals(long.class)) { - res[i] = new ReflectionInvokerBuilder.LongArgumentEntry(e); - } else if(type.equals(float.class)) { - res[i] = new ReflectionInvokerBuilder.FloatArgumentEntry(e); - } else if(type.equals(double.class)) { - res[i] = new ReflectionInvokerBuilder.DoubleArgumentEntry(e); - } else { + ReflectionArgumentEntry[] res = new ReflectionArgumentEntry[entries.length]; + for (int i = 0; i < entries.length; i++) { + ArgumentEntry e = entries[i]; + Class type = e.getType(); + if (!e.isAvailable()) { + res[i] = new ReflectionInvokerBuilder.NullArgumentEntry(e); + } else if (type.equals(boolean.class)) { + res[i] = new ReflectionInvokerBuilder.BooleanArgumentEntry(e); + } else if (type.equals(byte.class)) { + res[i] = new ReflectionInvokerBuilder.ByteArgumentEntry(e); + } else if (type.equals(short.class)) { + res[i] = new ReflectionInvokerBuilder.ShortArgumentEntry(e); + } else if (type.equals(int.class)) { + res[i] = new ReflectionInvokerBuilder.IntArgumentEntry(e); + } else if (type.equals(long.class)) { + res[i] = new ReflectionInvokerBuilder.LongArgumentEntry(e); + } else if (type.equals(float.class)) { + res[i] = new ReflectionInvokerBuilder.FloatArgumentEntry(e); + } else if (type.equals(double.class)) { + res[i] = new ReflectionInvokerBuilder.DoubleArgumentEntry(e); + } else { Type t = e.getGenericType(); - Template tmpl = messagePack.lookup(t); - if(tmpl == null){ - messagePack.register((Class)t); + Template tmpl = messagePack.lookup(t); + if (tmpl == null) { + messagePack.register((Class) t); tmpl = messagePack.lookup(t); } - res[i] = new ReflectionInvokerBuilder.ObjectArgumentEntry(messagePack,e, tmpl); - } - } - return buildInvoker(m, res, async); - } + res[i] = new ReflectionInvokerBuilder.ObjectArgumentEntry(messagePack, e, tmpl); + } + } + return buildInvoker(m, res, async); + } private Invoker buildInvoker(Method m, ReflectionArgumentEntry[] res, boolean async) { try { @@ -202,16 +200,19 @@ private Invoker buildInvoker(Method m, ReflectionArgumentEntry[] res, boolean as } catch (Throwable t) { t.printStackTrace(); // FIXME - // buildInvoker method should throw several exception (non-runtime exception) + // buildInvoker method should throw several exception (non-runtime + // exception) throw new RuntimeException(new NotBuiltException( - "invoker: " + m.getName() + " in " + m.getDeclaringClass().getName(), t)); + "invoker: " + m.getName() + " in " + + m.getDeclaringClass().getName(), t)); } } private CtClass buildInvokerCtClass(Method m, ReflectionArgumentEntry[] res) throws CannotCompileException, NotFoundException { Class c = m.getDeclaringClass(); - String invokerClassName = c.getName() + "_$$_" + m.getName() + "_$$_JavassistInvoker" + nextSeqId(); + String invokerClassName = c.getName() + "_$$_" + m.getName() + + "_$$_JavassistInvoker" + nextSeqId(); CtClass invokerCtClass = pool.makeClass(invokerClassName); buildSuperclass(invokerCtClass); buildConstructor(invokerCtClass); @@ -251,7 +252,7 @@ private void buildInvoke0Method(CtClass invokerCtClass, Method m, ReflectionArgu }; CtClass[] exceptTypes = new CtClass[] { pool.get(Throwable.class.getName()) }; try { - CtMethod newCtMethod = CtNewMethod.make(mod, retType, mname, + CtMethod newCtMethod = CtNewMethod.make(mod, retType, mname, paramTypes, exceptTypes, mbody, invokerCtClass); invokerCtClass.addMethod(newCtMethod); } catch (CannotCompileException e) { @@ -269,7 +270,8 @@ private String buildInvoke0MethodBody(Method m, ReflectionArgumentEntry[] res) { boolean isPrimType = paramTypes[i].isPrimitive(); if (isPrimType) { // ((Integer) $2[0]).intValue() buildString("((%s) $2[%d]).%s()", - new Object[] { toWrapperType(type).getName(), i, toPrimTypeMethod(type) }); + new Object[] { toWrapperType(type).getName(), i, + toPrimTypeMethod(type) }); } else { // (Integer) $2[0] buildString("(%s) $2[%d]", new Object[] { type.getName(), i }); } @@ -278,7 +280,7 @@ private String buildInvoke0MethodBody(Method m, ReflectionArgumentEntry[] res) { } } String args = getBuiltString(); - + boolean isVoidType = m.getReturnType().equals(void.class); boolean isPrimType = m.getReturnType().isPrimitive(); resetStringBuilder(); @@ -290,7 +292,8 @@ private String buildInvoke0MethodBody(Method m, ReflectionArgumentEntry[] res) { buildString("new %s(", new Object[] { toWrapperType(m.getReturnType()).getName() }); } } - buildString("((%s) $1).%s(%s)", new Object[] { m.getDeclaringClass().getName(), m.getName(), args }); + buildString("((%s) $1).%s(%s)", new Object[] { + m.getDeclaringClass().getName(), m.getName(), args }); if (!isVoidType && isPrimType) { buildString(")"); } @@ -349,8 +352,9 @@ private Class buildInvokerClass(CtClass invokerCtClass) private Invoker newInvokerInstance(Class c, Method m, ReflectionArgumentEntry[] res, boolean async) throws Exception { Constructor cons = c.getConstructor( - new Class[] { Method.class, ReflectionArgumentEntry[].class, boolean.class } - ); + new Class[] { Method.class, ReflectionArgumentEntry[].class, + boolean.class } + ); return cons.newInstance(new Object[] { m, res, async }); } @@ -367,7 +371,7 @@ protected void buildString(String format, Object... args) { } protected String getBuiltString() { - if(stringBuilder == null) { + if (stringBuilder == null) { return null; } return stringBuilder.toString(); diff --git a/src/main/java/org/msgpack/rpc/reflect/ProxyBuilder.java b/src/main/java/org/msgpack/rpc/reflect/ProxyBuilder.java index a361067..b622dc0 100644 --- a/src/main/java/org/msgpack/rpc/reflect/ProxyBuilder.java +++ b/src/main/java/org/msgpack/rpc/reflect/ProxyBuilder.java @@ -18,59 +18,58 @@ package org.msgpack.rpc.reflect; import java.lang.reflect.*; -import org.msgpack.rpc.Future; public abstract class ProxyBuilder { - public static class MethodEntry { - private Method method; - private String rpcName; - private Type genericReturnType; - private boolean async; - private InvokerBuilder.ArgumentEntry[] argumentEntries; - - public MethodEntry(Method method, String rpcName, - Type genericReturnType, boolean async, - InvokerBuilder.ArgumentEntry[] argumentEntries) { - this.method = method; - this.rpcName = rpcName; - this.genericReturnType = genericReturnType; - this.async = async; - this.argumentEntries = argumentEntries; - } - - public Method getMethod() { - return method; - } - - public String getRpcName() { - return rpcName; - } - - public Type getGenericReturnType() { - return genericReturnType; - } - - public boolean isReturnTypeVoid() { + public static class MethodEntry { + private Method method; + private String rpcName; + private Type genericReturnType; + private boolean async; + private InvokerBuilder.ArgumentEntry[] argumentEntries; + + public MethodEntry(Method method, String rpcName, + Type genericReturnType, boolean async, + InvokerBuilder.ArgumentEntry[] argumentEntries) { + this.method = method; + this.rpcName = rpcName; + this.genericReturnType = genericReturnType; + this.async = async; + this.argumentEntries = argumentEntries; + } + + public Method getMethod() { + return method; + } + + public String getRpcName() { + return rpcName; + } + + public Type getGenericReturnType() { + return genericReturnType; + } + + public boolean isReturnTypeVoid() { return genericReturnType == void.class || genericReturnType == Void.class; - } + } - public boolean isAsync() { - return async; - } + public boolean isAsync() { + return async; + } - public InvokerBuilder.ArgumentEntry[] getArgumentEntries() { - return argumentEntries; - } - } + public InvokerBuilder.ArgumentEntry[] getArgumentEntries() { + return argumentEntries; + } + } - // Override this method - public abstract Proxy buildProxy(Class iface, MethodEntry[] entries); + // Override this method + public abstract Proxy buildProxy(Class iface, MethodEntry[] entries); - public Proxy buildProxy(Class iface) { - checkValidation(iface); - MethodEntry[] entries = readMethodEntries(iface); - return buildProxy(iface, entries); - } + public Proxy buildProxy(Class iface) { + checkValidation(iface); + MethodEntry[] entries = readMethodEntries(iface); + return buildProxy(iface, entries); + } /* private static ProxyBuilder instance; @@ -97,51 +96,50 @@ private static ProxyBuilder selectDefaultProxyBuilder() { }*/ - static boolean isAsyncMethod(Method targetMethod) { - // return type is Future + static boolean isAsyncMethod(Method targetMethod) { + // return type is Future return targetMethod.getReturnType().equals( org.msgpack.rpc.Future.class ) || - targetMethod.getReturnType().equals( java.util.concurrent.Future.class ); - } + targetMethod.getReturnType().equals(java.util.concurrent.Future.class); + } - private static void checkValidation(Class iface) { - if(!iface.isInterface()) { - throw new IllegalArgumentException("not interface: "+iface); - } - // TODO - } + private static void checkValidation(Class iface) { + if (!iface.isInterface()) { + throw new IllegalArgumentException("not interface: " + iface); + } + // TODO + } - static MethodEntry[] readMethodEntries(Class iface) { - Method[] methods = MethodSelector.selectRpcClientMethod(iface); + static MethodEntry[] readMethodEntries(Class iface) { + Method[] methods = MethodSelector.selectRpcClientMethod(iface); - MethodEntry[] result = new MethodEntry[methods.length]; - for(int i=0; i < methods.length; i++) { - Method method = methods[i]; + MethodEntry[] result = new MethodEntry[methods.length]; + for (int i = 0; i < methods.length; i++) { + Method method = methods[i]; - InvokerBuilder.ArgumentEntry[] argumentEntries = - InvokerBuilder.readArgumentEntries(method, false); + InvokerBuilder.ArgumentEntry[] argumentEntries = + InvokerBuilder.readArgumentEntries(method, false); - boolean async = isAsyncMethod(method); + boolean async = isAsyncMethod(method); - String rpcName = method.getName(); - if(async) { - // removes /Async$/ - if(rpcName.endsWith("Async")) { - rpcName = rpcName.substring(0, rpcName.length()-5); - } - } + String rpcName = method.getName(); + if (async) { + // removes /Async$/ + if (rpcName.endsWith("Async")) { + rpcName = rpcName.substring(0, rpcName.length() - 5); + } + } - Type returnType = method.getGenericReturnType(); - if(async) { - // actual return type is Future - returnType = ((ParameterizedType)returnType).getActualTypeArguments()[0]; - } + Type returnType = method.getGenericReturnType(); + if (async) { + // actual return type is Future + returnType = ((ParameterizedType) returnType).getActualTypeArguments()[0]; + } - result[i] = new MethodEntry(method, rpcName, - returnType, async, argumentEntries); - } + result[i] = new MethodEntry(method, rpcName, + returnType, async, argumentEntries); + } - return result; - } + return result; + } } - diff --git a/src/main/java/org/msgpack/rpc/reflect/Reflect.java b/src/main/java/org/msgpack/rpc/reflect/Reflect.java index b7d322e..58bd05b 100644 --- a/src/main/java/org/msgpack/rpc/reflect/Reflect.java +++ b/src/main/java/org/msgpack/rpc/reflect/Reflect.java @@ -46,7 +46,7 @@ public Reflect(MessagePack messagePack) { proxyBuilder = new ReflectionProxyBuilder(messagePack); } - public Reflect( InvokerBuilder invokerBuilder,ProxyBuilder proxyBuilder) { + public Reflect(InvokerBuilder invokerBuilder, ProxyBuilder proxyBuilder) { this.invokerBuilder = invokerBuilder; this.proxyBuilder = proxyBuilder; } diff --git a/src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java b/src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java index 2c403f2..bdb28e8 100644 --- a/src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java +++ b/src/main/java/org/msgpack/rpc/reflect/ReflectionInvokerBuilder.java @@ -30,272 +30,278 @@ public class ReflectionInvokerBuilder extends InvokerBuilder { private static final Logger logger = LoggerFactory.getLogger(ReflectionInvokerBuilder.class); - protected MessagePack messagePack; - public ReflectionInvokerBuilder(MessagePack messagePack){ + protected MessagePack messagePack; + + public ReflectionInvokerBuilder(MessagePack messagePack) { this.messagePack = messagePack; } + static abstract class ReflectionArgumentEntry extends ArgumentEntry { + ReflectionArgumentEntry(ArgumentEntry e) { + super(e); + } + + public abstract void convert(Object[] params, Value obj) throws MessageTypeException; + + public void setNull(Object[] params) { + params[getIndex()] = null; + } + } + + static class NullArgumentEntry extends ReflectionArgumentEntry { + NullArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + } + } + + static class BooleanArgumentEntry extends ReflectionArgumentEntry { + BooleanArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asBooleanValue().getBoolean(); + } + } + + static class ByteArgumentEntry extends ReflectionArgumentEntry { + ByteArgumentEntry(ArgumentEntry e) { + super(e); + } - static abstract class ReflectionArgumentEntry extends ArgumentEntry { - ReflectionArgumentEntry(ArgumentEntry e) { - super(e); - } - - public abstract void convert(Object[] params, Value obj) throws MessageTypeException; - - public void setNull(Object[] params) { - params[getIndex()] = null; - } - } - - static class NullArgumentEntry extends ReflectionArgumentEntry { - NullArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { } - } - - static class BooleanArgumentEntry extends ReflectionArgumentEntry { - BooleanArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asBooleanValue().getBoolean(); - } - } - - static class ByteArgumentEntry extends ReflectionArgumentEntry { - ByteArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asIntegerValue().getByte(); - } - } - - static class ShortArgumentEntry extends ReflectionArgumentEntry { - ShortArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asIntegerValue().getShort(); - } - } - - static class IntArgumentEntry extends ReflectionArgumentEntry { - IntArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asIntegerValue().getInt(); - } - } - - static class LongArgumentEntry extends ReflectionArgumentEntry { - LongArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asIntegerValue().getLong(); - } - } - - static class FloatArgumentEntry extends ReflectionArgumentEntry { - FloatArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asFloatValue().getFloat(); - } - } - - static class DoubleArgumentEntry extends ReflectionArgumentEntry { - DoubleArgumentEntry(ArgumentEntry e) { - super(e); - } - public void convert(Object[] params, Value obj) throws MessageTypeException { - params[getIndex()] = obj.asFloatValue().getDouble(); - } - } - - static class ObjectArgumentEntry extends ReflectionArgumentEntry { - private Template template; + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asIntegerValue().getByte(); + } + } + + static class ShortArgumentEntry extends ReflectionArgumentEntry { + ShortArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asIntegerValue().getShort(); + } + } + + static class IntArgumentEntry extends ReflectionArgumentEntry { + IntArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asIntegerValue().getInt(); + } + } + + static class LongArgumentEntry extends ReflectionArgumentEntry { + LongArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asIntegerValue().getLong(); + } + } + + static class FloatArgumentEntry extends ReflectionArgumentEntry { + FloatArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asFloatValue().getFloat(); + } + } + + static class DoubleArgumentEntry extends ReflectionArgumentEntry { + DoubleArgumentEntry(ArgumentEntry e) { + super(e); + } + + public void convert(Object[] params, Value obj) throws MessageTypeException { + params[getIndex()] = obj.asFloatValue().getDouble(); + } + } + + static class ObjectArgumentEntry extends ReflectionArgumentEntry { + private Template template; private MessagePack messagePack; - ObjectArgumentEntry(MessagePack messagePack,ArgumentEntry e, Template template) { - super(e); - this.template = template; + ObjectArgumentEntry(MessagePack messagePack, ArgumentEntry e, Template template) { + super(e); + this.template = template; this.messagePack = messagePack; - } + } - public void convert(Object[] params, Value obj) throws MessageTypeException { + public void convert(Object[] params, Value obj) throws MessageTypeException { try { - params[getIndex()] = template.read(new Converter(messagePack,obj),null);//messagePack.convert(obj,template); + params[getIndex()] = template.read(new Converter(messagePack, obj), null);// messagePack.convert(obj,template); } catch (IOException e) { new MessageTypeException(e); } } - } - - private static class ReflectionInvoker implements Invoker { - protected Method method; - protected int parameterLength; - protected ReflectionArgumentEntry[] entries; - protected int minimumArrayLength; - boolean async; - - public ReflectionInvoker(Method method, ReflectionArgumentEntry[] entries, boolean async) { - this.method = method; - this.parameterLength = method.getParameterTypes().length; - this.entries = entries; - this.async = async; - this.minimumArrayLength = 0; - for(int i=0; i < entries.length; i++) { - ReflectionArgumentEntry e = entries[i]; - if(!e.isOptional()){//e.isRequired() || e.isNullable()) { - this.minimumArrayLength = i+1; - } - } - } - - public void invoke(Object target, Request request) throws Exception { - Object[] params = new Object[parameterLength]; - if(async) { - params[0] = request; - } - - // TODO set default values here - - try { - Value args = request.getArguments(); - - Value[] array = args.asArrayValue().getElementArray(); - int length = array.length; - if(length < minimumArrayLength) { - throw new MessageTypeException(String.format("Method needs at least %s args.But only %s args are passed",minimumArrayLength,length)); - } - - int i; - for(i=0; i < minimumArrayLength; i++) { - ReflectionArgumentEntry e = entries[i]; - if(!e.isAvailable()) { - continue; - } - - Value obj = array[i]; - if(obj.isNilValue()) { - if(e.isRequired()) { - // Required + nil => exception - throw new MessageTypeException(); - } else if(e.isOptional()) { - // Optional + nil => keep default value - } else { // Nullable - // Nullable + nil => set null - e.setNull(params); - } - } else { - try{ - e.convert(params, obj); - }catch(MessageTypeException mte){ - logger.error(String.format("Expect Method:%s ArgIndex:%s Type:%s. But passed:%s",request.getMethodName(),i,e.getGenericType(),obj)); + } + + private static class ReflectionInvoker implements Invoker { + protected Method method; + protected int parameterLength; + protected ReflectionArgumentEntry[] entries; + protected int minimumArrayLength; + boolean async; + + public ReflectionInvoker(Method method, ReflectionArgumentEntry[] entries, boolean async) { + this.method = method; + this.parameterLength = method.getParameterTypes().length; + this.entries = entries; + this.async = async; + this.minimumArrayLength = 0; + for (int i = 0; i < entries.length; i++) { + ReflectionArgumentEntry e = entries[i]; + if (!e.isOptional()) {// e.isRequired() || e.isNullable()) { + this.minimumArrayLength = i + 1; + } + } + } + + public void invoke(Object target, Request request) throws Exception { + Object[] params = new Object[parameterLength]; + if (async) { + params[0] = request; + } + + // TODO set default values here + + try { + Value args = request.getArguments(); + + Value[] array = args.asArrayValue().getElementArray(); + int length = array.length; + if (length < minimumArrayLength) { + throw new MessageTypeException(String.format("Method needs at least %s args.But only %s args are passed", minimumArrayLength, length)); + } + + int i; + for (i = 0; i < minimumArrayLength; i++) { + ReflectionArgumentEntry e = entries[i]; + if (!e.isAvailable()) { + continue; + } + + Value obj = array[i]; + if (obj.isNilValue()) { + if (e.isRequired()) { + // Required + nil => exception + throw new MessageTypeException(); + } else if (e.isOptional()) { + // Optional + nil => keep default value + } else { // Nullable + // Nullable + nil => set null + e.setNull(params); + } + } else { + try { + e.convert(params, obj); + } catch (MessageTypeException mte) { + logger.error(String.format("Expect Method:%s ArgIndex:%s Type:%s. But passed:%s", request.getMethodName(), i, e.getGenericType(), obj)); throw new MessageTypeException(String.format( - "%sth argument type is %s.But wrong type is sent.",i+1,e.getJavaTypeName()) - ); + "%sth argument type is %s.But wrong type is sent.", i + 1, e.getJavaTypeName())); } - } - } - - int max = length < entries.length ? length : entries.length; - for(; i < max; i++) { - ReflectionArgumentEntry e = entries[i]; - if(!e.isAvailable()) { - continue; - } - - Value obj = array[i]; - if(obj.isNilValue()) { - // this is Optional field becaue i >= minimumArrayLength - // Optional + nil => keep default value - } else { - - try{ - e.convert(params, obj); - }catch(MessageTypeException mte){ - logger.error(String.format("Expect Method:%s ArgIndex:%s Type:%s. But passed:%s",request.getMethodName(),i,e.getGenericType(),obj)); + } + } + + int max = length < entries.length ? length : entries.length; + for (; i < max; i++) { + ReflectionArgumentEntry e = entries[i]; + if (!e.isAvailable()) { + continue; + } + + Value obj = array[i]; + if (obj.isNilValue()) { + // this is Optional field becaue i >= minimumArrayLength + // Optional + nil => keep default value + } else { + + try { + e.convert(params, obj); + } catch (MessageTypeException mte) { + logger.error(String.format("Expect Method:%s ArgIndex:%s Type:%s. But passed:%s", request.getMethodName(), i, e.getGenericType(), obj)); throw new MessageTypeException(String.format( - "%sth argument type is %s.But wrong type is sent.",i+1,e.getJavaTypeName()) - ); + "%sth argument type is %s.But wrong type is sent.", i + 1, e.getJavaTypeName())); } - } - } + } + } - // latter entries are all Optional + nil => keep default value + // latter entries are all Optional + nil => keep default value - } catch (MessageTypeException e) { + } catch (MessageTypeException e) { throw e; - } catch (Exception e) { - //e.printStackTrace(); + } catch (Exception e) { + // e.printStackTrace(); throw e; - } + } - Object result = null; - try{ + Object result = null; + try { result = method.invoke(target, params); - }catch(InvocationTargetException e ){ - if(e.getCause() != null && e.getCause() instanceof Exception){ - throw (Exception)e.getCause(); - }else{ + } catch (InvocationTargetException e) { + if (e.getCause() != null && e.getCause() instanceof Exception) { + throw (Exception) e.getCause(); + } else { throw e; } } - if(!async) { - request.sendResult(result); - } - - // TODO exception - } - } - - public Invoker buildInvoker(Method targetMethod, ArgumentEntry[] entries, boolean async) { - int mod = targetMethod.getModifiers(); - if(!Modifier.isPublic(mod)) { - targetMethod.setAccessible(true); - } - - ReflectionArgumentEntry[] res = new ReflectionArgumentEntry[entries.length]; - for(int i=0; i < entries.length; i++) { - ArgumentEntry e = entries[i]; - Class type = e.getType(); - if(!e.isAvailable()) { - res[i] = new NullArgumentEntry(e); - } else if(type.equals(boolean.class)) { - res[i] = new BooleanArgumentEntry(e); - } else if(type.equals(byte.class)) { - res[i] = new ByteArgumentEntry(e); - } else if(type.equals(short.class)) { - res[i] = new ShortArgumentEntry(e); - } else if(type.equals(int.class)) { - res[i] = new IntArgumentEntry(e); - } else if(type.equals(long.class)) { - res[i] = new LongArgumentEntry(e); - } else if(type.equals(float.class)) { - res[i] = new FloatArgumentEntry(e); - } else if(type.equals(double.class)) { - res[i] = new DoubleArgumentEntry(e); - } else { + if (!async) { + request.sendResult(result); + } + + // TODO exception + } + } + + public Invoker buildInvoker(Method targetMethod, ArgumentEntry[] entries, boolean async) { + int mod = targetMethod.getModifiers(); + if (!Modifier.isPublic(mod)) { + targetMethod.setAccessible(true); + } + + ReflectionArgumentEntry[] res = new ReflectionArgumentEntry[entries.length]; + for (int i = 0; i < entries.length; i++) { + ArgumentEntry e = entries[i]; + Class type = e.getType(); + if (!e.isAvailable()) { + res[i] = new NullArgumentEntry(e); + } else if (type.equals(boolean.class)) { + res[i] = new BooleanArgumentEntry(e); + } else if (type.equals(byte.class)) { + res[i] = new ByteArgumentEntry(e); + } else if (type.equals(short.class)) { + res[i] = new ShortArgumentEntry(e); + } else if (type.equals(int.class)) { + res[i] = new IntArgumentEntry(e); + } else if (type.equals(long.class)) { + res[i] = new LongArgumentEntry(e); + } else if (type.equals(float.class)) { + res[i] = new FloatArgumentEntry(e); + } else if (type.equals(double.class)) { + res[i] = new DoubleArgumentEntry(e); + } else { Type t = e.getGenericType(); - Template tmpl = messagePack.lookup(t); - if(tmpl == null){ - messagePack.register((Class)t); + Template tmpl = messagePack.lookup(t); + if (tmpl == null) { + messagePack.register((Class) t); tmpl = messagePack.lookup(t); } - res[i] = new ObjectArgumentEntry(messagePack,e, tmpl); - } - } + res[i] = new ObjectArgumentEntry(messagePack, e, tmpl); + } + } - return new ReflectionInvoker(targetMethod, res, async); - } + return new ReflectionInvoker(targetMethod, res, async); + } } - diff --git a/src/main/java/org/msgpack/rpc/reflect/ReflectionProxyBuilder.java b/src/main/java/org/msgpack/rpc/reflect/ReflectionProxyBuilder.java index 8d81c17..bdc4481 100644 --- a/src/main/java/org/msgpack/rpc/reflect/ReflectionProxyBuilder.java +++ b/src/main/java/org/msgpack/rpc/reflect/ReflectionProxyBuilder.java @@ -23,142 +23,142 @@ import java.lang.reflect.*; import org.msgpack.rpc.*; import org.msgpack.*; -import org.msgpack.rpc.loop.netty.MessagePackEncoder; import org.msgpack.template.*; import org.msgpack.type.Value; import org.msgpack.unpacker.Converter; public class ReflectionProxyBuilder extends ProxyBuilder { - private static class ReflectionMethodEntry { - private String rpcName; - private Template returnTypeTemplate; - private boolean async; - private InvokerBuilder.ArgumentEntry[] argumentEntries; - - public ReflectionMethodEntry(MethodEntry e, Template returnTypeTemplate) { - this.rpcName = e.getRpcName(); - this.returnTypeTemplate = returnTypeTemplate; - this.async = e.isAsync(); - this.argumentEntries = e.getArgumentEntries(); - } - - public String getRpcName() { - return rpcName; - } - - public Template getReturnTypeTemplate() { - return returnTypeTemplate; - } - - public boolean isAsync() { - return async; - } - - public Object[] sort(Object[] args) { - Object[] params = new Object[argumentEntries.length]; - - for(int i=0; i < argumentEntries.length; i++) { - InvokerBuilder.ArgumentEntry e = argumentEntries[i]; - if(!e.isAvailable()) { - continue; - } - if(params.length < e.getIndex()) { - // FIXME - } - if(e.isRequired() && args[i] == null) { - // TODO type error - } - params[i] = args[e.getIndex()]; - } - - return params; - } - } - - public class ReflectionHandler implements InvocationHandler { - private Session s; - private Map entryMap; - - public ReflectionHandler(Session s, Map entryMap) { - this.s = s; - this.entryMap = entryMap; - } - - public Object invoke(Object proxy, Method method, Object[] args) { - ReflectionMethodEntry e = entryMap.get(method); - if(e == null) { - // FIXME - } - Object[] params = e.sort(args); - if(e.isAsync()) { - Future f = s.callAsyncApply(e.getRpcName(), params); - return new Future(messagePack, f, e.getReturnTypeTemplate()); - } else { - Value obj = s.callApply(e.getRpcName(), params); - if(obj.isNilValue()){ - return null; - }else{ - Template tmpl = e.getReturnTypeTemplate(); - if(tmpl == null) { - return null; - } + private static class ReflectionMethodEntry { + private String rpcName; + private Template returnTypeTemplate; + private boolean async; + private InvokerBuilder.ArgumentEntry[] argumentEntries; + + public ReflectionMethodEntry(MethodEntry e, Template returnTypeTemplate) { + this.rpcName = e.getRpcName(); + this.returnTypeTemplate = returnTypeTemplate; + this.async = e.isAsync(); + this.argumentEntries = e.getArgumentEntries(); + } + + public String getRpcName() { + return rpcName; + } + + public Template getReturnTypeTemplate() { + return returnTypeTemplate; + } + + public boolean isAsync() { + return async; + } + + public Object[] sort(Object[] args) { + Object[] params = new Object[argumentEntries.length]; + + for (int i = 0; i < argumentEntries.length; i++) { + InvokerBuilder.ArgumentEntry e = argumentEntries[i]; + if (!e.isAvailable()) { + continue; + } + if (params.length < e.getIndex()) { + // FIXME + } + if (e.isRequired() && args[i] == null) { + // TODO type error + } + params[i] = args[e.getIndex()]; + } + + return params; + } + } + + public class ReflectionHandler implements InvocationHandler { + private Session s; + private Map entryMap; + + public ReflectionHandler(Session s, Map entryMap) { + this.s = s; + this.entryMap = entryMap; + } + + public Object invoke(Object proxy, Method method, Object[] args) { + ReflectionMethodEntry e = entryMap.get(method); + if (e == null) { + // FIXME + } + Object[] params = e.sort(args); + if (e.isAsync()) { + Future f = s.callAsyncApply(e.getRpcName(), params); + return new Future(messagePack, f, e.getReturnTypeTemplate()); + } else { + Value obj = s.callApply(e.getRpcName(), params); + if (obj.isNilValue()) { + return null; + } else { + Template tmpl = e.getReturnTypeTemplate(); + if (tmpl == null) { + return null; + } try { - return tmpl.read(new Converter(messagePack,obj),null); - //return messagePack.convert(obj,tmpl);// obj.convert(tmpl); + return tmpl.read(new Converter(messagePack, obj), null); + // return messagePack.convert(obj,tmpl); + // obj.convert(tmpl); } catch (IOException e1) { return null; } } - } - } - } - - public class ReflectionProxy implements Proxy { - private Class iface; - private Map entryMap; - - public ReflectionProxy(Class iface, Map entryMap) { - this.iface = iface; - this.entryMap = entryMap; - } - - public T newProxyInstance(Session s) { - ReflectionHandler handler = new ReflectionHandler(s, entryMap); - return (T)java.lang.reflect.Proxy.newProxyInstance( - iface.getClassLoader(), new Class[] { iface }, handler); - } - } + } + } + } + + public class ReflectionProxy implements Proxy { + private Class iface; + private Map entryMap; + + public ReflectionProxy(Class iface, Map entryMap) { + this.iface = iface; + this.entryMap = entryMap; + } + + public T newProxyInstance(Session s) { + ReflectionHandler handler = new ReflectionHandler(s, entryMap); + return (T) java.lang.reflect.Proxy.newProxyInstance( + iface.getClassLoader(), new Class[] { iface }, handler); + } + } private MessagePack messagePack; - public ReflectionProxyBuilder(MessagePack messagePack){ + public ReflectionProxyBuilder(MessagePack messagePack) { this.messagePack = messagePack; } - public Proxy buildProxy(Class iface, MethodEntry[] entries) { - for(MethodEntry e : entries) { - Method method = e.getMethod(); - int mod = method.getModifiers(); - if(!Modifier.isPublic(mod)) { - method.setAccessible(true); - } - } - - Map entryMap = new HashMap(); - for(int i=0; i < entries.length; i++) { - MethodEntry e = entries[i]; - Template tmpl; - if(e.isReturnTypeVoid()) { - tmpl = null; - } else { - tmpl = messagePack.lookup(e.getGenericReturnType());// TemplateRegistry.lookup(e.getGenericReturnType(), true); - } - entryMap.put(e.getMethod(), new ReflectionMethodEntry(e, tmpl)); - } - - return new ReflectionProxy(iface, entryMap); - } + public Proxy buildProxy(Class iface, MethodEntry[] entries) { + for (MethodEntry e : entries) { + Method method = e.getMethod(); + int mod = method.getModifiers(); + if (!Modifier.isPublic(mod)) { + method.setAccessible(true); + } + } + + Map entryMap = new HashMap(); + for (int i = 0; i < entries.length; i++) { + MethodEntry e = entries[i]; + Template tmpl; + if (e.isReturnTypeVoid()) { + tmpl = null; + } else { + tmpl = messagePack.lookup(e.getGenericReturnType());// TemplateRegistry.lookup(e.getGenericReturnType(), + // true); + } + entryMap.put(e.getMethod(), new ReflectionMethodEntry(e, tmpl)); + } + + return new ReflectionProxy(iface, entryMap); + } } - diff --git a/src/main/java/org/msgpack/rpc/transport/PooledStreamClientTransport.java b/src/main/java/org/msgpack/rpc/transport/PooledStreamClientTransport.java index 6a3e029..306e92e 100644 --- a/src/main/java/org/msgpack/rpc/transport/PooledStreamClientTransport.java +++ b/src/main/java/org/msgpack/rpc/transport/PooledStreamClientTransport.java @@ -30,7 +30,7 @@ public abstract class PooledStreamClientTransport implements ClientTransport { private static final InternalLogger LOG = - InternalLoggerFactory.getInstance(PooledStreamClientTransport.class); + InternalLoggerFactory.getInstance(PooledStreamClientTransport.class); private final Object lock = new Object(); private final List pool = new ArrayList(); diff --git a/src/test/java/org/msgpack/rpc/BigDataTest.java b/src/test/java/org/msgpack/rpc/BigDataTest.java index 383afa6..6dcea86 100644 --- a/src/test/java/org/msgpack/rpc/BigDataTest.java +++ b/src/test/java/org/msgpack/rpc/BigDataTest.java @@ -10,83 +10,83 @@ import org.msgpack.type.ValueFactory; public class BigDataTest extends TestCase { - + private static String getBigString() { StringBuilder sb = new StringBuilder(1024 * 1024); // 1M Random random = new Random(); - for(int i = 0;i < 1024 * 1024;i++){ - sb.append( (char)('a' + random.nextInt(26))); + for (int i = 0; i < 1024 * 1024; i++) { + sb.append((char) ('a' + random.nextInt(26))); } return sb.toString(); } private static Value BIG_DATA = ValueFactory.createRawValue(getBigString()); - public static class BigDataDispatcher implements Dispatcher { - public void dispatch(Request request) { - assertEquals(BIG_DATA,request.getArguments().asArrayValue().get(0) ); - request.sendResult(BIG_DATA); - } - } - - @Test - public void testSyncBigDataLoad() throws Exception { - MessagePack messagePack = new MessagePack(); - EventLoop loop = EventLoop.start(messagePack); - Server svr = new Server(loop); - Client c = new Client("127.0.0.1", 19851, loop); - c.setRequestTimeout(10); - - try { - svr.serve(new BigDataDispatcher()); - svr.listen(19851); - - int num = 5; - - long start = System.currentTimeMillis(); - for(int i=0; i < num; i++) { - Value result = c.callApply("test", new Object[]{BIG_DATA}); - assertEquals(BIG_DATA, result); - } - long finish = System.currentTimeMillis(); + public static class BigDataDispatcher implements Dispatcher { + public void dispatch(Request request) { + assertEquals(BIG_DATA, request.getArguments().asArrayValue().get(0)); + request.sendResult(BIG_DATA); + } + } - double result = num / ((double)(finish - start) / 1000); - System.out.println("sync: "+result+" calls per sec"); + @Test + public void testSyncBigDataLoad() throws Exception { + MessagePack messagePack = new MessagePack(); + EventLoop loop = EventLoop.start(messagePack); + Server svr = new Server(loop); + Client c = new Client("127.0.0.1", 19851, loop); + c.setRequestTimeout(10); + + try { + svr.serve(new BigDataDispatcher()); + svr.listen(19851); + + int num = 5; + + long start = System.currentTimeMillis(); + for (int i = 0; i < num; i++) { + Value result = c.callApply("test", new Object[] { BIG_DATA }); + assertEquals(BIG_DATA, result); + } + long finish = System.currentTimeMillis(); + + double result = num / ((double) (finish - start) / 1000); + System.out.println("sync: " + result + " calls per sec"); + + } finally { + svr.close(); + c.close(); + loop.shutdown(); + } + } - } finally { - svr.close(); - c.close(); - loop.shutdown(); - } + @Test + public void testAsyncBigDataLoad() throws Exception { + EventLoop loop = EventLoop.start(); + Server svr = new Server(loop); + Client c = new Client("127.0.0.1", 19852, loop); + c.setRequestTimeout(100);// + + try { + svr.serve(new BigDataDispatcher()); + svr.listen(19852); + + int num = 10; + + long start = System.currentTimeMillis(); + for (int i = 0; i < num - 1; i++) { + c.notifyApply("test", new Object[] { BIG_DATA }); + } + c.callApply("test", new Object[] { BIG_DATA }); + long finish = System.currentTimeMillis(); + + double result = num / ((double) (finish - start) / 1000); + System.out.println("async: " + result + " calls per sec"); + + } finally { + svr.close(); + c.close(); + loop.shutdown(); + } } - @Test - public void testAsyncBigDataLoad() throws Exception { - EventLoop loop = EventLoop.start(); - Server svr = new Server(loop); - Client c = new Client("127.0.0.1", 19852, loop); - c.setRequestTimeout(100);// - - try { - svr.serve(new BigDataDispatcher()); - svr.listen(19852); - - int num = 10; - - long start = System.currentTimeMillis(); - for(int i=0; i < num-1; i++) { - c.notifyApply("test", new Object[]{BIG_DATA}); - } - c.callApply("test", new Object[]{BIG_DATA}); - long finish = System.currentTimeMillis(); - - double result = num / ((double)(finish - start) / 1000); - System.out.println("async: "+result+" calls per sec"); - - } finally { - svr.close(); - c.close(); - loop.shutdown(); - } - } } - diff --git a/src/test/java/org/msgpack/rpc/DecoratorTest.java b/src/test/java/org/msgpack/rpc/DecoratorTest.java index c055c15..93c238f 100644 --- a/src/test/java/org/msgpack/rpc/DecoratorTest.java +++ b/src/test/java/org/msgpack/rpc/DecoratorTest.java @@ -14,24 +14,23 @@ */ public class DecoratorTest extends TestCase { - public static class TestServer{ + public static class TestServer { public String success() { return "ok"; } - public String throwError(String errorMessage) throws Exception{ + public String throwError(String errorMessage) throws Exception { throw new MessageTypeException(errorMessage); } } - /** * Test any Exception is not thrown. * @throws Exception */ @Test - public void testDecorateStopWatch() throws Exception { + public void testDecorateStopWatch() throws Exception { BasicConfigurator.configure(); EventLoop loop = EventLoop.start(); @@ -39,7 +38,7 @@ public void testDecorateStopWatch() throws Exception { svr.setDispatcherBuilder( new StopWatchDispatcherBuilder(svr.getDispatcherBuilder()). withVerboseOutput(true) - ); + ); Client c = new Client("127.0.0.1", 19850, loop); c.setRequestTimeout(10); @@ -47,14 +46,14 @@ public void testDecorateStopWatch() throws Exception { svr.serve(new TestServer()); svr.listen(19850); - Value result = c.callApply("success", new Object[]{}); + Value result = c.callApply("success", new Object[] {}); assertNotNull(result); - try{ - c.callApply("throwError", new Object[]{"StopWatchTest"}); + try { + c.callApply("throwError", new Object[] { "StopWatchTest" }); fail("Exception must be thrown."); - }catch(Exception e){ + } catch (Exception e) { } diff --git a/src/test/java/org/msgpack/rpc/FutureTest.java b/src/test/java/org/msgpack/rpc/FutureTest.java index ddece5c..e36f81f 100644 --- a/src/test/java/org/msgpack/rpc/FutureTest.java +++ b/src/test/java/org/msgpack/rpc/FutureTest.java @@ -17,13 +17,7 @@ // package org.msgpack.rpc; -import org.msgpack.*; -import org.msgpack.rpc.*; -import org.msgpack.rpc.dispatcher.*; -import org.msgpack.rpc.config.*; import org.msgpack.rpc.loop.*; -import org.msgpack.rpc.loop.netty.*; -import java.util.*; import java.util.concurrent.TimeUnit; import junit.framework.*; import org.junit.Test; diff --git a/src/test/java/org/msgpack/rpc/ServerErrorTest.java b/src/test/java/org/msgpack/rpc/ServerErrorTest.java index 40a37c7..58c1284 100644 --- a/src/test/java/org/msgpack/rpc/ServerErrorTest.java +++ b/src/test/java/org/msgpack/rpc/ServerErrorTest.java @@ -4,36 +4,28 @@ import org.apache.log4j.BasicConfigurator; import org.junit.Test; import org.msgpack.MessageTypeException; -import org.msgpack.rpc.builder.StopWatchDispatcherBuilder; -import org.msgpack.rpc.error.NoMethodError; import org.msgpack.rpc.error.RemoteError; -import org.msgpack.rpc.error.TimeoutError; import org.msgpack.rpc.loop.EventLoop; -import org.msgpack.type.Value; - -import java.util.Date; /** * Test when server throws exceptions. * User: takeshita * Create: 12/06/15 12:12 */ -public class ServerErrorTest extends TestCase { - +public class ServerErrorTest extends TestCase { - public static class TestServer{ + public static class TestServer { - public String echo(String message){ + public String echo(String message) { return message; } - - public String waitWhile(int waitMSecs) throws Exception{ + public String waitWhile(int waitMSecs) throws Exception { Thread.sleep(waitMSecs); return "ok"; } - public String throwException(String errorMessage) throws Exception{ + public String throwException(String errorMessage) throws Exception { throw new MessageTypeException(errorMessage); } @@ -43,11 +35,11 @@ public String throwRuntimeException(String errorMessage) { } - static interface CallFunc{ + static interface CallFunc { public void apply(Client client); } - void call( CallFunc func) throws Exception{ + void call(CallFunc func) throws Exception { BasicConfigurator.configure(); EventLoop loop = EventLoop.start(); @@ -68,123 +60,119 @@ void call( CallFunc func) throws Exception{ } } - @Test - public void testNormalException() throws Exception { - call( new CallFunc(){ + public void testNormalException() throws Exception { + call(new CallFunc() { public void apply(Client client) { String message = "Normal exception"; - try{ - client.callApply("throwException",new Object[]{message}); + try { + client.callApply("throwException", new Object[] { message }); fail("Must throw exception"); - }catch(RemoteError e){ - assertEquals(message,e.getMessage()); - }catch(Exception e){ + } catch (RemoteError e) { + assertEquals(message, e.getMessage()); + } catch (Exception e) { System.out.println(e.getClass()); fail("Not normal exception"); } } - } - ); + }); } @Test - public void testRuntimeException() throws Exception { - call( new CallFunc(){ + public void testRuntimeException() throws Exception { + call(new CallFunc() { public void apply(Client client) { String message = "Normal exception"; - try{ - client.callApply("throwRuntimeException",new Object[]{message}); + try { + client.callApply("throwRuntimeException", new Object[] { message }); fail("Must throw exception"); - }catch(RemoteError e){ - assertEquals(message,e.getMessage()); - }catch(Exception e){ + } catch (RemoteError e) { + assertEquals(message, e.getMessage()); + } catch (Exception e) { System.out.println(e.getClass()); fail("Not normal exception"); } } - } - ); + }); } + @Test - public void testNullErrorMessage() throws Exception { - call( new CallFunc(){ + public void testNullErrorMessage() throws Exception { + call(new CallFunc() { public void apply(Client client) { - try{ - client.callApply("throwRuntimeException",new Object[]{null}); + try { + client.callApply("throwRuntimeException", new Object[] { null }); fail("Must throw exception"); - }catch(RemoteError e){ - assertEquals("",e.getMessage()); - }catch(Exception e){ + } catch (RemoteError e) { + assertEquals("", e.getMessage()); + } catch (Exception e) { System.out.println(e.getClass()); fail("Not normal exception"); } } - } - ); + }); } @Test - public void testNoMethodError() throws Exception { - call( new CallFunc(){ + public void testNoMethodError() throws Exception { + call(new CallFunc() { public void apply(Client client) { - try{ - client.callApply("methodWhichDoesNotExist",new Object[]{null}); + try { + client.callApply("methodWhichDoesNotExist", new Object[] { null }); fail("Must throw exception"); - }catch(RemoteError e){ - assertEquals(".CallError.NoMethodError",e.getMessage()); - }catch(Exception e){ + } catch (RemoteError e) { + assertEquals(".CallError.NoMethodError", e.getMessage()); + } catch (Exception e) { System.out.println("Wrong exception:" + e.getClass()); fail("Not NoMethodException"); } } - } - ); + }); } + @Test - public void testBadArgs() throws Exception { - call( new CallFunc(){ + public void testBadArgs() throws Exception { + call(new CallFunc() { public void apply(Client client) { - try{ - client.callApply("echo",new Object[]{1}); + try { + client.callApply("echo", new Object[] { 1 }); fail("Must throw exception"); - }catch(RemoteError e){ + } catch (RemoteError e) { // OK - }catch(Exception e){ + } catch (Exception e) { System.out.println("Wrong exception:" + e.getClass()); fail("Not NoMethodException"); } } - } - ); + }); } + @Test - public void testTimeout() throws Exception { - call( new CallFunc(){ + public void testTimeout() throws Exception { + call(new CallFunc() { public void apply(Client client) { - try{ - client.callApply("waitWhile",new Object[]{3000}); + try { + client.callApply("waitWhile", new Object[] { 3000 }); fail("Must throw exception"); - }catch(RemoteError e){ - assertEquals("timedout",e.getMessage()); - }catch(Exception e){ + } catch (RemoteError e) { + assertEquals("timedout", e.getMessage()); + } catch (Exception e) { System.out.println("Wrong exception:" + e.getClass()); fail("Not NoMethodException"); } } - } - ); + }); } } diff --git a/src/test/java/org/msgpack/rpc/ServerTest.java b/src/test/java/org/msgpack/rpc/ServerTest.java index 2676d02..41a5582 100644 --- a/src/test/java/org/msgpack/rpc/ServerTest.java +++ b/src/test/java/org/msgpack/rpc/ServerTest.java @@ -17,91 +17,82 @@ // package org.msgpack.rpc; -import org.apache.log4j.BasicConfigurator; import org.msgpack.*; -import org.msgpack.rpc.*; -import org.msgpack.rpc.builder.StopWatchDispatcherBuilder; import org.msgpack.rpc.dispatcher.*; -import org.msgpack.rpc.config.*; import org.msgpack.rpc.loop.*; -import org.msgpack.rpc.loop.netty.*; -import java.util.*; import junit.framework.*; import org.junit.Test; -import org.msgpack.template.Template; import org.msgpack.type.Value; import org.msgpack.type.ValueFactory; public class ServerTest extends TestCase { - private static Value MESSAGE = ValueFactory.createRawValue("ok"); - public static class TestDispatcher implements Dispatcher { - public void dispatch(Request request) { - request.sendResult(MESSAGE); - } - } - - @Test - public void testSyncLoad() throws Exception { - MessagePack messagePack = new MessagePack(); - EventLoop loop = EventLoop.start(messagePack); - Server svr = new Server(loop); - Client c = new Client("127.0.0.1", 19850, loop); - c.setRequestTimeout(10); - - - try { - svr.serve(new TestDispatcher()); - svr.listen(19850); - - int num = 1000; - - long start = System.currentTimeMillis(); - for(int i=0; i < num; i++) { - Value result = c.callApply("test", new Object[]{}); - assertEquals(MESSAGE, result); - } - long finish = System.currentTimeMillis(); - - double result = num / ((double)(finish - start) / 1000); - System.out.println("sync: "+result+" calls per sec"); - - } finally { - svr.close(); - c.close(); - loop.shutdown(); - } - } - - @Test - public void testAsyncLoad() throws Exception { - EventLoop loop = EventLoop.start(); - Server svr = new Server(loop); - Client c = new Client("127.0.0.1", 19850, loop); - c.setRequestTimeout(100);// - - try { - svr.serve(new TestDispatcher()); - svr.listen(19850); - - int num = 1000; - - long start = System.currentTimeMillis(); - for(int i=0; i < num-1; i++) { - c.notifyApply("test", new Object[]{}); - } - c.callApply("test", new Object[]{}); - long finish = System.currentTimeMillis(); - - double result = num / ((double)(finish - start) / 1000); - System.out.println("async: "+result+" calls per sec"); - - } finally { - svr.close(); - c.close(); - loop.shutdown(); - } - } + private static Value MESSAGE = ValueFactory.createRawValue("ok"); + public static class TestDispatcher implements Dispatcher { + public void dispatch(Request request) { + request.sendResult(MESSAGE); + } + } -} + @Test + public void testSyncLoad() throws Exception { + MessagePack messagePack = new MessagePack(); + EventLoop loop = EventLoop.start(messagePack); + Server svr = new Server(loop); + Client c = new Client("127.0.0.1", 19850, loop); + c.setRequestTimeout(10); + + try { + svr.serve(new TestDispatcher()); + svr.listen(19850); + + int num = 1000; + + long start = System.currentTimeMillis(); + for (int i = 0; i < num; i++) { + Value result = c.callApply("test", new Object[] {}); + assertEquals(MESSAGE, result); + } + long finish = System.currentTimeMillis(); + + double result = num / ((double) (finish - start) / 1000); + System.out.println("sync: " + result + " calls per sec"); + + } finally { + svr.close(); + c.close(); + loop.shutdown(); + } + } + + @Test + public void testAsyncLoad() throws Exception { + EventLoop loop = EventLoop.start(); + Server svr = new Server(loop); + Client c = new Client("127.0.0.1", 19850, loop); + c.setRequestTimeout(100);// + + try { + svr.serve(new TestDispatcher()); + svr.listen(19850); + + int num = 1000; + + long start = System.currentTimeMillis(); + for (int i = 0; i < num - 1; i++) { + c.notifyApply("test", new Object[] {}); + } + c.callApply("test", new Object[] {}); + long finish = System.currentTimeMillis(); + + double result = num / ((double) (finish - start) / 1000); + System.out.println("async: " + result + " calls per sec"); + + } finally { + svr.close(); + c.close(); + loop.shutdown(); + } + } +} diff --git a/src/test/java/org/msgpack/rpc/reflect/AnnotationTest.java b/src/test/java/org/msgpack/rpc/reflect/AnnotationTest.java index 3a8665f..0b2e264 100644 --- a/src/test/java/org/msgpack/rpc/reflect/AnnotationTest.java +++ b/src/test/java/org/msgpack/rpc/reflect/AnnotationTest.java @@ -17,67 +17,67 @@ // package org.msgpack.rpc.reflect; -import org.msgpack.*; import org.msgpack.annotation.*; -import org.msgpack.rpc.*; -import org.msgpack.rpc.dispatcher.*; -import org.msgpack.rpc.config.*; -import org.msgpack.rpc.loop.*; -import org.msgpack.rpc.loop.netty.*; -import java.util.*; -import junit.framework.*; import org.junit.Test; public class AnnotationTest extends ReflectTest { - public static interface IgnoreTest { - public String m01(String a0, @Ignore String a1); - public String m02(@Ignore String a0, String a1); - } - - public static interface OmitTest { - public String m01(String a0); - public String m02(String a0); - } - - public static class IgnoreTestHandler implements IgnoreTest { - public IgnoreTestHandler() { } - public String m01(String a0, @Ignore String a1) { - return ""+a0+a1; - } - public String m02(@Ignore String a0, String a1) { - return ""+a0+a1; - } - } - - public static class OmitTestHandler implements OmitTest { - public OmitTestHandler() { } - public String m01(String a0) { - return a0; - } - public String m02(String a0) { - return a0; - } - } - - @Test - public void testIgnoreClientOmitServer() throws Exception { - Context context = startServer(new OmitTestHandler()); - IgnoreTest c = context.getClient().proxy(IgnoreTest.class); - try { - String result; - - result = c.m01("a0", "a1"); - assertEquals("a0", result); - - result = c.m02("a0", "a1"); - assertEquals("a1", result); - - } finally { - context.close(); - } - } - - @Test + public static interface IgnoreTest { + public String m01(String a0, @Ignore String a1); + + public String m02(@Ignore String a0, String a1); + } + + public static interface OmitTest { + public String m01(String a0); + + public String m02(String a0); + } + + public static class IgnoreTestHandler implements IgnoreTest { + public IgnoreTestHandler() { + } + + public String m01(String a0, @Ignore String a1) { + return "" + a0 + a1; + } + + public String m02(@Ignore String a0, String a1) { + return "" + a0 + a1; + } + } + + public static class OmitTestHandler implements OmitTest { + public OmitTestHandler() { + } + + public String m01(String a0) { + return a0; + } + + public String m02(String a0) { + return a0; + } + } + + @Test + public void testIgnoreClientOmitServer() throws Exception { + Context context = startServer(new OmitTestHandler()); + IgnoreTest c = context.getClient().proxy(IgnoreTest.class); + try { + String result; + + result = c.m01("a0", "a1"); + assertEquals("a0", result); + + result = c.m02("a0", "a1"); + assertEquals("a1", result); + + } finally { + context.close(); + } + } + + @Test public void testIgnoreClientOmitServer2() throws Exception { Context context = startServer2(new OmitTestHandler()); IgnoreTest c = context.getClient().proxy(IgnoreTest.class); @@ -96,22 +96,22 @@ public void testIgnoreClientOmitServer2() throws Exception { } @Test - public void testOmitClientIgnoreServer() throws Exception { - Context context = startServer(new IgnoreTestHandler()); - OmitTest c = context.getClient().proxy(OmitTest.class); - try { - String result; - - result = c.m01("a0"); - assertEquals(""+"a0"+null, result); - - result = c.m02("a0"); - assertEquals(""+null+"a0", result); - - } finally { - context.close(); - } - } + public void testOmitClientIgnoreServer() throws Exception { + Context context = startServer(new IgnoreTestHandler()); + OmitTest c = context.getClient().proxy(OmitTest.class); + try { + String result; + + result = c.m01("a0"); + assertEquals("" + "a0" + null, result); + + result = c.m02("a0"); + assertEquals("" + null + "a0", result); + + } finally { + context.close(); + } + } @Test public void testOmitClientIgnoreServer2() throws Exception { @@ -119,49 +119,51 @@ public void testOmitClientIgnoreServer2() throws Exception { OmitTest c = context.getClient().proxy(OmitTest.class); try { String result; - + result = c.m01("a0"); - assertEquals(""+"a0"+null, result); + assertEquals("" + "a0" + null, result); result = c.m02("a0"); - assertEquals(""+null+"a0", result); + assertEquals("" + null + "a0", result); + + } finally { + context.close(); + } + } + + public static interface OptionalTestV1 { + public String m01(String a0); + } + + public static interface OptionalTestV2 { + public String m01(String a0, @Optional String a1); + } + + public static class OptionalTestHandler implements OptionalTestV2 { + public OptionalTestHandler() { + } + + public String m01(String a0, @Optional String a1) { + return "" + a0 + a1; + } + } + + @Test + public void testOptionalV1() throws Exception { + Context context = startServer(new OptionalTestHandler()); + OptionalTestV1 c = context.getClient().proxy(OptionalTestV1.class); + try { + String result; + + result = c.m01("a0"); + assertEquals("" + "a0" + null, result); } finally { context.close(); } } - public static interface OptionalTestV1 { - public String m01(String a0); - } - - public static interface OptionalTestV2 { - public String m01(String a0, @Optional String a1); - } - - public static class OptionalTestHandler implements OptionalTestV2 { - public OptionalTestHandler() { } - public String m01(String a0, @Optional String a1) { - return ""+a0+a1; - } - } - - @Test - public void testOptionalV1() throws Exception { - Context context = startServer(new OptionalTestHandler()); - OptionalTestV1 c = context.getClient().proxy(OptionalTestV1.class); - try { - String result; - - result = c.m01("a0"); - assertEquals(""+"a0"+null, result); - - } finally { - context.close(); - } - } - - @Test + @Test public void testOptionalV12() throws Exception { Context context = startServer2(new OptionalTestHandler()); OptionalTestV1 c = context.getClient().proxy(OptionalTestV1.class); @@ -169,29 +171,29 @@ public void testOptionalV12() throws Exception { String result; result = c.m01("a0"); - assertEquals(""+"a0"+null, result); + assertEquals("" + "a0" + null, result); } finally { context.close(); } } - @Test - public void testOptionalV2() throws Exception { - Context context = startServer(new OptionalTestHandler()); - OptionalTestV2 c = context.getClient().proxy(OptionalTestV2.class); - try { - String result; + @Test + public void testOptionalV2() throws Exception { + Context context = startServer(new OptionalTestHandler()); + OptionalTestV2 c = context.getClient().proxy(OptionalTestV2.class); + try { + String result; - result = c.m01("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + result = c.m01("a0", "a1"); + assertEquals("" + "a0" + "a1", result); - } finally { - context.close(); - } - } + } finally { + context.close(); + } + } - @Test + @Test public void testOptionalV22() throws Exception { Context context = startServer2(new OptionalTestHandler()); OptionalTestV2 c = context.getClient().proxy(OptionalTestV2.class); @@ -199,79 +201,93 @@ public void testOptionalV22() throws Exception { String result; result = c.m01("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + assertEquals("" + "a0" + "a1", result); } finally { context.close(); } } - public static interface IndexTestV1 { - public String m01(String a0); - public String m02(@Optional String a0); - public String m03(@Optional String a0); - } - - public static interface IndexTestV2 { - public String m01(@Optional @Index(1) String a1, @Index(0) String a0); - public String m02(@Index(1) @Optional String a1, @Optional String a2); - public String m03(@Index(1) @Optional String a1, @Index(0) @Optional String a0); - } - - public static interface IndexTestV2Full { - public String m01(String a0, @Optional String a1); - public String m02(@Optional String a0, @Optional String a1, @Optional String a2); - public String m03(@Optional String a0, @Optional String a1); - } - - public static class IndexTestHandlerV1 implements IndexTestV1 { - public IndexTestHandlerV1() { } - public String m01(String a0) { - return ""+a0; - } - public String m02(@Optional String a0) { - return ""+a0; - } - public String m03(@Optional String a0) { - return ""+a0; - } - } - - public static class IndexTestHandlerV2 { - public IndexTestHandlerV2() { } - public String m01(@Optional @Index(1) String a1, @Index(0) String a0) { - return ""+a0+a1; - } - public String m02(@Index(1) @Optional String a1, @Optional String a2) { - return ""+a1+a2; - } - public String m03(@Index(1) @Optional String a1, @Index(0) @Optional String a0) { - return ""+a0+a1; - } - } - - @Test - public void testIndexV1ClientV2Server() throws Exception { - Context context = startServer(new IndexTestHandlerV2()); - IndexTestV1 c = context.getClient().proxy(IndexTestV1.class); - try { - String result; - - result = c.m01("a0"); - assertEquals(""+"a0"+null, result); - - result = c.m02("a0"); - assertEquals(""+null+null, result); - - result = c.m03("a0"); - assertEquals(""+"a0"+null, result); - - } finally { - context.close(); - } - } - - @Test + public static interface IndexTestV1 { + public String m01(String a0); + + public String m02(@Optional String a0); + + public String m03(@Optional String a0); + } + + public static interface IndexTestV2 { + public String m01(@Optional @Index(1) String a1, @Index(0) String a0); + + public String m02(@Index(1) @Optional String a1, @Optional String a2); + + public String m03(@Index(1) @Optional String a1, @Index(0) @Optional String a0); + } + + public static interface IndexTestV2Full { + public String m01(String a0, @Optional String a1); + + public String m02(@Optional String a0, @Optional String a1, @Optional String a2); + + public String m03(@Optional String a0, @Optional String a1); + } + + public static class IndexTestHandlerV1 implements IndexTestV1 { + public IndexTestHandlerV1() { + } + + public String m01(String a0) { + return "" + a0; + } + + public String m02(@Optional String a0) { + return "" + a0; + } + + public String m03(@Optional String a0) { + return "" + a0; + } + } + + public static class IndexTestHandlerV2 { + public IndexTestHandlerV2() { + } + + public String m01(@Optional @Index(1) String a1, @Index(0) String a0) { + return "" + a0 + a1; + } + + public String m02(@Index(1) @Optional String a1, @Optional String a2) { + return "" + a1 + a2; + } + + public String m03(@Index(1) @Optional String a1, @Index(0) @Optional String a0) { + return "" + a0 + a1; + } + } + + @Test + public void testIndexV1ClientV2Server() throws Exception { + Context context = startServer(new IndexTestHandlerV2()); + IndexTestV1 c = context.getClient().proxy(IndexTestV1.class); + try { + String result; + + result = c.m01("a0"); + assertEquals("" + "a0" + null, result); + + result = c.m02("a0"); + assertEquals("" + null + null, result); + + result = c.m03("a0"); + assertEquals("" + "a0" + null, result); + + } finally { + context.close(); + } + } + + @Test public void testIndexV1ClientV2Server2() throws Exception { Context context = startServer2(new IndexTestHandlerV2()); IndexTestV1 c = context.getClient().proxy(IndexTestV1.class); @@ -279,41 +295,41 @@ public void testIndexV1ClientV2Server2() throws Exception { String result; result = c.m01("a0"); - assertEquals(""+"a0"+null, result); + assertEquals("" + "a0" + null, result); result = c.m02("a0"); - assertEquals(""+null+null, result); + assertEquals("" + null + null, result); result = c.m03("a0"); - assertEquals(""+"a0"+null, result); + assertEquals("" + "a0" + null, result); } finally { context.close(); } } - @Test - public void testIndexV2ClientV1Server() throws Exception { - Context context = startServer(new IndexTestHandlerV1()); - IndexTestV2 c = context.getClient().proxy(IndexTestV2.class); - try { - String result; + @Test + public void testIndexV2ClientV1Server() throws Exception { + Context context = startServer(new IndexTestHandlerV1()); + IndexTestV2 c = context.getClient().proxy(IndexTestV2.class); + try { + String result; - result = c.m01("a1", "a0"); - assertEquals(""+"a0", result); + result = c.m01("a1", "a0"); + assertEquals("" + "a0", result); - result = c.m02("a1", "a2"); - assertEquals(""+null, result); + result = c.m02("a1", "a2"); + assertEquals("" + null, result); - result = c.m03("a1", "a0"); - assertEquals(""+"a0", result); + result = c.m03("a1", "a0"); + assertEquals("" + "a0", result); - } finally { - context.close(); - } - } + } finally { + context.close(); + } + } - @Test + @Test public void testIndexV2ClientV1Server2() throws Exception { Context context = startServer2(new IndexTestHandlerV1()); IndexTestV2 c = context.getClient().proxy(IndexTestV2.class); @@ -321,41 +337,41 @@ public void testIndexV2ClientV1Server2() throws Exception { String result; result = c.m01("a1", "a0"); - assertEquals(""+"a0", result); + assertEquals("" + "a0", result); result = c.m02("a1", "a2"); - assertEquals(""+null, result); + assertEquals("" + null, result); result = c.m03("a1", "a0"); - assertEquals(""+"a0", result); + assertEquals("" + "a0", result); } finally { context.close(); } } - @Test - public void testIndexV2FullClientV2Server() throws Exception { - Context context = startServer(new IndexTestHandlerV2()); - IndexTestV2Full c = context.getClient().proxy(IndexTestV2Full.class); - try { - String result; + @Test + public void testIndexV2FullClientV2Server() throws Exception { + Context context = startServer(new IndexTestHandlerV2()); + IndexTestV2Full c = context.getClient().proxy(IndexTestV2Full.class); + try { + String result; - result = c.m01("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + result = c.m01("a0", "a1"); + assertEquals("" + "a0" + "a1", result); - result = c.m02("a0", "a1", "a2"); - assertEquals(""+"a1"+"a2", result); + result = c.m02("a0", "a1", "a2"); + assertEquals("" + "a1" + "a2", result); - result = c.m03("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + result = c.m03("a0", "a1"); + assertEquals("" + "a0" + "a1", result); - } finally { - context.close(); - } - } + } finally { + context.close(); + } + } - @Test + @Test public void testIndexV2FullClientV2Server2() throws Exception { Context context = startServer2(new IndexTestHandlerV2()); IndexTestV2Full c = context.getClient().proxy(IndexTestV2Full.class); @@ -363,17 +379,16 @@ public void testIndexV2FullClientV2Server2() throws Exception { String result; result = c.m01("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + assertEquals("" + "a0" + "a1", result); result = c.m02("a0", "a1", "a2"); - assertEquals(""+"a1"+"a2", result); + assertEquals("" + "a1" + "a2", result); result = c.m03("a0", "a1"); - assertEquals(""+"a0"+"a1", result); + assertEquals("" + "a0" + "a1", result); } finally { context.close(); } } } - diff --git a/src/test/java/org/msgpack/rpc/reflect/DispatcherTest.java b/src/test/java/org/msgpack/rpc/reflect/DispatcherTest.java index 6026992..65b19f3 100644 --- a/src/test/java/org/msgpack/rpc/reflect/DispatcherTest.java +++ b/src/test/java/org/msgpack/rpc/reflect/DispatcherTest.java @@ -17,93 +17,87 @@ // package org.msgpack.rpc.reflect; -import org.msgpack.*; import org.msgpack.rpc.*; -import org.msgpack.rpc.dispatcher.*; -import org.msgpack.rpc.config.*; -import org.msgpack.rpc.loop.*; -import org.msgpack.rpc.loop.netty.*; import java.util.*; -import junit.framework.*; import org.junit.Test; import org.msgpack.type.Value; public class DispatcherTest extends ReflectTest { - @Test - public void testSyncHandler() throws Exception { - Context context = startServer(new SyncHandler()); - Client c = context.getClient(); - try { - Value result; - - result = c.callApply("m01", new Object[]{}); - assertTrue(result.isRawValue()); - assertEquals("m01", result.asRawValue().getString()); - - result = c.callApply("m02", new Object[]{"furuhashi"}); - assertTrue(result.isRawValue()); - assertEquals("m02"+"furuhashi", result.asRawValue().getString()); - - result = c.callApply("m03", new Object[]{1978}); - assertTrue(result.isRawValue()); - assertEquals("m03"+1978, result.asRawValue().getString()); - - List list = new ArrayList(); - list.add("sadayuki"); - list.add("kumofs"); - result = c.callApply("m04", new Object[]{list}); - assertTrue(result.isRawValue()); - assertEquals("m04"+stringify1(list), result.asRawValue().getString()); - - List> alist = new ArrayList>(); - List alist_n1 = new ArrayList(); - alist_n1.add("1"); - alist_n1.add("2"); - alist_n1.add("3"); - alist.add(alist_n1); - List alist_n2 = new ArrayList(); - alist_n2.add("a"); - alist_n2.add("b"); - alist_n2.add("c"); - alist.add(alist_n2); - result = c.callApply("m05", new Object[]{alist}); - assertTrue(result.isRawValue()); - assertEquals("m05"+stringify2(alist), result.asRawValue().getString()); - - result = c.callApply("m06", new Object[]{"viver", 2006}); - assertTrue(result.isRawValue()); - assertEquals("m06"+"viver"+2006, result.asRawValue().getString()); - - } finally { - context.close(); - } - } - - @Test + @Test + public void testSyncHandler() throws Exception { + Context context = startServer(new SyncHandler()); + Client c = context.getClient(); + try { + Value result; + + result = c.callApply("m01", new Object[] {}); + assertTrue(result.isRawValue()); + assertEquals("m01", result.asRawValue().getString()); + + result = c.callApply("m02", new Object[] { "furuhashi" }); + assertTrue(result.isRawValue()); + assertEquals("m02" + "furuhashi", result.asRawValue().getString()); + + result = c.callApply("m03", new Object[] { 1978 }); + assertTrue(result.isRawValue()); + assertEquals("m03" + 1978, result.asRawValue().getString()); + + List list = new ArrayList(); + list.add("sadayuki"); + list.add("kumofs"); + result = c.callApply("m04", new Object[] { list }); + assertTrue(result.isRawValue()); + assertEquals("m04" + stringify1(list), result.asRawValue().getString()); + + List> alist = new ArrayList>(); + List alist_n1 = new ArrayList(); + alist_n1.add("1"); + alist_n1.add("2"); + alist_n1.add("3"); + alist.add(alist_n1); + List alist_n2 = new ArrayList(); + alist_n2.add("a"); + alist_n2.add("b"); + alist_n2.add("c"); + alist.add(alist_n2); + result = c.callApply("m05", new Object[] { alist }); + assertTrue(result.isRawValue()); + assertEquals("m05" + stringify2(alist), result.asRawValue().getString()); + + result = c.callApply("m06", new Object[] { "viver", 2006 }); + assertTrue(result.isRawValue()); + assertEquals("m06" + "viver" + 2006, result.asRawValue().getString()); + + } finally { + context.close(); + } + } + + @Test public void testSyncHandler2() throws Exception { Context context = startServer2(new SyncHandler()); Client c = context.getClient(); try { Value result; - result = c.callApply("m01", new Object[]{}); + result = c.callApply("m01", new Object[] {}); assertTrue(result.isRawValue()); assertEquals("m01", result.asRawValue().getString()); - result = c.callApply("m02", new Object[]{"furuhashi"}); + result = c.callApply("m02", new Object[] { "furuhashi" }); assertTrue(result.isRawValue()); - assertEquals("m02"+"furuhashi", result.asRawValue().getString()); + assertEquals("m02" + "furuhashi", result.asRawValue().getString()); - result = c.callApply("m03", new Object[]{1978}); + result = c.callApply("m03", new Object[] { 1978 }); assertTrue(result.isRawValue()); - assertEquals("m03"+1978, result.asRawValue().getString()); + assertEquals("m03" + 1978, result.asRawValue().getString()); List list = new ArrayList(); list.add("sadayuki"); list.add("kumofs"); - result = c.callApply("m04", new Object[]{list}); + result = c.callApply("m04", new Object[] { list }); assertTrue(result.isRawValue()); - assertEquals("m04"+stringify1(list), result.asRawValue().getString()); + assertEquals("m04" + stringify1(list), result.asRawValue().getString()); List> alist = new ArrayList>(); List alist_n1 = new ArrayList(); @@ -116,13 +110,13 @@ public void testSyncHandler2() throws Exception { alist_n2.add("b"); alist_n2.add("c"); alist.add(alist_n2); - result = c.callApply("m05", new Object[]{alist}); + result = c.callApply("m05", new Object[] { alist }); assertTrue(result.isRawValue()); - assertEquals("m05"+stringify2(alist), result.asRawValue().getString()); + assertEquals("m05" + stringify2(alist), result.asRawValue().getString()); - result = c.callApply("m06", new Object[]{"viver", 2006}); + result = c.callApply("m06", new Object[] { "viver", 2006 }); assertTrue(result.isRawValue()); - assertEquals("m06"+"viver"+2006, result.asRawValue().getString()); + assertEquals("m06" + "viver" + 2006, result.asRawValue().getString()); } finally { context.close(); @@ -130,54 +124,54 @@ public void testSyncHandler2() throws Exception { } @Test - public void testAsyncHandler() throws Exception { - Context context = startServer(new AsyncHandler()); - Client c = context.getClient(); - try { - Value result; - - result = c.callApply("m01", new Object[]{}); - assertTrue(result.isRawValue()); - assertEquals("m01", result.asRawValue().getString()); - - result = c.callApply("m02", new Object[]{"furuhashi"}); - assertTrue(result.isRawValue()); - assertEquals("m02"+"furuhashi", result.asRawValue().getString()); - - result = c.callApply("m03", new Object[]{1978}); - assertTrue(result.isRawValue()); - assertEquals("m03"+1978, result.asRawValue().getString()); - - List list = new ArrayList(); - list.add("sadayuki"); - list.add("kumofs"); - result = c.callApply("m04", new Object[]{list}); - assertTrue(result.isRawValue()); - assertEquals("m04"+stringify1(list), result.asRawValue().getString()); - - List> alist = new ArrayList>(); - List alist_n1 = new ArrayList(); - alist_n1.add("1"); - alist_n1.add("2"); - alist_n1.add("3"); - alist.add(alist_n1); - List alist_n2 = new ArrayList(); - alist_n2.add("a"); - alist_n2.add("b"); - alist_n2.add("c"); - alist.add(alist_n2); - result = c.callApply("m05", new Object[]{alist}); - assertTrue(result.isRawValue()); - assertEquals("m05"+stringify2(alist), result.asRawValue().getString()); - - result = c.callApply("m06", new Object[]{"viver", 2006}); - assertTrue(result.isRawValue()); - assertEquals("m06"+"viver"+2006, result.asRawValue().getString()); - - } finally { - context.close(); - } - } + public void testAsyncHandler() throws Exception { + Context context = startServer(new AsyncHandler()); + Client c = context.getClient(); + try { + Value result; + + result = c.callApply("m01", new Object[] {}); + assertTrue(result.isRawValue()); + assertEquals("m01", result.asRawValue().getString()); + + result = c.callApply("m02", new Object[] { "furuhashi" }); + assertTrue(result.isRawValue()); + assertEquals("m02" + "furuhashi", result.asRawValue().getString()); + + result = c.callApply("m03", new Object[] { 1978 }); + assertTrue(result.isRawValue()); + assertEquals("m03" + 1978, result.asRawValue().getString()); + + List list = new ArrayList(); + list.add("sadayuki"); + list.add("kumofs"); + result = c.callApply("m04", new Object[] { list }); + assertTrue(result.isRawValue()); + assertEquals("m04" + stringify1(list), result.asRawValue().getString()); + + List> alist = new ArrayList>(); + List alist_n1 = new ArrayList(); + alist_n1.add("1"); + alist_n1.add("2"); + alist_n1.add("3"); + alist.add(alist_n1); + List alist_n2 = new ArrayList(); + alist_n2.add("a"); + alist_n2.add("b"); + alist_n2.add("c"); + alist.add(alist_n2); + result = c.callApply("m05", new Object[] { alist }); + assertTrue(result.isRawValue()); + assertEquals("m05" + stringify2(alist), result.asRawValue().getString()); + + result = c.callApply("m06", new Object[] { "viver", 2006 }); + assertTrue(result.isRawValue()); + assertEquals("m06" + "viver" + 2006, result.asRawValue().getString()); + + } finally { + context.close(); + } + } @Test public void testAsyncHandler2() throws Exception { @@ -186,24 +180,24 @@ public void testAsyncHandler2() throws Exception { try { Value result; - result = c.callApply("m01", new Object[]{}); + result = c.callApply("m01", new Object[] {}); assertTrue(result.isRawValue()); assertEquals("m01", result.asRawValue().getString()); - result = c.callApply("m02", new Object[]{"furuhashi"}); + result = c.callApply("m02", new Object[] { "furuhashi" }); assertTrue(result.isRawValue()); - assertEquals("m02"+"furuhashi", result.asRawValue().getString()); + assertEquals("m02" + "furuhashi", result.asRawValue().getString()); - result = c.callApply("m03", new Object[]{1978}); + result = c.callApply("m03", new Object[] { 1978 }); assertTrue(result.isRawValue()); - assertEquals("m03"+1978, result.asRawValue().getString()); + assertEquals("m03" + 1978, result.asRawValue().getString()); List list = new ArrayList(); list.add("sadayuki"); list.add("kumofs"); - result = c.callApply("m04", new Object[]{list}); + result = c.callApply("m04", new Object[] { list }); assertTrue(result.isRawValue()); - assertEquals("m04"+stringify1(list), result.asRawValue().getString()); + assertEquals("m04" + stringify1(list), result.asRawValue().getString()); List> alist = new ArrayList>(); List alist_n1 = new ArrayList(); @@ -216,17 +210,16 @@ public void testAsyncHandler2() throws Exception { alist_n2.add("b"); alist_n2.add("c"); alist.add(alist_n2); - result = c.callApply("m05", new Object[]{alist}); + result = c.callApply("m05", new Object[] { alist }); assertTrue(result.isRawValue()); - assertEquals("m05"+stringify2(alist), result.asRawValue().getString()); + assertEquals("m05" + stringify2(alist), result.asRawValue().getString()); - result = c.callApply("m06", new Object[]{"viver", 2006}); + result = c.callApply("m06", new Object[] { "viver", 2006 }); assertTrue(result.isRawValue()); - assertEquals("m06"+"viver"+2006, result.asRawValue().getString()); + assertEquals("m06" + "viver" + 2006, result.asRawValue().getString()); } finally { context.close(); } } } - diff --git a/src/test/java/org/msgpack/rpc/reflect/ProxyTest.java b/src/test/java/org/msgpack/rpc/reflect/ProxyTest.java index af8f568..c93f83c 100644 --- a/src/test/java/org/msgpack/rpc/reflect/ProxyTest.java +++ b/src/test/java/org/msgpack/rpc/reflect/ProxyTest.java @@ -17,21 +17,12 @@ // package org.msgpack.rpc.reflect; -import org.msgpack.*; -import org.msgpack.rpc.*; -import org.msgpack.rpc.dispatcher.*; -import org.msgpack.rpc.config.*; -import org.msgpack.rpc.loop.*; -import org.msgpack.rpc.loop.netty.*; import java.util.*; -import junit.framework.*; - -import org.junit.BeforeClass; import org.junit.Test; public class ProxyTest extends ReflectTest { - + @Test public void testSyncClient() throws Exception { Context context = startServer(new SyncHandler()); @@ -115,28 +106,28 @@ public void testSyncClient2() throws Exception { context.close(); } } - - public interface NullOrException{ - - public String returnNullValue(); - - public String throwsException() throws Exception; - + + public interface NullOrException { + + public String returnNullValue(); + + public String throwsException() throws Exception; + } - - public class NullOrExceptionSyncHandler implements NullOrException{ - public String returnNullValue(){ - return null; - } - - public String throwsException() throws Exception{ - throw new Exception("Error"); - } - + public class NullOrExceptionSyncHandler implements NullOrException { + + public String returnNullValue() { + return null; + } + + public String throwsException() throws Exception { + throw new Exception("Error"); + } + } - + /*public void testNullReturnValue() throws Exception { Context context = startServer2(new NullOrExceptionSyncHandler()); NullOrException c = context.getClient().proxy(NullOrException.class); @@ -144,5 +135,5 @@ public String throwsException() throws Exception{ String result = c.returnNullValue(); Assert.assertNull(result); }*/ - + } diff --git a/src/test/java/org/msgpack/rpc/reflect/ReflectTest.java b/src/test/java/org/msgpack/rpc/reflect/ReflectTest.java index 0d093eb..01b3c1e 100644 --- a/src/test/java/org/msgpack/rpc/reflect/ReflectTest.java +++ b/src/test/java/org/msgpack/rpc/reflect/ReflectTest.java @@ -31,156 +31,170 @@ public abstract class ReflectTest extends TestCase { static MessagePack messagePack = new MessagePack(); - static String stringify1(Iterable a) { - StringBuilder sb = new StringBuilder(); - for(String s : a) { - sb.append(s); - } - return sb.toString(); - } - - static String stringify2(Iterable> a) { - StringBuilder sb = new StringBuilder(); - for(Iterable i : a) { - for(String s : i) { - sb.append(s); - } - } - return sb.toString(); - } - - - public static interface TestRpc { - public String m01(); - public String m02(String a1); - public String m03(int a1); - public String m04(List a1); - public String m05(List> a1); - public String m06(String a1, int a2); - } - - public static class SyncHandler implements TestRpc { - public String m01() { - return "m01"; - } - - public String m02(String a1) { - return "m02"+a1; - } - - public String m03(int a1) { - return "m03"+a1; - } - - public String m04(List a1) { - return "m04"+stringify1(a1); - } - - public String m05(List> a1) { - return "m05"+stringify2(a1); - } - - public String m06(String a1, int a2) { - return "m06"+a1+a2; - } - } - - public static class AsyncHandler { + static String stringify1(Iterable a) { + StringBuilder sb = new StringBuilder(); + for (String s : a) { + sb.append(s); + } + return sb.toString(); + } + + static String stringify2(Iterable> a) { + StringBuilder sb = new StringBuilder(); + for (Iterable i : a) { + for (String s : i) { + sb.append(s); + } + } + return sb.toString(); + } + + public static interface TestRpc { + public String m01(); + + public String m02(String a1); + + public String m03(int a1); + + public String m04(List a1); + + public String m05(List> a1); + + public String m06(String a1, int a2); + } + + public static class SyncHandler implements TestRpc { + public String m01() { + return "m01"; + } + + public String m02(String a1) { + return "m02" + a1; + } + + public String m03(int a1) { + return "m03" + a1; + } + + public String m04(List a1) { + return "m04" + stringify1(a1); + } + + public String m05(List> a1) { + return "m05" + stringify2(a1); + } + + public String m06(String a1, int a2) { + return "m06" + a1 + a2; + } + } + + public static class AsyncHandler { public void m01(Callback callback) { callback.sendResult("m01"); } public void m02(Callback callback, String a1) { - callback.sendResult("m02"+a1); + callback.sendResult("m02" + a1); } public void m03(Callback callback, int a1) { - callback.sendResult("m03"+a1); + callback.sendResult("m03" + a1); } public void m04(Callback callback, List a1) { - callback.sendResult("m04"+stringify1(a1)); + callback.sendResult("m04" + stringify1(a1)); } public void m05(Callback callback, List> a1) { - callback.sendResult("m05"+stringify2(a1)); + callback.sendResult("m05" + stringify2(a1)); } public void m06(Callback callback, String a1, int a2) { - callback.sendResult("m06"+a1+a2); + callback.sendResult("m06" + a1 + a2); + } + } + + static class Context { + Server server; + Client client; + int port; + + Context(Server server, Client client, int port) { + this.server = server; + this.client = client; + this.port = port; + } + + Server getServer() { + return server; + } + + Client getClient() { + return client; + } + + int getPort() { + return port; } + + void close() { + server.close(); + client.close(); + } + } + + int port = 19860; + + public synchronized Context startServer(Object handler) throws Exception { + Server svr = new Server(EventLoop.defaultEventLoop()); + Client c = new Client("127.0.0.1", port); + c.setRequestTimeout(10); + try { + svr.serve(new ReflectionMethodDispatcher(handler, + MethodSelector.selectRpcServerMethod(handler.getClass()))); + svr.listen(port); + } catch (Exception e) { + svr.close(); + c.close(); + throw e; + } + return new Context(svr, c, port++); + } + + public synchronized Context startServer2(Object handler) throws Exception { + Server svr = new Server(EventLoop.defaultEventLoop()); + Client c = new Client("127.0.0.1", port); + c.setRequestTimeout(10); + try { + svr.serve(new JavassistMethodDispatcher(handler, + MethodSelector.selectRpcServerMethod(handler.getClass()))); + svr.listen(port); + } catch (Exception e) { + svr.close(); + c.close(); + throw e; + } + return new Context(svr, c, port++); } - static class Context { - Server server; - Client client; - int port; - Context(Server server, Client client, int port) { - this.server = server; - this.client = client; - this.port = port; - } - Server getServer() { return server; } - Client getClient() { return client; } - int getPort() { return port; } - void close() { - server.close(); - client.close(); - } - } - - int port = 19860; - - public synchronized Context startServer(Object handler) throws Exception { - Server svr = new Server(EventLoop.defaultEventLoop()); - Client c = new Client("127.0.0.1", port); - c.setRequestTimeout(10); - try { - svr.serve(new ReflectionMethodDispatcher(handler, - MethodSelector.selectRpcServerMethod(handler.getClass()))); - svr.listen(port); - } catch (Exception e) { - svr.close(); - c.close(); - throw e; - } - return new Context(svr, c, port++); - } - - public synchronized Context startServer2(Object handler) throws Exception { - Server svr = new Server(EventLoop.defaultEventLoop()); - Client c = new Client("127.0.0.1", port); - c.setRequestTimeout(10); - try { - svr.serve(new JavassistMethodDispatcher(handler, - MethodSelector.selectRpcServerMethod(handler.getClass()))); - svr.listen(port); - } catch (Exception e) { - svr.close(); - c.close(); - throw e; - } - return new Context(svr, c, port++); - } - - static class ReflectionMethodDispatcher extends MethodDispatcher { - public ReflectionMethodDispatcher(Object target, Method[] methods) { - super(new Reflect(ReflectTest.messagePack),target, methods); - InvokerBuilder builder = new ReflectionInvokerBuilder(ReflectTest.messagePack);//ReflectionInvokerBuilder.getInstance(); - for(Method method : methods) { + static class ReflectionMethodDispatcher extends MethodDispatcher { + public ReflectionMethodDispatcher(Object target, Method[] methods) { + super(new Reflect(ReflectTest.messagePack), target, methods); + InvokerBuilder builder = new ReflectionInvokerBuilder(ReflectTest.messagePack);// ReflectionInvokerBuilder.getInstance(); + for (Method method : methods) { methodMap.put(method.getName(), builder.buildInvoker(method)); } - } - } + } + } - static class JavassistMethodDispatcher extends MethodDispatcher { + static class JavassistMethodDispatcher extends MethodDispatcher { public JavassistMethodDispatcher(Object target, Method[] methods) { - super(new Reflect(ReflectTest.messagePack),target, methods); + super(new Reflect(ReflectTest.messagePack), target, methods); InvokerBuilder builder = new JavassistInvokerBuilder(ReflectTest.messagePack); - for(Method method : methods) { + for (Method method : methods) { methodMap.put(method.getName(), builder.buildInvoker(method)); } } - } + } } -