class Sumac::Closer

Public Class Methods

new(connection) click to toggle source
# File lib/sumac/closer.rb, line 4
def initialize(connection)
  raise "argument 'connection' must be a Connection" unless connection.is_a?(Connection)
  @connection = connection
  @future = QuackConcurrency::Future.new
end

Public Instance Methods

close() click to toggle source
# File lib/sumac/closer.rb, line 20
def close
  @connection.mutex.synchronize do
    case @connection.at.to_sym
    when :initial, :compatibility_handshake, :initialization_handshake
      @connection.to(:kill)
    when :active
      @connection.to(:initiate_shutdown)
    end
  end
  @future.get
  @connection.scheduler.join
  nil
end
complete() click to toggle source
# File lib/sumac/closer.rb, line 34
def complete
  @future.set
  nil
end
job_finished() click to toggle source
# File lib/sumac/closer.rb, line 10
def job_finished
  try_close if @connection.at?([:shutdown, :kill])
  nil
end
join() click to toggle source
# File lib/sumac/closer.rb, line 39
def join
  @future.get
  @connection.scheduler.join
  nil
end
try_close() click to toggle source
# File lib/sumac/closer.rb, line 15
def try_close
  @connection.to(:close) if can_close?
  nil
end

Private Instance Methods

can_close?() click to toggle source
# File lib/sumac/closer.rb, line 47
def can_close?
  !@connection.call_dispatcher.any_calls_pending? &&
    !@connection.call_processor.any_calls_processing?
end