class Concurrent::AbstractExecutorService

@!macro abstract_executor_service_public_api @!visibility private

Constants

FALLBACK_POLICIES

The set of possible fallback policies that may be set at thread pool creation.

Attributes

fallback_policy[R]

@!macro executor_service_attr_reader_fallback_policy

Public Class Methods

new(*args, &block) click to toggle source

Create a new thread pool.

Calls superclass method
# File lib/concurrent/executor/abstract_executor_service.rb, line 20
def initialize(*args, &block)
  super(&nil)
  synchronize { ns_initialize(*args, &block) }
end

Public Instance Methods

auto_terminate=(value) click to toggle source

@!macro executor_service_method_auto_terminate_setter

# File lib/concurrent/executor/abstract_executor_service.rb, line 61
def auto_terminate=(value)
  synchronize { self.ns_auto_terminate = value }
end
auto_terminate?() click to toggle source

@!macro executor_service_method_auto_terminate_question

# File lib/concurrent/executor/abstract_executor_service.rb, line 56
def auto_terminate?
  synchronize { ns_auto_terminate? }
end
kill() click to toggle source

@!macro executor_service_method_kill

# File lib/concurrent/executor/abstract_executor_service.rb, line 31
def kill
  raise NotImplementedError
end
running?() click to toggle source

@!macro executor_service_method_running_question

# File lib/concurrent/executor/abstract_executor_service.rb, line 41
def running?
  synchronize { ns_running? }
end
shutdown() click to toggle source

@!macro executor_service_method_shutdown

# File lib/concurrent/executor/abstract_executor_service.rb, line 26
def shutdown
  raise NotImplementedError
end
shutdown?() click to toggle source

@!macro executor_service_method_shutdown_question

# File lib/concurrent/executor/abstract_executor_service.rb, line 51
def shutdown?
  synchronize { ns_shutdown? }
end
shuttingdown?() click to toggle source

@!macro executor_service_method_shuttingdown_question

# File lib/concurrent/executor/abstract_executor_service.rb, line 46
def shuttingdown?
  synchronize { ns_shuttingdown? }
end
wait_for_termination(timeout = nil) click to toggle source

@!macro executor_service_method_wait_for_termination

# File lib/concurrent/executor/abstract_executor_service.rb, line 36
def wait_for_termination(timeout = nil)
  raise NotImplementedError
end

Private Instance Methods

handle_fallback(*args) { |*args| ... } click to toggle source

Handler which executes the `fallback_policy` once the queue size reaches `max_queue`.

@param [Array] args the arguments to the task which is being handled.

@!visibility private

# File lib/concurrent/executor/abstract_executor_service.rb, line 73
def handle_fallback(*args)
  case fallback_policy
  when :abort
    raise RejectedExecutionError
  when :discard
    false
  when :caller_runs
    begin
      yield(*args)
    rescue => ex
      # let it fail
      log DEBUG, ex
    end
    true
  else
    fail "Unknown fallback policy #{fallback_policy}"
  end
end
ns_auto_terminate=(value) click to toggle source
# File lib/concurrent/executor/abstract_executor_service.rb, line 116
def ns_auto_terminate=(value)
  case value
  when true
    AtExit.add(self) { terminate_at_exit }
    @auto_terminate = true
  when false
    AtExit.delete(self)
    @auto_terminate = false
  else
    raise ArgumentError
  end
end
ns_auto_terminate?() click to toggle source
# File lib/concurrent/executor/abstract_executor_service.rb, line 112
def ns_auto_terminate?
  !!@auto_terminate
end
ns_execute(*args, &task) click to toggle source
# File lib/concurrent/executor/abstract_executor_service.rb, line 92
def ns_execute(*args, &task)
  raise NotImplementedError
end
ns_kill_execution() click to toggle source

@!macro [attach] executor_service_method_ns_kill_execution

Callback method called when the executor has been killed.
The default behavior is to do nothing.
# File lib/concurrent/executor/abstract_executor_service.rb, line 108
def ns_kill_execution
  # do nothing
end
ns_shutdown_execution() click to toggle source

@!macro [attach] executor_service_method_ns_shutdown_execution

Callback method called when an orderly shutdown has completed.
The default behavior is to signal all waiting threads.
# File lib/concurrent/executor/abstract_executor_service.rb, line 100
def ns_shutdown_execution
  # do nothing
end
terminate_at_exit() click to toggle source
# File lib/concurrent/executor/abstract_executor_service.rb, line 129
def terminate_at_exit
  kill # TODO be gentle first
  wait_for_termination(10)
end