Class: InvocationContext
- Inherits:
-
AbstractInvocationContext
- Object
- AbstractInvocationContext
- InvocationContext
- Includes:
- Enumerable
- Defined in:
- lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb
Instance Method Summary collapse
- #[](i) ⇒ Object
- #[]=(i, value) ⇒ Object
- #build_command(command) ⇒ Object
- #create_instance(*args) ⇒ Object
- #current_command ⇒ Object
- #encapsulate_payload_item(payload_item) ⇒ Object
- #execute ⇒ Object
- #finalize(command, is_executed, interpreter, connection_type, tcp_ip_address) ⇒ Object
- #get_enum_name(*args) ⇒ Object
- #get_enum_value(*args) ⇒ Object
- #get_index(*args) ⇒ Object
- #get_instance_field(*args) ⇒ Object
- #get_rank(*args) ⇒ Object
- #get_ref_value(*args) ⇒ Object
- #get_size(*args) ⇒ Object
- #get_static_field(*args) ⇒ Object
- #get_value ⇒ Object
-
#initialize(runtime_name, connection_type, tcp_ip_address, command, is_executed = false) ⇒ InvocationContext
constructor
A new instance of InvocationContext.
- #invoke_generic_method(*args) ⇒ Object
- #invoke_generic_static_method(*args) ⇒ Object
- #invoke_instance_method(*args) ⇒ Object
- #invoke_static_method(*args) ⇒ Object
- #iterator ⇒ Object
- #response_command ⇒ Object
- #retrieve_array(*args) ⇒ Object
- #set_index(*args) ⇒ Object
- #set_instance_field(*args) ⇒ Object
- #set_static_field(*args) ⇒ Object
Methods inherited from AbstractInvocationContext
Constructor Details
#initialize(runtime_name, connection_type, tcp_ip_address, command, is_executed = false) ⇒ InvocationContext
Returns a new instance of InvocationContext.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 9 def initialize(runtime_name, connection_type, tcp_ip_address, command, is_executed = false) @is_executed = is_executed @runtime_name = runtime_name @connection_type = connection_type @tcp_ip_address = tcp_ip_address @current_command = command @response_command = nil @interpreter = Interpreter.new # generates warning # ObjectSpace.define_finalizer(self, self.finalize(@current_command, @is_executed, @interpreter, @connection_type, @tcp_ip_address)) end |
Instance Method Details
#[](i) ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 39 def [](i) if not [CommandType::REFERENCE, CommandType::ARRAY_GET_ITEM].include? @current_command.command_type raise "Object is not iterable" else invocation_context_iterator = InvocationContextIterator.new(self) invocation_context_iterator[i] end end |
#[]=(i, value) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 48 def []=(i, value) if not [CommandType::REFERENCE, CommandType::ARRAY_SET_ITEM, CommandType::ARRAY_GET_ITEM].include? @current_command.command_type raise "Object is not iterable" else invocation_context_iterator = InvocationContextIterator.new(self) invocation_context_iterator[i] = value end end |
#build_command(command) ⇒ Object
165 166 167 168 169 170 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 165 def build_command(command) command.payload.each_index { |i| command.payload[i] = encapsulate_payload_item(command.payload[i]) } return command.prepend_arg_to_payload(@current_command) end |
#create_instance(*args) ⇒ Object
78 79 80 81 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 78 def create_instance(*args) local_command = Command.new(@runtime_name, CommandType::CREATE_CLASS_INSTANCE, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#current_command ⇒ Object
194 195 196 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 194 def current_command @current_command end |
#encapsulate_payload_item(payload_item) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 172 def encapsulate_payload_item(payload_item) if payload_item.is_a? Command payload_item.payload.each_index { |i| payload_item.payload[i] = encapsulate_payload_item(payload_item.payload[i]) } return payload_item elsif payload_item.is_a? InvocationContext return payload_item.current_command elsif payload_item.is_a? Array payload_item.each_index { |i| payload_item[i] = encapsulate_payload_item(payload_item[i]) } return Command.new(@runtime_name, CommandType::ARRAY, [*payload_item]) else return Command.new(@runtime_name, CommandType::VALUE, [*payload_item]) end end |
#execute ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 57 def execute @response_command = @interpreter.execute(@current_command, @connection_type, @tcp_ip_address) if @response_command.command_type == CommandType::EXCEPTION raise ExceptionThrower.throw_exception(@response_command) end if @response_command.command_type == CommandType::CREATE_CLASS_INSTANCE @current_command = @response_command @is_executed = true return self end return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, @response_command, true) end |
#finalize(command, is_executed, interpreter, connection_type, tcp_ip_address) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 22 def finalize(command, is_executed, interpreter, connection_type, tcp_ip_address) proc do if command.command_type == CommandType::REFERENCE && is_executed == true destructCommand = Command.new(@runtime_name, CommandType::DESTRUCT_REFERENCE, command.payload) interpreter.execute(destructCommand, connection_type, tcp_ip_address) end end end |
#get_enum_name(*args) ⇒ Object
138 139 140 141 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 138 def get_enum_name(*args) local_command = Command.new(@runtime_name, CommandType::GET_ENUM_NAME, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_enum_value(*args) ⇒ Object
143 144 145 146 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 143 def get_enum_value(*args) local_command = Command.new(@runtime_name, CommandType::GET_ENUM_VALUE, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_index(*args) ⇒ Object
108 109 110 111 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 108 def get_index(*args) local_command = Command.new(@runtime_name, CommandType::ARRAY_GET_ITEM, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_instance_field(*args) ⇒ Object
93 94 95 96 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 93 def get_instance_field(*args) local_command = Command.new(@runtime_name, CommandType::GET_INSTANCE_FIELD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_rank(*args) ⇒ Object
118 119 120 121 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 118 def get_rank(*args) local_command = Command.new(@runtime_name, CommandType::ARRAY_GET_RANK, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_ref_value(*args) ⇒ Object
148 149 150 151 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 148 def get_ref_value(*args) local_command = Command.new(@runtime_name, CommandType::GET_REF_VALUE, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_size(*args) ⇒ Object
113 114 115 116 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 113 def get_size(*args) local_command = Command.new(@runtime_name, CommandType::ARRAY_GET_SIZE, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_static_field(*args) ⇒ Object
83 84 85 86 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 83 def get_static_field(*args) local_command = Command.new(@runtime_name, CommandType::GET_STATIC_FIELD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#get_value ⇒ Object
161 162 163 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 161 def get_value return @current_command.payload[0] end |
#invoke_generic_method(*args) ⇒ Object
133 134 135 136 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 133 def invoke_generic_method(*args) local_command = Command.new(@runtime_name, CommandType::INVOKE_GENERIC_METHOD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#invoke_generic_static_method(*args) ⇒ Object
128 129 130 131 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 128 def invoke_generic_static_method(*args) local_command = Command.new(@runtime_name, CommandType::INVOKE_GENERIC_STATIC_METHOD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#invoke_instance_method(*args) ⇒ Object
73 74 75 76 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 73 def invoke_instance_method(*args) local_command = Command.new(@runtime_name, CommandType::INVOKE_INSTANCE_METHOD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#invoke_static_method(*args) ⇒ Object
103 104 105 106 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 103 def invoke_static_method(*args) local_command = Command.new(@runtime_name, CommandType::INVOKE_STATIC_METHOD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#iterator ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 31 def iterator if not [CommandType::REFERENCE, CommandType::ARRAY_GET_ITEM, CommandType::ARRAY_SET_ITEM].include? @current_command.command_type raise "Object is not iterable" else return InvocationContextIterator.new(self) end end |
#response_command ⇒ Object
198 199 200 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 198 def response_command @response_command end |
#retrieve_array(*args) ⇒ Object
154 155 156 157 158 159 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 154 def retrieve_array(*args) local_command = Command.new(@runtime_name, CommandType::RETRIEVE_ARRAY, [*args]) localInvCtx = InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) localInvCtx.execute return localInvCtx.response_command.payload end |
#set_index(*args) ⇒ Object
123 124 125 126 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 123 def set_index(*args) local_command = Command.new(@runtime_name, CommandType::ARRAY_SET_ITEM, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#set_instance_field(*args) ⇒ Object
98 99 100 101 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 98 def set_instance_field(*args) local_command = Command.new(@runtime_name, CommandType::SET_INSTANCE_FIELD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |
#set_static_field(*args) ⇒ Object
88 89 90 91 |
# File 'lib/javonet-ruby-sdk/sdk/internal/invocation_context.rb', line 88 def set_static_field(*args) local_command = Command.new(@runtime_name, CommandType::SET_STATIC_FIELD, [*args]) return InvocationContext.new(@runtime_name, @connection_type, @tcp_ip_address, build_command(local_command)) end |