Skip to content

Commit

Permalink
quiet logging, cruft removal, comments in C
Browse files Browse the repository at this point in the history
  • Loading branch information
slyphon committed Jun 17, 2011
1 parent 9d97bab commit cb525b7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 23 deletions.
3 changes: 0 additions & 3 deletions ext/zookeeper_base.rb
Expand Up @@ -27,9 +27,6 @@ def reopen(timeout = 10, watcher=nil)
set_default_global_watcher(&watcher)
end


# $stderr.puts "@_running is #{@_running.inspect}"

@start_stop_mutex.synchronize do
init(@host)

Expand Down
27 changes: 9 additions & 18 deletions ext/zookeeper_c.c
Expand Up @@ -25,6 +25,8 @@

static VALUE Zookeeper = Qnil;

// slyphon: possibly add a lock to this for synchronizing during get_next_event

struct zkrb_instance_data {
zhandle_t *zh;
clientid_t myid;
Expand All @@ -41,14 +43,6 @@ typedef enum {
#define IS_SYNC(zkrbcall) ((zkrbcall)==SYNC || (zkrbcall)==SYNC_WATCH)
#define IS_ASYNC(zkrbcall) ((zkrbcall)==ASYNC || (zkrbcall)==ASYNC_WATCH)

pthread_mutex_t zkrb_init_mutex = PTHREAD_MUTEX_INITIALIZER;

/*static void zkrb_debug_log(char *debug_str) {*/
/* if (ZKRBDebugging) {*/
/* fprintf(stderr, "%s\n", debug_str);*/
/* }*/
/*}*/

static int destroy_zkrb_instance(struct zkrb_instance_data* ptr) {
int rv = ZOK;

Expand Down Expand Up @@ -161,8 +155,6 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
zkrb_calling_context *ctx =
zkrb_calling_context_alloc(ZKRB_GLOBAL_REQ, zk_local_ctx->queue);

/* pthread_mutex_lock(&zkrb_init_mutex);*/

zk_local_ctx->zh =
zookeeper_init(
RSTRING_PTR(hostPort),
Expand All @@ -172,8 +164,6 @@ static VALUE method_init(int argc, VALUE* argv, VALUE self) {
ctx,
0);

/* pthread_mutex_unlock(&zkrb_init_mutex);*/

#warning [wickman] TODO handle this properly on the Ruby side rather than C side
if (!zk_local_ctx->zh) {
rb_raise(rb_eRuntimeError, "error connecting to zookeeper: %d", errno);
Expand Down Expand Up @@ -483,6 +473,8 @@ static int is_running(VALUE self) {
}


/* slyphon: NEED TO PROTECT THIS AGAINST SHUTDOWN */

static VALUE method_get_next_event(VALUE self, VALUE blocking) {
char buf[64];
FETCH_DATA_PTR(self, zk);
Expand Down Expand Up @@ -578,14 +570,15 @@ static VALUE method_close_handle(VALUE self) {
fprintf(stderr, "CLOSING ZK INSTANCE:");
print_zkrb_instance_data(zk);
}

/* Note that after zookeeper_close() returns, ZK handle is invalid */
int rc = destroy_zkrb_instance(zk);


// this is a value on the ruby side we can check to see if destroy_zkrb_instance
// has been called
rb_iv_set(self, "@_closed", Qtrue);


/* Note that after zookeeper_close() returns, ZK handle is invalid */
int rc = destroy_zkrb_instance(zk);

return INT2FIX(rc);
}

Expand All @@ -609,7 +602,6 @@ static VALUE method_recv_timeout(VALUE self) {
return INT2NUM(zoo_recv_timeout(zk->zh));
}

// how do you make a class method??
static VALUE klass_method_set_debug_level(VALUE klass, VALUE level) {
Check_Type(level, T_FIXNUM);
ZKRBDebugging = (FIX2INT(level) == ZOO_LOG_LEVEL_DEBUG);
Expand Down Expand Up @@ -651,7 +643,6 @@ static void zkrb_define_methods(void) {
DEFINE_METHOD(has_events, 0);

// Make these class methods?
/* DEFINE_METHOD(set_debug_level, 1);*/
DEFINE_METHOD(zerror, 1);

rb_define_singleton_method(Zookeeper, "set_debug_level", klass_method_set_debug_level, 1);
Expand Down
2 changes: 1 addition & 1 deletion lib/zookeeper/common.rb
Expand Up @@ -41,7 +41,7 @@ def get_completion(req_id)

def dispatch_next_callback(blocking=true)
hash = get_next_event(blocking)
Zookeeper.logger.debug { "get_next_event returned: #{hash.inspect}" }
# Zookeeper.logger.debug { "get_next_event returned: #{hash.inspect}" }

return nil unless hash

Expand Down
2 changes: 1 addition & 1 deletion lib/zookeeper/em_client.rb
Expand Up @@ -111,7 +111,7 @@ def detach
# we have an event waiting
def notify_readable
if @zk_client.running?
logger.debug { "#{self.class.name}: dispatching events while #{@zk_client.running?}" }
# logger.debug { "#{self.class.name}: dispatching events while #{@zk_client.running?}" }

read_io_nb if @zk_client.dispatch_next_callback(false)

Expand Down

0 comments on commit cb525b7

Please sign in to comment.