Class: Contender::ExecutorService Abstract

Inherits:
Executor
  • Object
show all
Defined in:
lib/contender/executor_service.rb

Overview

This class is abstract.

Direct Known Subclasses

Pool::PoolExecutor

Instance Method Summary collapse

Methods inherited from Executor

#execute

Instance Method Details

#await_termination(timeout) ⇒ Boolean

This method is abstract.

Parameters:

  • timeout (Float)

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


19
20
21
# File 'lib/contender/executor_service.rb', line 19

def await_termination(timeout)
  raise NotImplementedError
end

#future_for(task) ⇒ FutureTask

Parameters:

  • task (Object)

Returns:



89
90
91
# File 'lib/contender/executor_service.rb', line 89

def future_for(task)
  FutureTask.new task
end

#invoke_all(tasks) ⇒ Array<FutureTask>

Parameters:

  • tasks (Array<Object>)

Returns:



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/contender/executor_service.rb', line 52

def invoke_all(tasks)
  finished = false
  futures = Array.new

  begin
    tasks.each do |task|
      future = create_task_for task

      futures.push future
      execute future
    end

    futures.each do |future|
      unless future.done?
        begin
          future.result
        rescue CancellationError
        rescue ExecutionError
          # The caller can deal with these errors
        end
      end
    end

    finished = true
    futures
  ensure
    unless finished
      futures.each do |future|
        future.cancel true
      end
    end
  end
end

#shutdownundefined

This method is abstract.

Returns:

  • (undefined)

Raises:

  • (NotImplementedError)


6
7
8
# File 'lib/contender/executor_service.rb', line 6

def shutdown
  raise NotImplementedError
end

#shutdown!Array

This method is abstract.

Returns:

  • (Array)

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/contender/executor_service.rb', line 12

def shutdown!
  raise NotImplementedError
end

#shutdown?Boolean

This method is abstract.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/contender/executor_service.rb', line 25

def shutdown?
  raise NotImplementedError
end

#submit(callable = nil, &block) ⇒ FutureTask

Parameters:

  • callable (Object) (defaults to: nil)

Returns:

Raises:

  • (ArgumentError)

    If neither a block nor callable were given



39
40
41
42
43
44
45
46
47
# File 'lib/contender/executor_service.rb', line 39

def submit(callable = nil, &block)
  callable ||= block

  raise ArgumentError unless callable

  future = future_for callable
  execute future
  future
end

#terminated?Boolean

This method is abstract.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


31
32
33
# File 'lib/contender/executor_service.rb', line 31

def terminated?
  raise NotImplementedError
end