Class: Pione::TupleSpace::TupleSpaceServer

Inherits:
PioneObject
  • Object
show all
Includes:
DRbUndumped, TupleSpaceServerMethod
Defined in:
lib/pione/tuple-space/tuple-space-server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from TupleSpaceServerMethod

tuple_space_interface

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_spaceObject (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_sObject



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

Returns:

  • (Boolean)


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_locationBasicLocation

Return common base location of the space.

Returns:

  • (BasicLocation)

    base location



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_sizeObject

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_sizeObject



140
141
142
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 140

def data_size
  @__ts__.data_size
end

#finished_sizeObject



136
137
138
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 136

def finished_size
  @__ts__.finished_size
end

#inspectObject



202
203
204
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 202

def inspect
  "#<Pione::TupleSpace::TupleSpaceServer:%s>" % object_id
end

#nowObject



96
97
98
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 96

def now
  Time.now
end

#pidObject

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.

Parameters:

Returns:



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.

Parameters:

  • location (BasicLocation)

    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.

Parameters:

Returns:



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.

Parameters:

Returns:



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_sizeObject



128
129
130
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 128

def task_size
  @__ts__.task_size
end

#task_worker_resourceObject

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

#terminateObject

Shutdown the server.



145
146
147
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 145

def terminate
  @terminated = true
end

#working_sizeObject



132
133
134
# File 'lib/pione/tuple-space/tuple-space-server.rb', line 132

def working_size
  @__ts__.working_size
end