Class: Sensu::Transport::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu/transport/base.rb

Direct Known Subclasses

RabbitMQ

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase



12
13
14
15
16
# File 'lib/sensu/transport/base.rb', line 12

def initialize
  @on_error = Proc.new {}
  @before_reconnect = Proc.new {}
  @after_reconnect = Proc.new {}
end

Instance Attribute Details

#loggerLogger



10
11
12
# File 'lib/sensu/transport/base.rb', line 10

def logger
  @logger
end

Class Method Details

.descendantsObject

Discover available transports (Subclasses)



128
129
130
131
132
# File 'lib/sensu/transport/base.rb', line 128

def self.descendants
  ObjectSpace.each_object(Class).select do |klass|
    klass < self
  end
end

Instance Method Details

#ack(*args, &callback) ⇒ Object

Alias for acknowledge()



114
115
116
# File 'lib/sensu/transport/base.rb', line 114

def ack(*args, &callback)
  acknowledge(*args, &callback)
end

#acknowledge(info) {|info| ... } ⇒ Object

Acknowledge the delivery of a message from the transport.

Yields:

  • (info)

    passes acknowledgment info to an optional callback/block.



109
110
111
# File 'lib/sensu/transport/base.rb', line 109

def acknowledge(info, &callback)
  callback.call(info) if callback
end

#after_reconnect(&callback) ⇒ Proc

Set the after reconnect callback.



41
42
43
# File 'lib/sensu/transport/base.rb', line 41

def after_reconnect(&callback)
  @after_reconnect = callback
end

#before_reconnect(&callback) ⇒ Proc

Set the before reconnect callback.



32
33
34
# File 'lib/sensu/transport/base.rb', line 32

def before_reconnect(&callback)
  @before_reconnect = callback
end

#closeObject

Close the transport connection.



61
# File 'lib/sensu/transport/base.rb', line 61

def close; end

#connect(options = {}) ⇒ Object

Transport connection setup.



48
# File 'lib/sensu/transport/base.rb', line 48

def connect(options={}); end

#connected?TrueClass, FalseClass

Indicates if connected to the transport.



56
57
58
# File 'lib/sensu/transport/base.rb', line 56

def connected?
  false
end

#on_error(&callback) ⇒ Proc

Set the error callback.



23
24
25
# File 'lib/sensu/transport/base.rb', line 23

def on_error(&callback)
  @on_error = callback
end

#publish(type, pipe, message, options = {}) {|info| ... } ⇒ Object

Publish a message to the transport.

Yields:

  • (info)

    passes publish info to an optional callback/block.

Yield Parameters:

  • info (Hash)

    contains publish information, which may contain an error object.



73
74
75
76
# File 'lib/sensu/transport/base.rb', line 73

def publish(type, pipe, message, options={}, &callback)
  info = {:error => nil}
  callback.call(info) if callback
end

#reconnectObject

Reconnect to the transport.



51
# File 'lib/sensu/transport/base.rb', line 51

def reconnect; end

#stats(funnel, options = {}, &callback) ⇒ Object

Transport funnel stats, such as message and consumer counts.



122
123
124
125
# File 'lib/sensu/transport/base.rb', line 122

def stats(funnel, options={}, &callback)
  info = {}
  callback.call(info)
end

#subscribe(type, pipe, funnel = nil, options = {}) {|info, message| ... } ⇒ Object

Subscribe to a transport pipe and/or funnel.

Yields:

  • (info, message)

    passes message info and content to the consumer callback/block.

Yield Parameters:

  • info (Hash)

    contains message information.

  • message (String)

    message.



90
91
92
93
94
# File 'lib/sensu/transport/base.rb', line 90

def subscribe(type, pipe, funnel=nil, options={}, &callback)
  info = {}
  message = ''
  callback.call(info, message)
end

#unsubscribe {|info| ... } ⇒ Object

Unsubscribe from all transport pipes and/or funnels.

Yields:

  • (info)

    passes info to an optional callback/block.

Yield Parameters:

  • info (Hash)

    contains unsubscribe information.



100
101
102
103
# File 'lib/sensu/transport/base.rb', line 100

def unsubscribe(&callback)
  info = {}
  callback.call(info) if callback
end