Hi guys, can you help to understand?
I'm sure that i'm making a big mistake but i can't see it.Now i'm trying
to implement the producer/consumer algorithm.I created a server class
that will start a threaded server ring, and a provider class that will
resister
the tuple spaces in the server ring.Also i created Producer class and
the Consumer cLass.Now regardless if the algorithm is a true
Produce/Consumer, i can't read from the tuple spaces with the "take"
method, it seems it cant' indentify the tuple space .
PLEASE any one can help me i'm in this trouble since 2 days!
Below my class's ruby code.


----server

require 'rinda/ring'
require 'rinda/tuplespace'

class Tupleserver
  def initialize
  end
  def start
    DRb.start_service
    ts = Rinda::TupleSpace.new
    Rinda::RingServer.new ts
    DRb.thread.join;
  end
end

----Provider

 require 'rinda/ring'
 require 'rinda/tuplespace'
class Provider
  def initialize
  end
  def start
    DRb.start_service
    ts = Rinda::TupleSpace.new
    prov = Rinda::RingProvider.new :TupleSpace, ts, 'Tuple Space'
    prov.provide;
    DRb.thread.join
  end
end

----Consumer

require 'rinda/ring'
require 'rinda/tuplespace'
class Consumer
  def initialize
    DRb.start_service
    ring_server = Rinda::RingFinger.primary
    ts = ring_server.read([:name, :TupleSpace, nil, nil])[2]
    @ts = Rinda::TupleSpaceProxy.new ts
    @buff=0;
  end
  def execute
    while true
      puts "eccomi sono il consumatore"
      @buff=@ts.take([:ciao,nil,nil])[2]
      if(@buff!=0)
        @buff=@buff.to_i-1;
        @ts.write[:ciao,@buff];
      end
      puts "vuoto";
      @ts.write([:ciao,'empty',nil]);
    end
  end
end

----Producer

require 'rinda/ring'
require 'rinda/tuplespace'
class Producer
  def initialize
    DRb.start_service
    ring_server = Rinda::RingFinger.primary
    ts = ring_server.read([:name,:TupleSpace, nil, nil])[2]
    @ts = Rinda::TupleSpaceProxy.new ts
    @buff=0;
  end
  def execute
    while true
      while @buff!=10
        @buff=@buff.to_i+1;
      end
      puts "avverto che รจ pieno"
      @ts.write([:TupleSpace,@buff,nil]);
      puts"aspetto che sia vuoto"
      @ts.take([:TupleSpace,'empty',nil])[1];
      @buff=0;
    end
  end
end


----Main
require 'rinda/ring'
require 'rinda/tuplespace'
require "Tupleserver";
require "Producer";
require "Consumer";
require "Provider"
require "Searchservice"

server=Tupleserver.new;
Thread.new{server.start()};
provider=Provider.new;
Thread.new{provider.start()}
Searchservice.new;
producer=Producer.new;
consumer1=Consumer.new;
consumer2=Consumer.new;
t1=Thread.new{producer.execute()};
t2=Thread.new{consumer1.execute()};
t3=Thread.new{consumer2.execute()};
t1.join;
t2.join;
t3.join;
-- 
Posted via http://www.ruby-forum.com/.