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 128
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 12
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()

# File lib/sensu/transport/base.rb, line 114
def ack(*args, &callback)
  acknowledge(*args, &callback)
end
acknowledge(info, &callback) 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 109
def acknowledge(info, &callback)
  callback.call(info) if callback
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 41
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 32
def before_reconnect(&callback)
  @before_reconnect = callback
end
close() click to toggle source

Close the transport connection.

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

Transport connection setup.

@param options [Hash, String]

# File lib/sensu/transport/base.rb, line 48
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 56
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 23
def on_error(&callback)
  @on_error = callback
end
publish(type, pipe, message, options={}, &callback) 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.
# File lib/sensu/transport/base.rb, line 73
def publish(type, pipe, message, options={}, &callback)
  info = {:error => nil}
  callback.call(info) if callback
end
reconnect() click to toggle source

Reconnect to the transport.

# File lib/sensu/transport/base.rb, line 51
def reconnect; end
stats(funnel, options={}, &callback) 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.

# File lib/sensu/transport/base.rb, line 122
def stats(funnel, options={}, &callback)
  info = {}
  callback.call(info)
end
subscribe(type, pipe, funnel=nil, options={}, &callback) 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 90
def subscribe(type, pipe, funnel=nil, options={}, &callback)
  info = {}
  message = ''
  callback.call(info, message)
end
unsubscribe(&callback) 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 100
def unsubscribe(&callback)
  info = {}
  callback.call(info) if callback
end