Class: Pione::Command::PioneTupleSpaceViewerContext

Inherits:
Rootage::CommandContext show all
Defined in:
lib/pione/command/pione-tuple-space-viewer.rb

Instance Attribute Summary

Attributes inherited from Rootage::ProcessContext

#model, #scenario

Instance Method Summary collapse

Methods inherited from Rootage::CommandContext

#quit, #stop

Methods inherited from Rootage::ProcessContext

#fail, #initialize, make, #test

Constructor Details

This class inherits a constructor from Rootage::ProcessContext

Instance Method Details

#get_tuple_space(address) ⇒ Object

Get a tuple space from the address.



165
166
167
168
169
170
171
# File 'lib/pione/command/pione-tuple-space-viewer.rb', line 165

def get_tuple_space(address)
  ref = DRbObject.new_with_uri(address)
  ref.ping
  ref.get_tuple_space(nil)
rescue DRb::DRbConnError => e
  abort("cannot connect to %s: %s" % [address, e.message])
end

#show_bag(tuple_space, type) ⇒ Object

Show tuples of the typed bag in the tuple space server.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
# File 'lib/pione/command/pione-tuple-space-viewer.rb', line 174

def show_bag(tuple_space, type)
  tuple_space.all_tuples(type).each do |tuple|
    next if not(option[:identifiers].empty?) and not(option[:identifiers].include?(tuple.first.to_s))
    next if option[:exclusions].include?(tuple.first.to_s)

    t = TupleSpace::Tuple.from_array(tuple)

    # rule_path
    if option[:rule_path]
      if t.respond_to?(:domain)
        next unless /^(#{option[:rule_path]})/.match(t.domain)
      else
        next
      end
    end

    # name
    if option[:data_name]
      if t.kind_of?(TupleSpace::Data) and t.respond_to?(:name)
        next unless Lang::DataExpr.new(@data_name).match(t.name)
      else
        next
      end
    end

    # show
    res = PP.pp(tuple, "")
    res.gsub!(/\:[a-z]\w+/) {|s| s.color(:red) }
    res.gsub!(/\#<(\S+)/) {|s| "#<%s" % $1.color(:green) }
    puts res
  end
end