class Pione::Command::PioneTupleSpaceViewerContext

Public Instance Methods

get_tuple_space(address) click to toggle source

Get a tuple space from the address.

# 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) click to toggle source

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

# 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