Class: Google::Cloud::Debugger::Transmitter

Inherits:
Object
  • Object
show all
Defined in:
lib/google/cloud/debugger/transmitter.rb

Overview

Transmitter

Responsible for submit evaluated breakpoints back to Stackdriver Debugger service asynchronously. It maintains a thread pool.

The transmitter is controlled by the debugger agent it belongs to. Debugger agent submits evaluated breakpoint asynchronously, and the transmitter submits the breakpoints to Stackdriver Debugger service.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#agentGoogle::Cloud::Debugger::Agent

The debugger agent this transmiter belongs to



60
61
62
# File 'lib/google/cloud/debugger/transmitter.rb', line 60

def agent
  @agent
end

#max_queueObject Also known as: max_queue_size

Maximum backlog size for this transmitter's queue



64
65
66
# File 'lib/google/cloud/debugger/transmitter.rb', line 64

def max_queue
  @max_queue
end

#threadsObject

Maximum threads used in the thread pool



70
71
72
# File 'lib/google/cloud/debugger/transmitter.rb', line 70

def threads
  @threads
end

Instance Method Details

#on_error {|callback| ... } ⇒ Object

Register to be notified of errors when raised.

If an unhandled error has occurred the transmitter will attempt to recover from the error and resume submitting breakpoints.

Multiple error handlers can be added.

Yields:

  • (callback)

    The block to be called when an error is raised.

Yield Parameters:

  • error (Exception)

    The error raised.



158
159
160
# File 'lib/google/cloud/debugger/transmitter.rb', line 158

def on_error &block
  @error_callbacks << block
end

#startTransmitter

Starts the transmitter and its thread pool.

Returns:

  • (Transmitter)

    returns self so calls can be chained.



110
111
112
113
# File 'lib/google/cloud/debugger/transmitter.rb', line 110

def start
  # no-op
  self
end

#started?boolean

Whether the transmitter has been started.

Returns:

  • (boolean)

    true when started, false otherwise.



134
135
136
# File 'lib/google/cloud/debugger/transmitter.rb', line 134

def started?
  @thread_pool&.running?
end

#stop(timeout = nil) ⇒ Transmitter

Stops the transmitter and its thread pool. Once stopped, cannot be started again.

Returns:

  • (Transmitter)

    returns self so calls can be chained.



120
121
122
123
124
125
126
127
# File 'lib/google/cloud/debugger/transmitter.rb', line 120

def stop timeout = nil
  if @thread_pool
    @thread_pool.shutdown
    @thread_pool.wait_for_termination timeout
  end

  self
end

#stopped?boolean

Whether the transmitter has been stopped.

Returns:

  • (boolean)

    true when stopped, false otherwise.



143
144
145
# File 'lib/google/cloud/debugger/transmitter.rb', line 143

def stopped?
  !started?
end

#submit(breakpoint) ⇒ Object

Enqueue an evaluated breakpoint to be submitted by the transmitter.

Raises:

  • (TransmitterError)

    if there are no resources available to make queue the API call on the thread pool.



95
96
97
98
99
100
101
102
103
104
# File 'lib/google/cloud/debugger/transmitter.rb', line 95

def submit breakpoint
  Concurrent::Promises.future_on @thread_pool, breakpoint do |bp|
    submit_sync bp
  end
rescue Concurrent::RejectedExecutionError => e
  raise TransmitterError.new(
    "Error asynchronously submitting breakpoint: #{e.message}",
    breakpoint
  )
end