Module: Ganymed::Client::Processor
- Includes:
- EM::Deferrable
- Defined in:
- lib/ganymed/client/processor.rb
Overview
An EventMachine Protocol that can send events to a Ganymed processor.
Class Method Summary collapse
-
.connect(host, port, origin = nil) ⇒ Object
Connect to a Ganymed processor.
Instance Method Summary collapse
-
#event(ns, value, opts = {}) ⇒ Object
Emit a new Event.
-
#metadata(data, opts = {}) ⇒ Object
Emit a metadata object to the Processor.
Class Method Details
.connect(host, port, origin = nil) ⇒ Object
Connect to a Ganymed processor.
72 73 74 |
# File 'lib/ganymed/client/processor.rb', line 72 def self.connect(host, port, origin=nil) EM.connect(host, port, self, host, port, origin) end |
Instance Method Details
#event(ns, value, opts = {}) ⇒ Object
Emit a new Event.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/ganymed/client/processor.rb', line 22 def event(ns, value, opts={}) opts = { :cf => nil, :now => Time.now.utc, :resolution => 0, :origin => @origin, }.merge(opts) data = { :_type => :event, :n => ns, :c => opts[:cf], :o => opts[:origin], :t => opts[:now].to_i, :r => opts[:resolution].to_i, :v => value } send_data(data.to_msgpack) end |
#metadata(data, opts = {}) ⇒ Object
Emit a metadata object to the Processor.
A metadata object contains arbitrary data related to the origin. This can be queried by Websocket clients for displaying information about origins.
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ganymed/client/processor.rb', line 52 def (data, opts={}) opts = { :origin => @origin, }.merge(opts) data = { :_type => :metadata, :origin => opts[:origin], :data => data, } send_data(data.to_msgpack) end |