Class: GRPC::Core::Call

Inherits:
Object
  • Object
show all
Defined in:
ext/grpc/rb_call.c

Constant Summary collapse

INTERNAL_ALL_CALLs =
hash_all_calls

Instance Method Summary collapse

Constructor Details

#initializeObject

Init func that fails by raising an exception.



70
71
72
73
74
75
# File 'ext/grpc/rb_grpc.c', line 70

VALUE grpc_rb_cannot_init(VALUE self) {
  rb_raise(rb_eTypeError,
           "initialization of %s only allowed from the gRPC native layer",
           rb_obj_classname(self));
  return Qnil;
}

Instance Method Details

#cancelObject

Called by clients to cancel an RPC on the server.

Can be called multiple times, from any thread.


173
174
175
176
177
178
179
180
181
182
183
184
# File 'ext/grpc/rb_call.c', line 173

static VALUE grpc_rb_call_cancel(VALUE self) {
  grpc_call *call = NULL;
  grpc_call_error err;
  TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
  err = grpc_call_cancel(call, NULL);
  if (err != GRPC_CALL_OK) {
    rb_raise(grpc_rb_eCallError, "cancel failed: %s (code=%d)",
             grpc_call_error_detail_of(err), err);
  }

  return Qnil;
}

#initialize_copy(self) ⇒ Object

Init/Clone func that fails by raising an exception.



78
79
80
81
82
83
84
# File 'ext/grpc/rb_grpc.c', line 78

VALUE grpc_rb_cannot_init_copy(VALUE copy, VALUE self) {
  (void)self;
  rb_raise(rb_eTypeError,
           "initialization of %s only allowed from the gRPC native layer",
           rb_obj_classname(copy));
  return Qnil;
}

#metadataObject

metadata = call.metadata

Gets the metadata object saved the call.



228
229
230
# File 'ext/grpc/rb_call.c', line 228

static VALUE (VALUE self) {
  return rb_ivar_get(self, );
}

#metadata=(metadata) ⇒ Object

call.metadata = metadata

Saves the metadata hash on the call.



237
238
239
240
241
242
243
244
245
# File 'ext/grpc/rb_call.c', line 237

static VALUE (VALUE self, VALUE ) {
  if (!NIL_P() && TYPE() != T_HASH) {
    rb_raise(rb_eTypeError, "bad metadata: got:<%s> want: <Hash>",
             rb_obj_classname());
    return Qnil;
  }

  return rb_ivar_set(self, , );
}

#peerObject

Called to obtain the peer that this call is connected to.



187
188
189
190
191
192
193
194
195
196
197
# File 'ext/grpc/rb_call.c', line 187

static VALUE grpc_rb_call_get_peer(VALUE self) {
  VALUE res = Qnil;
  grpc_call *call = NULL;
  char *peer = NULL;
  TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);
  peer = grpc_call_get_peer(call);
  res = rb_str_new2(peer);
  gpr_free(peer);

  return res;
}

#cq=(CompletionQueue) ⇒ Object

GRPC::Core::CallOps::SEND_INITIAL_METADATA => <op_value>,

  GRPC::Core::CallOps::SEND_MESSAGE => <op_value>,
  ...
}
tag = Object.new
timeout = 10
call.start_batch(cqueue, tag, timeout, ops)

Start a batch of operations defined in the array ops; when complete, post a
completion of type 'tag' to the completion queue bound to the call.

Also waits for the batch to complete, until timeout is reached.
The order of ops specified in the batch has no significance.
Only one operation of each type can be active at once in any given
batch


631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
# File 'ext/grpc/rb_call.c', line 631

static VALUE grpc_rb_call_run_batch(VALUE self, VALUE cqueue, VALUE tag,
                                    VALUE timeout, VALUE ops_hash) {
  run_batch_stack st;
  grpc_call *call = NULL;
  grpc_event ev;
  grpc_call_error err;
  VALUE result = Qnil;
  VALUE rb_write_flag = rb_ivar_get(self, id_write_flag);
  uint write_flag = 0;
  TypedData_Get_Struct(self, grpc_call, &grpc_call_data_type, call);

  /* Validate the ops args, adding them to a ruby array */
  if (TYPE(ops_hash) != T_HASH) {
    rb_raise(rb_eTypeError, "call#run_batch: ops hash should be a hash");
    return Qnil;
  }
  if (rb_write_flag != Qnil) {
    write_flag = NUM2UINT(rb_write_flag);
  }
  grpc_run_batch_stack_init(&st, write_flag);
  grpc_run_batch_stack_fill_ops(&st, ops_hash);

  /* call grpc_call_start_batch, then wait for it to complete using
   * pluck_event */
  err = grpc_call_start_batch(call, st.ops, st.op_num, ROBJECT(tag), NULL);
  if (err != GRPC_CALL_OK) {
    grpc_run_batch_stack_cleanup(&st);
    rb_raise(grpc_rb_eCallError,
             "grpc_call_start_batch failed with %s (code=%d)",
             grpc_call_error_detail_of(err), err);
    return Qnil;
  }
  ev = grpc_rb_completion_queue_pluck_event(cqueue, tag, timeout);
  if (ev.type == GRPC_QUEUE_TIMEOUT) {
    grpc_run_batch_stack_cleanup(&st);
    rb_raise(grpc_rb_eOutOfTime, "grpc_call_start_batch timed out");
    return Qnil;
  }

  /* Build and return the BatchResult struct result,
     if there is an error, it's reflected in the status */
  result = grpc_run_batch_stack_build_result(&st);
  grpc_run_batch_stack_cleanup(&st);
  return result;
}

#statusObject

status = call.status

Gets the status object saved the call.



204
205
206
# File 'ext/grpc/rb_call.c', line 204

static VALUE grpc_rb_call_get_status(VALUE self) {
  return rb_ivar_get(self, id_status);
}

#status=(status) ⇒ Object

call.status = status

Saves a status object on the call.



213
214
215
216
217
218
219
220
221
# File 'ext/grpc/rb_call.c', line 213

static VALUE grpc_rb_call_set_status(VALUE self, VALUE status) {
  if (!NIL_P(status) && rb_obj_class(status) != grpc_rb_sStatus) {
    rb_raise(rb_eTypeError, "bad status: got:<%s> want: <Struct::Status>",
             rb_obj_classname(status));
    return Qnil;
  }

  return rb_ivar_set(self, id_status, status);
}

#write_flagObject

write_flag = call.write_flag

Gets the write_flag value saved the call.



252
253
254
# File 'ext/grpc/rb_call.c', line 252

static VALUE grpc_rb_call_get_write_flag(VALUE self) {
  return rb_ivar_get(self, id_write_flag);
}

#write_flag=(write_flag) ⇒ Object

call.write_flag = write_flag

Saves the write_flag on the call.



261
262
263
264
265
266
267
268
269
# File 'ext/grpc/rb_call.c', line 261

static VALUE grpc_rb_call_set_write_flag(VALUE self, VALUE write_flag) {
  if (!NIL_P(write_flag) && TYPE(write_flag) != T_FIXNUM) {
    rb_raise(rb_eTypeError, "bad write_flag: got:<%s> want: <Fixnum>",
             rb_obj_classname(write_flag));
    return Qnil;
  }

  return rb_ivar_set(self, id_write_flag, write_flag);
}