static grpc_resolver *zookeeper_create(grpc_resolver_args *args, const char *lb_policy_name) { zookeeper_resolver *r; size_t length; char *path = args->uri->path; if (0 == strcmp(args->uri->authority, "")) { gpr_log(GPR_ERROR, "No authority specified in zookeeper uri"); return NULL; } /** Removes the trailing slash if exists */ length = strlen(path); if (length > 1 && path[length - 1] == '/') { path[length - 1] = 0; } r = gpr_malloc(sizeof(zookeeper_resolver)); memset(r, 0, sizeof(*r)); gpr_ref_init(&r->refs, 1); gpr_mu_init(&r->mu); grpc_resolver_init(&r->base, &zookeeper_resolver_vtable); r->name = gpr_strdup(path); r->client_channel_factory = args->client_channel_factory; grpc_client_channel_factory_ref(r->client_channel_factory); r->lb_policy_name = gpr_strdup(lb_policy_name); /** Initializes zookeeper client */ zoo_set_debug_level(ZOO_LOG_LEVEL_WARN); r->zookeeper_handle = zookeeper_init(args->uri->authority, zookeeper_global_watcher, GRPC_ZOOKEEPER_SESSION_TIMEOUT, 0, 0, 0); if (r->zookeeper_handle == NULL) { gpr_log(GPR_ERROR, "Unable to connect to zookeeper server"); return NULL; } return &r->base; }
void grpc_client_channel_finish_initialization( grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, grpc_resolver *resolver, grpc_client_channel_factory *client_channel_factory) { /* post construction initialization: set the transport setup pointer */ GPR_ASSERT(client_channel_factory != NULL); grpc_channel_element *elem = grpc_channel_stack_last_element(channel_stack); channel_data *chand = elem->channel_data; gpr_mu_lock(&chand->mu); GPR_ASSERT(!chand->resolver); chand->resolver = resolver; GRPC_RESOLVER_REF(resolver, "channel"); if (!grpc_closure_list_empty(chand->waiting_for_config_closures) || chand->exit_idle_when_lb_policy_arrives) { chand->started_resolving = true; GRPC_CHANNEL_STACK_REF(chand->owning_stack, "resolver"); grpc_resolver_next(exec_ctx, resolver, &chand->resolver_result, &chand->on_resolver_result_changed); } chand->client_channel_factory = client_channel_factory; grpc_client_channel_factory_ref(client_channel_factory); gpr_mu_unlock(&chand->mu); }