RINDA Probem

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”
@[email protected]([:ciao,nil,nil])[2]
if(@buff!=0)
@[email protected]_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
@[email protected]_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;

sorry previously i postetd a wrong Cosumer class here the right ver

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”
@[email protected]([:TupleSpace,nil,nil])[2]
if(@buff!=0)
@[email protected]_i-1;
@ts.write[:TupleSpace,@buff];
end
puts “vuoto”;
@ts.write([:TupleSpace,‘empty’,nil]);
end
end
end

On Fri, Aug 20, 2010 at 5:21 PM, Gino F. [email protected]
wrote:

----Main

require “Searchservice”

missing this code

martin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs