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

Instance Method Summary collapse

Class Method Details

.connect(host, port, origin = nil) ⇒ Object

Connect to a Ganymed processor.

Parameters:

  • host (String)

    Host to connect to.

  • port (Fixnum)

    Port to connect to.

  • origin (String) (defaults to: nil)

    Origin of events. Defaults to the fully-qualified hostname.



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.

Parameters:

  • ns (String)

    Event namespace.

  • value (Object)

    Event value.

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • cf (String)

    Consolidation function used in this event.

  • now (Time)

    Event timestamp.

  • resolution (Fixnum)

    Event resolution.

  • origin (String)

    Event origin.



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.

Parameters:

  • data (Hash)

    Metadata object.

  • opts (Hash) (defaults to: {})

    Options

Options Hash (opts):

  • origin (String)

    Metadata origin.



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