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

Instance Method Summary collapse

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.

Parameters:



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.

Parameters:

  • msg (String)

    error message



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.

Parameters:

Returns:



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.

Parameters:

Returns:



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.

Parameters:

Returns:



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_serverObject

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.

Parameters:

Yields:

  • the action



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