Class: Pione::TupleSpace::TupleSpaceServer
- Inherits:
-
PioneObject
- Object
- PioneObject
- Pione::TupleSpace::TupleSpaceServer
- Includes:
- DRbUndumped, TupleSpaceServerMethod
- Defined in:
- lib/pione/tuple-space/tuple-space-server.rb
Instance Attribute Summary collapse
-
#tuple_space ⇒ Object
readonly
Returns the value of attribute tuple_space.
Class Method Summary collapse
Instance Method Summary collapse
-
#alive? ⇒ Boolean
def drburi @remote_object ||= DRb.start_service(nil, self) @remote_object.__drburi end.
-
#all_tuples(*args) ⇒ Object
Return all tuples of the tuple space.
- #attribute(name) ⇒ Object
-
#base_location ⇒ BasicLocation
Return common base location of the space.
-
#count_tuple(tuple) ⇒ Object
Return the number of tuples matched with specified tuple.
-
#current_task_worker_size ⇒ Object
Return the current worker size of the server.
- #data_size ⇒ Object
- #finished_size ⇒ Object
-
#initialize(data = {}, use_proxy = true) ⇒ TupleSpaceServer
constructor
A new instance of TupleSpaceServer.
- #inspect ⇒ Object
- #now ⇒ Object
-
#pid ⇒ Object
Return pid.
-
#read!(tuple) ⇒ BasicTuple?
Read a tuple with no waiting time.
-
#set_base_location(location) ⇒ void
Set base location.
-
#take!(tuple) ⇒ BasicTuple?
Take a tuple with no waiting time.
-
#take_all!(tuple) ⇒ Array<BasicTuple>
Take all tuples with no waiting time.
- #task_size ⇒ Object
-
#task_worker_resource ⇒ Object
Return the worker resource size of the server.
-
#terminate ⇒ Object
Shutdown the server.
- #working_size ⇒ Object
Methods included from TupleSpaceServerMethod
Constructor Details
#initialize(data = {}, use_proxy = true) ⇒ TupleSpaceServer
Returns a new instance of TupleSpaceServer.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 56 def initialize(data={}, use_proxy=true) @__ts__ = Rinda::TupleSpace.new @tuple_space = @__ts__ if use_proxy @ts = Rinda::TupleSpaceProxy.new(@__ts__) else @ts = @__ts__ end def @ts.to_s;"#<Rinda::TupleSpace>" end # check task worker resource resource = data[:task_worker_resource] || 1 write(TupleSpace::TaskWorkerResourceTuple.new(number: resource)) @terminated = false end |
Instance Attribute Details
#tuple_space ⇒ Object (readonly)
Returns the value of attribute tuple_space.
54 55 56 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 54 def tuple_space @tuple_space end |
Class Method Details
.to_s ⇒ Object
64 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 64 def @ts.to_s;"#<Rinda::TupleSpace>" end |
Instance Method Details
#alive? ⇒ Boolean
def drburi @remote_object ||= DRb.start_service(nil, self) @remote_object.__drburi end
87 88 89 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 87 def alive? not(@terminated) end |
#all_tuples(*args) ⇒ Object
Return all tuples of the tuple space.
124 125 126 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 124 def all_tuples(*args) @__ts__.all_tuples(*args).compact end |
#attribute(name) ⇒ Object
194 195 196 197 198 199 200 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 194 def attribute(name) if tuple = read!(TupleSpace::AttributeTuple.new(key: name)) return tuple.value else return nil end end |
#base_location ⇒ BasicLocation
Return common base location of the space.
104 105 106 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 104 def base_location read(TupleSpace::BaseLocationTuple.any).location end |
#count_tuple(tuple) ⇒ Object
Return the number of tuples matched with specified tuple.
114 115 116 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 114 def count_tuple(tuple) read_all(tuple).size end |
#current_task_worker_size ⇒ Object
Return the current worker size of the server.
119 120 121 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 119 def current_task_worker_size read_all(TupleSpace::AgentTuple.new(agent_type: :task_worker)).size end |
#data_size ⇒ Object
140 141 142 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 140 def data_size @__ts__.data_size end |
#finished_size ⇒ Object
136 137 138 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 136 def finished_size @__ts__.finished_size end |
#inspect ⇒ Object
202 203 204 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 202 def inspect "#<Pione::TupleSpace::TupleSpaceServer:%s>" % object_id end |
#now ⇒ Object
96 97 98 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 96 def now Time.now end |
#pid ⇒ Object
Return pid
92 93 94 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 92 def pid Process.pid end |
#read!(tuple) ⇒ BasicTuple?
Read a tuple with no waiting time. If there are no matched tuples, return
nil
.
156 157 158 159 160 161 162 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 156 def read!(tuple) begin read(tuple, 0) rescue Rinda::RequestExpiredError nil end end |
#set_base_location(location) ⇒ void
This method returns an undefined value.
Set base location.
78 79 80 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 78 def set_base_location(location) write(TupleSpace::BaseLocationTuple.new(location.as_directory)) end |
#take!(tuple) ⇒ BasicTuple?
Take a tuple with no waiting time. If there are no matched tuples, return
nil
.
171 172 173 174 175 176 177 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 171 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.
186 187 188 189 190 191 192 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 186 def take_all!(tuple) begin take_all(tuple, 0) rescue Rinda::RequestExpiredError [] end end |
#task_size ⇒ Object
128 129 130 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 128 def task_size @__ts__.task_size end |
#task_worker_resource ⇒ Object
Return the worker resource size of the server.
109 110 111 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 109 def task_worker_resource read(TupleSpace::TaskWorkerResourceTuple.any).number end |
#terminate ⇒ Object
Shutdown the server.
145 146 147 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 145 def terminate @terminated = true end |
#working_size ⇒ Object
132 133 134 |
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 132 def working_size @__ts__.working_size end |