Class: Majordomo::Client
- Inherits:
-
Object
- Object
- Majordomo::Client
- Defined in:
- ext/majordomo/client.c
Class Method Summary collapse
-
.new(*args) ⇒ Object
Creates a new Majordomo::Client instance.
Instance Method Summary collapse
-
#broker ⇒ String
Returns the URI of the broker this client is connected to.
-
#close ⇒ nil
Close the client connection to the broker.
-
#recv("service") ⇒ String?
Send a request to the broker and get a reply even if it has to retry several times.
-
#send("service", "message") ⇒ Boolean
Send a request to the broker.
-
#timeout ⇒ Fixnum
Returns the request timeout for this client (in msecs).
-
#timeout=(val) ⇒ nil
Sets the request timeout for this client (in msecs).
Class Method Details
.Majordomo::Client.new("tcp: //0.0.0.0:5555") ⇒ Majordomo::Client .Majordomo::Client.new("tcp: //0.0.0.0:5555", true) ⇒ Majordomo::Client
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'ext/majordomo/client.c', line 75
static VALUE rb_majordomo_client_s_new(int argc, VALUE *argv, VALUE klass)
{
rb_majordomo_client_t *client = NULL;
struct nogvl_md_client_new_args args;
VALUE obj, broker, verbose;
rb_scan_args(argc, argv, "11", &broker, &verbose);
if (verbose == Qnil)
verbose = Qfalse;
Check_Type(broker, T_STRING);
obj = Data_Make_Struct(klass, rb_majordomo_client_t, rb_mark_majordomo_client, rb_free_majordomo_client, client);
args.broker = RSTRING_PTR(broker);
args.verbose = (verbose == Qtrue ? 1 : 0);
client->client = (mdp_client_t *)rb_thread_blocking_region(rb_nogvl_mdp_client_new, (void *)&args, RUBY_UBF_IO, 0);
client->broker = rb_str_new4(broker);
client->timeout = INT2NUM(MAJORDOMO_CLIENT_TIMEOUT);
#ifndef HAVE_RB_THREAD_BLOCKING_REGION
client->recv_buffer = zlist_new();
#endif
rb_obj_call_init(obj, 0, NULL);
return obj;
}
|
Instance Method Details
#broker ⇒ String
108 109 110 111 |
# File 'ext/majordomo/client.c', line 108
static VALUE rb_majordomo_client_broker(VALUE obj){
GetMajordomoClient(obj);
return client->broker;
}
|
#close ⇒ nil
283 284 285 286 287 288 289 |
# File 'ext/majordomo/client.c', line 283
static VALUE rb_majordomo_client_close(VALUE obj){
VALUE ret;
GetMajordomoClient(obj);
ret = rb_thread_blocking_region(rb_nogvl_mdp_client_close, (void *)client->client, RUBY_UBF_IO, 0);
client->client = NULL;
return ret;
}
|
#recv("service") ⇒ String?
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
# File 'ext/majordomo/client.c', line 256
static VALUE rb_majordomo_client_recv(VALUE obj, VALUE service){
VALUE rep;
zmsg_t *reply = NULL;
struct nogvl_md_client_recv_args args;
GetMajordomoClient(obj);
Check_Type(service, T_STRING);
args.client = client;
args.service = RSTRING_PTR(service);
reply = (zmsg_t *)rb_thread_blocking_region(rb_nogvl_mdp_client_recv, (void *)&args, RUBY_UBF_IO, 0);
if (!reply)
return Qnil;
rep = MajordomoEncode(rb_str_new2(zmsg_popstr(reply)));
zmsg_destroy(&reply);
return rep;
}
|
#send("service", "message") ⇒ Boolean
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'ext/majordomo/client.c', line 192
static VALUE rb_majordomo_client_send(VALUE obj, VALUE service, VALUE message){
struct nogvl_md_client_send_args args;
GetMajordomoClient(obj);
Check_Type(service, T_STRING);
Check_Type(message, T_STRING);
args.client = client->client;
args.service = RSTRING_PTR(service);
args.request = zmsg_new();
if (!args.request)
return Qfalse;
if (zmsg_pushstr(args.request, RSTRING_PTR(message)) != 0){
zmsg_destroy(&args.request);
return Qfalse;
}
rb_thread_blocking_region(rb_nogvl_mdp_client_send, (void *)&args, RUBY_UBF_IO, 0);
return Qtrue;
}
|
#timeout ⇒ Fixnum
124 125 126 127 |
# File 'ext/majordomo/client.c', line 124
static VALUE rb_majordomo_client_timeout(VALUE obj){
GetMajordomoClient(obj);
return client->timeout;
}
|
#timeout=(val) ⇒ nil
141 142 143 144 145 146 147 |
# File 'ext/majordomo/client.c', line 141
static VALUE rb_majordomo_client_timeout_equals(VALUE obj, VALUE timeout){
GetMajordomoClient(obj);
Check_Type(timeout, T_FIXNUM);
mdp_client_set_timeout(client->client, FIX2INT(timeout));
client->timeout = timeout;
return Qnil;
}
|