Class: Concord::ComputationContext
- Inherits:
-
Object
- Object
- Concord::ComputationContext
- Defined in:
- lib/concord.rb
Overview
Transactional wrapper for proxy <=> client interactions
Instance Attribute Summary collapse
-
#computation ⇒ Object
Returns the value of attribute computation.
-
#transaction ⇒ Object
Returns the value of attribute transaction.
Instance Method Summary collapse
-
#get_state(key) ⇒ String
Retrieve a binary blob stored in the proxy state.
-
#initialize(computation) ⇒ ComputationContext
constructor
Initialize a new ‘ComputationContext`.
-
#produce_record(stream, key, value) ⇒ Object
Produce a record on ‘stream` with `key` and `value`.
-
#set_state(key, value) ⇒ Object
Store a binary blob, identified by a key, in the proxy state.
-
#set_timer(key, time) ⇒ Object
Set a timer to trigger a callback in the future the ‘process_timer` callback to identify the specific callback.
Constructor Details
#initialize(computation) ⇒ ComputationContext
Initialize a new ‘ComputationContext`
35 36 37 38 39 40 |
# 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 |
Instance Attribute Details
#computation ⇒ Object
Returns the value of attribute computation.
31 32 33 |
# File 'lib/concord.rb', line 31 def computation @computation end |
#transaction ⇒ Object
Returns the value of attribute transaction.
31 32 33 |
# File 'lib/concord.rb', line 31 def transaction @transaction end |
Instance Method Details
#get_state(key) ⇒ String
Retrieve a binary blob stored in the proxy state
67 68 69 |
# File 'lib/concord.rb', line 67 def get_state(key) computation.get_state(key) end |
#produce_record(stream, key, value) ⇒ Object
Produce a record on ‘stream` with `key` and `value`
46 47 48 49 50 51 52 53 |
# File 'lib/concord.rb', line 46 def produce_record(stream, key, value) r = ::Concord::Thrift::Record.new r. = ::Concord::Thrift::RecordMetadata.new r.key = key r.data = value r.userStream = stream transaction.records.push(r) end |
#set_state(key, value) ⇒ Object
Store a binary blob, identified by a key, in the proxy state
74 75 76 |
# File 'lib/concord.rb', line 74 def set_state(key, value) computation.set_state(key, value) end |
#set_timer(key, time) ⇒ Object
Set a timer to trigger a callback in the future the ‘process_timer` callback to identify the specific callback.
60 61 62 |
# File 'lib/concord.rb', line 60 def set_timer(key, time) transaction.timers[key] = time end |