Module: Pione::TupleSpace::TupleSpaceInterface
- Included in:
- Bacon::Context, Agent::TupleSpaceClient, Command::PioneClient, RuleEngine::BasicHandler, RuleEngine::DataFinder
- Defined in:
- lib/pione/tuple-space/tuple-space-interface.rb
Class Method Summary collapse
-
.tuple_space_operation(name) ⇒ Object
Define tuple space operation.
Instance Method Summary collapse
-
#process_log(record) ⇒ void
Put a log tuple with the data as a process record into tuple space.
-
#processing_error(msg) ⇒ void
Send a processing error.
-
#read!(tuple) ⇒ BasicTuple?
Read a tuple with no waiting time.
-
#set_tuple_space(server) ⇒ void
Set tuple space server which provides operations.
-
#take!(tuple) ⇒ BasicTuple?
Take a tuple with no waiting time.
-
#take_all!(tuple) ⇒ Array<BasicTuple>
Take all tuples with no waiting time.
-
#tuple_space_server ⇒ Object
Return the tuple space server.
-
#with_process_log(record) { ... } ⇒ void
Do the action with loggging.
Class Method Details
.tuple_space_operation(name) ⇒ Object
Define tuple space operation.
6 7 8 9 10 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 6 def self.tuple_space_operation(name) define_method(name) do |*args, &b| @__tuple_space__.__send__(name, *args, &b) end end |
Instance Method Details
#process_log(record) ⇒ void
This method returns an undefined value.
Put a log tuple with the data as a process record into tuple space. The record’s value of transition is “complete” by default and the timestamp set automatically.
78 79 80 81 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 78 def process_log(record) record = record.merge(transition: "complete") unless record.transition write(TupleSpace::ProcessLogTuple.new(record)) end |
#processing_error(msg) ⇒ void
This method returns an undefined value.
Send a processing error.
104 105 106 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 104 def processing_error(msg) write(TupleSpace::CommandTuple.new(name: "terminate", args: {message: msg})) end |
#read!(tuple) ⇒ BasicTuple?
Read a tuple with no waiting time. If there are no matched tuples, return nil.
33 34 35 36 37 38 39 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 33 def read!(tuple) begin read(tuple, 0) rescue Rinda::RequestExpiredError nil end end |
#set_tuple_space(server) ⇒ void
This method returns an undefined value.
Set tuple space server which provides operations.
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 110 def set_tuple_space(server) @__tuple_space__ = server # override #to_s as it's uri because dead remote objects cause exceptions # when you try to watch the object if server.methods.include?(:__drburi) def @__tuple_space__.to_s __drburi end end end |
#take!(tuple) ⇒ BasicTuple?
Take a tuple with no waiting time. If there are no matched tuples, return nil.
48 49 50 51 52 53 54 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 48 def take!(tuple) begin take(tuple, 0) rescue Rinda::RequestExpiredError nil end end |
#take_all!(tuple) ⇒ Array<BasicTuple>
Take all tuples with no waiting time. If there are no matched tuples, return empty array.
63 64 65 66 67 68 69 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 63 def take_all!(tuple) begin take_all(tuple, 0) rescue Rinda::RequestExpiredError [] end end |
#tuple_space_server ⇒ Object
Return the tuple space server.
22 23 24 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 22 def tuple_space_server @__tuple_space__ end |
#with_process_log(record) { ... } ⇒ void
This method returns an undefined value.
Do the action with loggging.
90 91 92 93 94 95 96 97 |
# File 'lib/pione/tuple-space/tuple-space-interface.rb', line 90 def with_process_log(record) process_log(record.merge(transition: "start")) result = yield process_log(record.merge(transition: "complete")) return result rescue DRb::DRbConnError yield end |