class Concord::ComputationContext

Transactional wrapper for proxy <=> client interactions

Attributes

computation[RW]
transaction[RW]

Public Class Methods

new(computation) click to toggle source

Initialize a new ‘ComputationContext` @param computation [Object] The user-defined computation

# File lib/concord.rb, line 35
def initialize(computation)
  self.computation = computation
  self.transaction = ::Concord::Thrift::ComputationTx.new
  self.transaction.records = []
  self.transaction.timers = {}
end

Public Instance Methods

get_state(key) click to toggle source

Retrieve a binary blob stored in the proxy state @param key [String] Key to fetch from data store @return [String] Binary blob of data

# File lib/concord.rb, line 67
def get_state(key)
  computation.get_state(key)
end
produce_record(stream, key, value) click to toggle source

Produce a record on ‘stream` with `key` and `value` @param stream [String] Globally unique name of string @param key [String] Key to group by on stream (pending grouping) @param value [String] Binary blob to pass downstream with tuple

# File lib/concord.rb, line 46
def produce_record(stream, key, value)
  r = ::Concord::Thrift::Record.new
  r.meta = ::Concord::Thrift::RecordMetadata.new
  r.key = key
  r.data = value
  r.userStream = stream
  transaction.records.push(r)
end
set_state(key, value) click to toggle source

Store a binary blob, identified by a key, in the proxy state @param key [String] Key to set in data store @param value [String] Binary blob

# File lib/concord.rb, line 74
def set_state(key, value)
  computation.set_state(key, value)
end
set_timer(key, time) click to toggle source

Set a timer to trigger a callback in the future @param key [String] Name of the timer. This parameter will be passed to the ‘process_timer` callback to identify the specific callback. @param time [FixNum] Integer representing the time (in milliseconds) at

which the callback should be triggered.
# File lib/concord.rb, line 60
def set_timer(key, time)
  transaction.timers[key] = time
end