Class: CorosyncCommander::Execution::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/corosync_commander/execution/message.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Message

Returns a new instance of Message.



30
31
32
33
34
35
36
# File 'lib/corosync_commander/execution/message.rb', line 30

def initialize(params = {})
	@sender = params[:sender]
	@recipients = Corosync::CPG::MemberList.new(params[:recipients])
	@execution_id = params[:execution_id]
	@type = params[:type]
	@content = params[:content]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



10
11
12
# File 'lib/corosync_commander/execution/message.rb', line 10

def content
  @content
end

#execution_idObject (readonly)

Returns the value of attribute execution_id.



8
9
10
# File 'lib/corosync_commander/execution/message.rb', line 8

def execution_id
  @execution_id
end

#recipientsObject (readonly)

Returns the value of attribute recipients.



7
8
9
# File 'lib/corosync_commander/execution/message.rb', line 7

def recipients
  @recipients
end

#senderObject (readonly)

Returns the value of attribute sender.



6
7
8
# File 'lib/corosync_commander/execution/message.rb', line 6

def sender
  @sender
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/corosync_commander/execution/message.rb', line 9

def type
  @type
end

Class Method Details

.from_cpg_message(sender, data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/corosync_commander/execution/message.rb', line 12

def self.from_cpg_message(sender, data)
	data = JSON.parse(data)

	recipients = Corosync::CPG::MemberList.new
	data[0].each do |m|
		nodeid,pid = m.split(':').map{|i| i.to_i}
		recipients << Corosync::CPG::Member.new(nodeid,pid)
	end

	execution_id = data[1]

	type = data[2]

	content = data[3]

	self.new(:sender => sender, :recipients => recipients, :execution_id => execution_id, :type => type, :content => content)
end

Instance Method Details

#reply(content) ⇒ Object



38
39
40
# File 'lib/corosync_commander/execution/message.rb', line 38

def reply(content)
	self.class.new(:recipients => [@sender], :execution_id => @execution_id, :type => 'response', :content => content)
end

#to_sObject



42
43
44
# File 'lib/corosync_commander/execution/message.rb', line 42

def to_s
	[@recipients.to_a, @execution_id, @type, @content].to_json
end