Permalink
Browse files

cleanup and misc

  • Loading branch information...
1 parent a6d4098 commit 28ab3d09395471bc721fb42423bc27fa40152dd3 @slyphon slyphon committed May 25, 2012
Showing with 34 additions and 39 deletions.
  1. +4 −2 Guardfile
  2. +0 −5 lib/zk/client/base.rb
  3. +30 −32 lib/zk/client/threaded.rb
View
@@ -14,7 +14,9 @@ guard 'rspec', :version => 2 do
watch(%r{^spec/.+_spec\.rb$})
# run all specs when the support files change
- watch(%r{^spec/support}) { 'spec' }
+ watch(%r{^spec/support/.+\.rb$}) { 'spec' }
+
+ watch('spec/shared/client_examples.rb') { 'spec/zk/client_spec.rb' }
watch(%r%^spec/support/client_forker.rb$%) { 'spec/zk/00_forked_client_integration_spec.rb' }
@@ -32,7 +34,7 @@ guard 'rspec', :version => 2 do
when %r{^(?:zk/locker/locker_base|spec/shared/locker)}
Dir["spec/zk/locker/*_spec.rb"]
- when %r{^zk/client/(?:base|state_mixin)}
+ when %r{^zk/client/(?:base|state_mixin|unixisms)}
Dir['spec/zk/{client,client/*,zookeeper}_spec.rb']
when 'zk' # .rb
View
@@ -128,10 +128,6 @@ def mri_closed?
#
# @return [Symbol] state of connection after operation
def reopen(timeout=nil)
-# timeout ||= @session_timeout # XXX: @session_timeout ?
-# cnx.reopen(timeout)
-# @threadpool.start!
-# state
end
# close the underlying connection and clear all pending events.
@@ -287,7 +283,6 @@ def wait_until_connected(timeout=10)
# zk.create("/path", '', :mode => :persistent_sequential)
# # => "/path0"
#
- #
# @example create ephemeral and sequential node
#
# zk.create("/path", '', :sequence => true, :ephemeral => true)
View
@@ -347,14 +347,15 @@ def close!
on_tpool ? shutdown_thread : shutdown_thread.join(30)
end
- # {see Base#close}
+ # {see ZK::Client::Base#close}
def close
super
subs, @fork_subs = @fork_subs, []
subs.each(&:unsubscribe)
nil
end
+
# (see Threadpool#on_threadpool?)
def on_threadpool?
@threadpool and @threadpool.on_threadpool?
@@ -365,6 +366,11 @@ def on_exception(&blk)
@threadpool.on_exception(&blk)
end
+ def closed?
+ return true if @mutex.synchronize { @client_state == CLOSED }
+ super
+ end
+
def create(path, *args)
opts = args.extract_options!
@@ -402,35 +408,12 @@ def raw_event_handler(event)
logger.error { "BUG: Exception caught in raw_event_handler: #{e.to_std_format}" }
end
- def closed?
- return true if @mutex.synchronize { @client_state == CLOSED }
- super
- end
-
- # are we in running (not-paused) state?
- # @private
- def running?
- @mutex.synchronize { @client_state == RUNNING }
- end
-
- # are we in paused state?
- # @private
- def paused?
- @mutex.synchronize { @client_state == PAUSED }
- end
-
- # has shutdown time arrived?
- # @private
- def close_requested?
- @mutex.synchronize { @client_state == CLOSE_REQ }
- end
-
# @private
def wait_until_connected_or_dying(timeout)
time_to_stop = Time.now + timeout
@mutex.synchronize do
- while (@last_cnx_state != Zookeeper::ZOO_CONNECTED_STATE) && (Time.now < time_to_stop) && (@client_state == RUNNING)
+ while (@last_cnx_state != Zookeeper::ZOO_CONNECTED_STATE) && (Time.now < time_to_stop) && running?
@cond.wait(timeout)
end
@@ -439,6 +422,25 @@ def wait_until_connected_or_dying(timeout)
end
private
+ # are we in running (not-paused) state?
+ def running?
+ @client_state == RUNNING
+ end
+
+ # are we in paused state?
+ def paused?
+ @client_state == PAUSED
+ end
+
+ # has shutdown time arrived?
+ def close_requested?
+ @client_state == CLOSE_REQ
+ end
+
+ def dead_or_dying?
+ (@client_state == CLOSE_REQ) || (@client_state == CLOSED)
+ end
+
# this is just here so we can see it in stack traces
def reopen_after_session_expired
reopen
@@ -457,11 +459,11 @@ def reconnect_thread_body
@mutex.synchronize do
# either we havne't seen a valid session update from this
# connection yet, or we're doing fine, so just wait
- @cond.wait_while { !seen_session_state_event? or (valid_session_state? and (@client_state == RUNNING)) }
+ @cond.wait_while { !seen_session_state_event? or (valid_session_state? and running?) }
# we've entered into a non-running state, so we exit
# note: need to restart this thread after a fork in parent
- if @client_state != RUNNING
+ unless running?
logger.debug { "session failure watcher thread exiting, @client_state: #{@client_state}" }
return
end
@@ -512,7 +514,7 @@ def call_and_check_rc(meth, opts)
wait_until_connected_or_dying(retry_duration)
- if (@last_cnx_state != Zookeeper::ZOO_CONNECTED_STATE) || (Time.now > time_to_stop) || (@client_state != RUNNING)
+ if (@last_cnx_state != Zookeeper::ZOO_CONNECTED_STATE) || (Time.now > time_to_stop) || !running?
raise e
else
retry
@@ -543,10 +545,6 @@ def create_connection(*args)
::Zookeeper.new(*args)
end
- def dead_or_dying?
- (@client_state == CLOSE_REQ) || (@client_state == CLOSED)
- end
-
def unlocked_connect(opts={})
return if @cnx
timeout = opts.fetch(:timeout, @connection_timeout)

0 comments on commit 28ab3d0

Please sign in to comment.