module Concurrent::JavaExecutor

def <<(task)

Returns:
  • (self) - returns itself

Parameters:
  • task (Proc) -- the asynchronous task to perform
def <<(task)
  post(&task)
  self
end

def kill

not running.
will be accepted. Has no additional effect if the executor is
complete but enqueued tasks will be dismissed and no new tasks
Begin an immediate shutdown. In-progress tasks will be allowed to
def kill
  @executor.shutdownNow
  nil
end

def post(*args)

Raises:
  • (ArgumentError) - if no task is given

Returns:
  • (Boolean) - `true` if the task is queued, `false` if the executor

Other tags:
    Yield: - the asynchronous task to perform

Parameters:
  • args (Array) -- zero or more arguments to be passed to the task
def post(*args)
  raise ArgumentError.new('no block given') unless block_given?
  if running?
    @executor.submit{ yield(*args) }
    true
  else
    false
  end
rescue Java::JavaUtilConcurrent::RejectedExecutionException => ex
  raise RejectedExecutionError
end

def running?

Returns:
  • (Boolean) - `true` when running, `false` when shutting down or shutdown
def running?
  ! (shuttingdown? || shutdown?)
end

def set_shutdown_hook

def set_shutdown_hook
  # without this the process may fail to exit
  at_exit { self.kill }
end

def shutdown

executor is not running.
but no new tasks will be accepted. Has no additional effect if the
Begin an orderly shutdown. Tasks already in the queue will be executed,
def shutdown
  @executor.shutdown
  nil
end

def shutdown?

Returns:
  • (Boolean) - `true` when shutdown, `false` when shutting down or running
def shutdown?
  @executor.isShutdown || @executor.isTerminated
end

def shuttingdown?

Returns:
  • (Boolean) - `true` when not running and not shutdown, else `false`
def shuttingdown?
  if @executor.respond_to? :isTerminating
    @executor.isTerminating
  else
    false
  end
end

def wait_for_termination(timeout)

Returns:
  • (Boolean) - `true` if shutdown complete or false on `timeout`

Parameters:
  • timeout (Integer) -- the maximum number of seconds to wait for shutdown to complete

Other tags:
    Note: - Does not initiate shutdown or termination. Either `shutdown` or `kill`
def wait_for_termination(timeout)
  @executor.awaitTermination(1000 * timeout, java.util.concurrent.TimeUnit::MILLISECONDS)
end