Class: BackPressure::Executor Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/back_pressure/executor.rb

Overview

This class is abstract.

Implementations of ‘BackPressure::Executor` are capable of providing blocking back-pressure to callers using their `execute` or `execute!` methods.

This interface makes no guarantees about how implementations go about controlling back-pressure or the order in which execution will occur in the presence or absence of blocking back-pressure.

Author:

Since:

  • 1.0.0

Direct Known Subclasses

GatedExecutor

Instance Method Summary collapse

Instance Method Details

#blocked?Boolean

Note:

This method should be used only for observation-based tooling.

Helper method for determining if any threads are currently blocked by back-pressure.

Returns:

  • (Boolean)

Since:

  • 1.0.0



93
94
95
# File 'lib/back_pressure/executor.rb', line 93

def blocked?
  fail NotImplementedError
end

#blocked_threadsSet{Thread}

Note:

This method should be used only for observation-based tooling.

Helper method for observing which threads, if any, are blocked at the instant the method is invoked. The returned value is a frozen snapshot, and the included threads are not guaranteed to be still blocking by the time they are accessed.

Returns:

  • (Set{Thread})

Since:

  • 1.0.0



81
82
83
# File 'lib/back_pressure/executor.rb', line 81

def blocked_threads
  fail NotImplementedError
end

#execute(blocking_time_limit: nil) ⇒ Boolean

Executes the provided block, after waiting out any back-pressure, returning ‘true` IFF the block was executed.

Parameters:

  • blocking_time_limit (Number) (defaults to: nil)

    : the maximum time to wait, in seconds, when back-pressure is being applied, before aborting (optional).

Yield Returns:

  • (void)

    : the value returned by the block is ignored by this method.

Returns:

  • (Boolean)

    : returns ‘true` if block was successfully executed, and `false` if tht `blocking_time_limit` was reached before it could be executed.

Since:

  • 1.0.0



48
49
50
# File 'lib/back_pressure/executor.rb', line 48

def execute(blocking_time_limit: nil)
  fail NotImplementedError
end

#execute!(blocking_time_limit: nil) ⇒ Object

Executes the provided block, after waiting out any back-pressure, returning the result of the block or raising an ‘ExecutionExpired` exception if the provided limit was reached before execution could begin.

Parameters:

  • blocking_time_limit (Number) (defaults to: nil)

    : the maximum time to wait, in seconds, when back-pressure is being applied, before aborting (optional).

Yield Returns:

  • (Object)

    : the value returned from the block is returned by this method

Returns:

  • (Object)

    : returns the unmodified value of the result of executing the provided block.

Raises:

Since:

  • 1.0.0



67
68
69
# File 'lib/back_pressure/executor.rb', line 67

def execute!(blocking_time_limit: nil)
  fail NotImplementedError
end