Module: CPEE::Message

Defined in:
lib/cpee/message.rb

Constant Summary collapse

@@who =
'cpee'
@@type =
'instance'

Class Method Summary collapse

Class Method Details

.send(type, event, cpee, instance, instance_uuid, instance_name, content = {}, backend = nil) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/cpee/message.rb', line 42

def self::send(type, event, cpee, instance, instance_uuid, instance_name, content={}, backend=nil)
  target = '%02i' % CPEE::Message::target
  topic = ::File::dirname(event)
  name = ::File::basename(event)
  payload = {
    @@who => cpee,
    @@type + '-url' => File.join(cpee,instance.to_s),
    @@type => instance,
    'topic' => topic,
    'type' => type,
    'name' => name,
    'timestamp' =>  Time.now.xmlschema(3),
    'content' => content
  }
  payload[@@type + '-uuid'] = instance_uuid if instance_uuid
  payload[@@type + '-name'] = instance_name if instance_name

  backend.publish(type.to_s + ':' + target + ':' + event.to_s,
    instance.to_s + ' ' +
    JSON::generate(payload)
  )
end

.send_url(type, event, cpee, content = {}, backend) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/cpee/message.rb', line 65

def self::send_url(type, event, cpee, content={}, backend)
  EM.defer do
    topic = ::File::dirname(event)
    name = ::File::basename(event)
    payload = {
      @@who => cpee,
      'topic' => topic,
      'type' => type,
      'name' => name,
      'timestamp' =>  Time.now.xmlschema(3),
      'content' => content
    }
    client = Riddl::Client.new(backend)
    client.post [
      Riddl::Parameter::Simple::new('type',type),
      Riddl::Parameter::Simple::new('topic',topic),
      Riddl::Parameter::Simple::new('event',name),
      Riddl::Parameter::Complex::new('notification','application/json',JSON::generate(payload))
    ]
  end
end

.set_workers(workers) ⇒ Object

}}}



33
34
35
36
# File 'lib/cpee/message.rb', line 33

def self::set_workers(workers)
  @@tworkers = (workers < 1 && workers > 99 ? 1 : workers).freeze
  @@last = -1
end

.targetObject



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

def self::target
  @@last < @@tworkers-1 ? @@last += 1 : @@last = 0
end

.typeObject

}}}



26
27
28
# File 'lib/cpee/message.rb', line 26

def self::type #{{{
  @@type
end

.type=(it) ⇒ Object

}}}



29
30
31
# File 'lib/cpee/message.rb', line 29

def self::type=(it) #{{{
  @@type = it
end

.whoObject

{{{



20
21
22
# File 'lib/cpee/message.rb', line 20

def self::who #{{{
  @@who
end

.who=(it) ⇒ Object

}}}



23
24
25
# File 'lib/cpee/message.rb', line 23

def self::who=(it) #{{{
  @@who = it
end