class Sensu::Transport::Base

Attributes

logger[RW]

@!attribute [rw] logger

@return [Logger] the Sensu logger object.

Public Class Methods

descendants() click to toggle source

Discover available transports (Subclasses)

# File lib/sensu/transport/base.rb, line 138
def self.descendants
  ObjectSpace.each_object(Class).select do |klass|
    klass < self
  end
end
new() click to toggle source
# File lib/sensu/transport/base.rb, line 17
def initialize
  @on_error = Proc.new {}
  @before_reconnect = Proc.new {}
  @after_reconnect = Proc.new {}
end

Public Instance Methods

ack(*args, &callback) click to toggle source

Alias for acknowledge(). This should be superseded by a proper alias via alias_method in the transport class.

# File lib/sensu/transport/base.rb, line 122
def ack(*args, &callback)
  acknowledge(*args, &callback)
end
acknowledge(info) { |info| ... } click to toggle source

Acknowledge the delivery of a message from the transport.

@param info [Hash] message information, eg. contains its id. @yield [info] passes acknowledgment info to an optional callback/block.

# File lib/sensu/transport/base.rb, line 116
def acknowledge(info)
  yield(info) if block_given?
end
after_reconnect(&callback) click to toggle source

Set the after reconnect callback.

@param callback [Proc] called after reconnecting to the

transport.

@return [Proc] the after reconnect callback.

# File lib/sensu/transport/base.rb, line 46
def after_reconnect(&callback)
  @after_reconnect = callback
end
before_reconnect(&callback) click to toggle source

Set the before reconnect callback.

@param callback [Proc] called before attempting to reconnect

to the transport.

@return [Proc] the before reconnect callback.

# File lib/sensu/transport/base.rb, line 37
def before_reconnect(&callback)
  @before_reconnect = callback
end
close() click to toggle source

Close the transport connection.

# File lib/sensu/transport/base.rb, line 68
def close; end
connect(options={}) click to toggle source

Transport connection setup.

@param options [Hash, String]

# File lib/sensu/transport/base.rb, line 53
def connect(options={}); end
connected?() click to toggle source

Indicates if connected to the transport.

@return [TrueClass, FalseClass]

# File lib/sensu/transport/base.rb, line 63
def connected?
  false
end
on_error(&callback) click to toggle source

Set the error callback.

@param callback [Proc] called in the event of a transport

error, the exception object should be passed as a parameter.

@return [Proc] the error callback.

# File lib/sensu/transport/base.rb, line 28
def on_error(&callback)
  @on_error = callback
end
publish(type, pipe, message, options={}) { |info| ... } click to toggle source

Publish a message to the transport.

@param type [Symbol] the transport pipe type, possible values

are: :direct and :fanout.

@param pipe [String] the transport pipe name. @param message [String] the message to be published to the transport. @param options [Hash] the options to publish the message with. @yield [info] passes publish info to an optional callback/block. @yieldparam info [Hash] contains publish information, which

may contain an error object (:error).
# File lib/sensu/transport/base.rb, line 80
def publish(type, pipe, message, options={})
  info = {:error => nil}
  yield(info) if block_given?
end
reconnect(force=false) click to toggle source

Reconnect to the transport.

@param force [Boolean] the reconnect.

# File lib/sensu/transport/base.rb, line 58
def reconnect(force=false); end
stats(funnel, options={}) { |info| ... } click to toggle source

Transport funnel stats, such as message and consumer counts.

@param funnel [String] the transport funnel to get stats for. @param options [Hash] the options to get funnel stats with. @yield [info] passes funnel stats a callback/block. @yieldparam info [Hash] contains funnel stats.

# File lib/sensu/transport/base.rb, line 132
def stats(funnel, options={})
  info = {}
  yield(info) if block_given?
end
subscribe(type, pipe, funnel=nil, options={}) { |info, message| ... } click to toggle source

Subscribe to a transport pipe and/or funnel.

@param type [Symbol] the transport pipe type, possible values

are: :direct and :fanout.

@param pipe [String] the transport pipe name. @param funnel [String] the transport funnel, which may be

connected to multiple pipes.

@param options [Hash] the options to consume messages with. @yield [info, message] passes message info and content to

the consumer callback/block.

@yieldparam info [Hash] contains message information. @yieldparam message [String] message.

# File lib/sensu/transport/base.rb, line 97
def subscribe(type, pipe, funnel=nil, options={})
  info = {}
  message = ''
  yield(info, message)
end
unsubscribe() { |info| ... } click to toggle source

Unsubscribe from all transport pipes and/or funnels.

@yield [info] passes info to an optional callback/block. @yieldparam info [Hash] contains unsubscribe information.

# File lib/sensu/transport/base.rb, line 107
def unsubscribe
  info = {}
  yield(info) if block_given?
end

Private Instance Methods

catch_errors() { || ... } click to toggle source

Catch transport errors and call the #on_error callback, providing it with the error object as an argument. This method is intended to be applied where necessary, not to be confused with a catch-all. Not all transports will need this.

@yield [] callback/block to execute within a rescue block to

catch transport errors.
# File lib/sensu/transport/base.rb, line 153
def catch_errors
  begin
    yield
  rescue => error
    @on_error.call(error)
  end
end