Class: Handler
- Inherits:
-
AbstractHandler
- Object
- AbstractHandler
- Handler
- Defined in:
- lib/javonet-ruby-sdk/core/handler/handler.rb
Class Method Summary collapse
- .handle_command(command) ⇒ Object
- .initialize_handler_dict ⇒ Object
- .is_response_array(response) ⇒ Object
- .parse_response(response, runtime_name) ⇒ Object
Methods inherited from AbstractHandler
Class Method Details
.handle_command(command) ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/javonet-ruby-sdk/core/handler/handler.rb', line 170 def self.handle_command(command) initialize_handler_dict begin if command.command_type == CommandType::RETRIEVE_ARRAY response_array = $handler_dict[CommandType::REFERENCE].handle_command(command.payload[0]) return Command.create_array_response(response_array, command.runtime_name) end response = $handler_dict[command.command_type].handle_command(command) if response.is_a? Exception ExceptionSerializer.serialize_exception(response, command) else parse_response(response, command.runtime_name) end rescue Exception => e ExceptionSerializer.serialize_exception(e, command) end end |
.initialize_handler_dict ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/javonet-ruby-sdk/core/handler/handler.rb', line 64 def self.initialize_handler_dict return unless $handler_dict.empty? value_handler = ValueHandler.new load_library_handler = LoadLibraryHandler.new invoke_static_method_handler = InvokeStaticMethodHandler.new get_static_field_handler = GetStaticFieldHandler.new set_static_field_handler = SetStaticFieldHandler.new create_class_instance_handler = CreateClassInstanceHandler.new get_type_handler = GetTypeHandler.new resolve_instance_handler = ResolveInstanceHandler.new get_module_handler = GetModuleHandler.new invoke_instance_method_handler = InvokeInstanceMethodHandler.new exception_handler = ExceptionHandler.new heartbeat_handler = HeartbeatHandler.new casting_handler = CastingHandler.new get_instance_field_handler = GetInstanceFieldHandler.new optimize_handler = OptimizeHandler.new generate_lib_handler = GenerateLibHandler.new invoke_global_function_handler = InvokeGlobalFunctionHandler.new destruct_reference_handler = DestructReferenceHandler.new array_reference_handler = ArrayReferenceHandler.new array_get_item_handler = ArrayGetItemHandler.new array_get_size_handler = ArrayGetSizeHandler.new array_get_rank_handler = ArrayGetRankHandler.new array_set_item_handler = ArraySetItemHandler.new array_handler = ArrayHandler.new retrieve_array_handler = RetrieveArrayHandler.new set_instance_field_handler = SetInstanceFieldHandler.new invoke_generic_static_method_handler = InvokeGenericStaticMethodHandler.new invoke_generic_method_handler = InvokeGenericMethodHandler.new get_enum_item_handler = GetEnumItemHandler.new get_enum_name_handler = GetEnumNameHandler.new get_enum_value_handler = GetEnumValueHandler.new as_ref_handler = AsRefHandler.new as_out_handler = AsOutHandler.new get_ref_value_handler = GetRefValueHandler.new enable_namespace_handler = EnableNamespaceHandler.new enable_type_handler = EnableTypeHandler.new create_null_handler = CreateNullHandler.new get_static_method_as_delegate_handler = GetStaticMethodAsDelegateHandler.new get_instance_method_as_delegate_handler = GetInstanceMethodAsDelegateHandler.new pass_delegate_handler = PassDelegateHandler.new invoke_delegate_handler = InvokeDelegateHandler.new convert_type_handler = ConvertTypeHandler.new add_event_listener_handler = AddEventListenerHandler.new plugin_wrapper_handler = PluginWrapperHandler.new get_async_operation_result_handler = GetAsyncOperationResultHandler.new as_kwargs_handler = AsKwargsHandler.new get_result_type_handler = GetResultTypeHandler.new get_global_field_handler = GetGlobalFieldHandler.new register_for_update_handler = RegisterForUpdateHandler.new value_for_update_handler = ValueForUpdateHandler.new $handler_dict[CommandType::VALUE] = value_handler $handler_dict[CommandType::LOAD_LIBRARY] = load_library_handler $handler_dict[CommandType::INVOKE_STATIC_METHOD] = invoke_static_method_handler $handler_dict[CommandType::GET_STATIC_FIELD] = get_static_field_handler $handler_dict[CommandType::SET_STATIC_FIELD] = set_static_field_handler $handler_dict[CommandType::CREATE_CLASS_INSTANCE] = create_class_instance_handler $handler_dict[CommandType::GET_TYPE] = get_type_handler $handler_dict[CommandType::REFERENCE] = resolve_instance_handler $handler_dict[CommandType::GET_MODULE] = get_module_handler $handler_dict[CommandType::INVOKE_INSTANCE_METHOD] = invoke_instance_method_handler $handler_dict[CommandType::EXCEPTION] = exception_handler $handler_dict[CommandType::HEARTBEAT] = heartbeat_handler $handler_dict[CommandType::CAST] = casting_handler $handler_dict[CommandType::GET_INSTANCE_FIELD] = get_instance_field_handler $handler_dict[CommandType::OPTIMIZE] = optimize_handler $handler_dict[CommandType::GENERATE_LIB] = generate_lib_handler $handler_dict[CommandType::INVOKE_GLOBAL_FUNCTION] = invoke_global_function_handler $handler_dict[CommandType::DESTRUCT_REFERENCE] = destruct_reference_handler $handler_dict[CommandType::ARRAY_REFERENCE] = array_reference_handler $handler_dict[CommandType::ARRAY_GET_ITEM] = array_get_item_handler $handler_dict[CommandType::ARRAY_GET_SIZE] = array_get_size_handler $handler_dict[CommandType::ARRAY_GET_RANK] = array_get_rank_handler $handler_dict[CommandType::ARRAY_SET_ITEM] = array_set_item_handler $handler_dict[CommandType::ARRAY] = array_handler $handler_dict[CommandType::RETRIEVE_ARRAY] = retrieve_array_handler $handler_dict[CommandType::SET_INSTANCE_FIELD] = set_instance_field_handler $handler_dict[CommandType::INVOKE_GENERIC_STATIC_METHOD] = invoke_generic_static_method_handler $handler_dict[CommandType::INVOKE_GENERIC_METHOD] = invoke_generic_method_handler $handler_dict[CommandType::GET_ENUM_ITEM] = get_enum_item_handler $handler_dict[CommandType::GET_ENUM_NAME] = get_enum_name_handler $handler_dict[CommandType::GET_ENUM_VALUE] = get_enum_value_handler $handler_dict[CommandType::AS_REF] = as_ref_handler $handler_dict[CommandType::AS_OUT] = as_out_handler $handler_dict[CommandType::GET_REF_VALUE] = get_ref_value_handler $handler_dict[CommandType::ENABLE_NAMESPACE] = enable_namespace_handler $handler_dict[CommandType::ENABLE_TYPE] = enable_type_handler $handler_dict[CommandType::CREATE_NULL] = create_null_handler $handler_dict[CommandType::GET_STATIC_METHOD_AS_DELEGATE] = get_static_method_as_delegate_handler $handler_dict[CommandType::GET_INSTANCE_METHOD_AS_DELEGATE] = get_instance_method_as_delegate_handler $handler_dict[CommandType::PASS_DELEGATE] = pass_delegate_handler $handler_dict[CommandType::INVOKE_DELEGATE] = invoke_delegate_handler $handler_dict[CommandType::CONVERT_TYPE] = convert_type_handler $handler_dict[CommandType::ADD_EVENT_LISTENER] = add_event_listener_handler $handler_dict[CommandType::PLUGIN_WRAPPER] = plugin_wrapper_handler $handler_dict[CommandType::GET_ASYNC_OPERATION_RESULT] = get_async_operation_result_handler $handler_dict[CommandType::AS_KWARGS] = as_kwargs_handler $handler_dict[CommandType::GET_RESULT_TYPE] = get_result_type_handler $handler_dict[CommandType::GET_GLOBAL_FIELD] = get_global_field_handler $handler_dict[CommandType::REGISTER_FOR_UPDATE] = register_for_update_handler $handler_dict[CommandType::VALUE_FOR_UPDATE] = value_for_update_handler end |
.is_response_array(response) ⇒ Object
224 225 226 |
# File 'lib/javonet-ruby-sdk/core/handler/handler.rb', line 224 def self.is_response_array(response) response.is_a? Array end |
.parse_response(response, runtime_name) ⇒ Object
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/javonet-ruby-sdk/core/handler/handler.rb', line 192 def self.parse_response(response, runtime_name) # Build base response (primitive vs reference) response_command = if TypesHandler.primitive_or_none?(response) Command.create_response(response, runtime_name) else reference_cache = ReferencesCache.instance guid = reference_cache.cache_reference(response) Command.create_reference(guid, runtime_name) end # Append ValueForUpdate commands from invocation contexts if present invocation_contexts = RegisterForUpdateHandler.get_or_create_context_dict if invocation_contexts && !invocation_contexts.empty? ref_cache = ReferencesCache.instance invocation_contexts.each do |key, value| instance_guid = ref_cache.cache_reference(value) update_context_command = Command.new( runtime_name, CommandType::VALUE_FOR_UPDATE, [key.to_s, instance_guid] ) response_command = response_command.add_arg_to_payload(update_context_command) end # Clear all entries after processing this request invocation_contexts.clear end response_command end |