2004-02-17 17:29:07 -05:00
|
|
|
#
|
|
|
|
# = tuplespace: <i>???</i>
|
|
|
|
#
|
|
|
|
# <i>Overview of rinda/tuplespace.rb</i>
|
|
|
|
#
|
|
|
|
# <i>Example(s)</i>
|
|
|
|
#
|
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
require 'monitor'
|
|
|
|
require 'thread'
|
|
|
|
require 'drb/drb'
|
|
|
|
require 'rinda/rinda'
|
|
|
|
|
|
|
|
module Rinda
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
|
|
|
# A TupleEntry is a Tuple (i.e. a possible entry in some Tuplespace)
|
|
|
|
# together with expiry and cancellation data.
|
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class TupleEntry
|
|
|
|
include DRbUndumped
|
|
|
|
|
|
|
|
def initialize(ary, sec=nil)
|
|
|
|
@cancel = false
|
|
|
|
@ary = make_tuple(ary)
|
|
|
|
@renewer = nil
|
|
|
|
renew(sec)
|
|
|
|
end
|
|
|
|
attr_accessor :expires
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
@cancel = true
|
|
|
|
end
|
|
|
|
|
|
|
|
def alive?
|
|
|
|
!canceled? && !expired?
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Return the object which makes up the tuple itself: the Array
|
|
|
|
# or Hash.
|
2003-10-05 08:23:33 -04:00
|
|
|
def value; @ary.value; end
|
2004-02-17 17:29:07 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def canceled?; @cancel; end
|
2004-02-17 17:29:07 -05:00
|
|
|
|
|
|
|
# Has this tuple expired? (true/false).
|
2003-10-05 08:23:33 -04:00
|
|
|
def expired?
|
|
|
|
return true unless @expires
|
|
|
|
return false if @expires > Time.now
|
|
|
|
return true if @renewer.nil?
|
|
|
|
renew(@renewer)
|
|
|
|
return true unless @expires
|
|
|
|
return @expires < Time.now
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Reset the expiry data according to the supplied argument. If
|
|
|
|
# the argument is:
|
|
|
|
#
|
|
|
|
# +nil+:: it is set to expire in the far future.
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 19:19:47 -04:00
|
|
|
# +false+:: it has expired.
|
2004-02-17 17:29:07 -05:00
|
|
|
# Numeric:: it will expire in that many seconds.
|
|
|
|
#
|
|
|
|
# Otherwise the argument refers to some kind of renewer object
|
|
|
|
# which will reset its expiry time.
|
2003-10-05 08:23:33 -04:00
|
|
|
def renew(sec_or_renewer)
|
|
|
|
sec, @renewer = get_renewer(sec_or_renewer)
|
|
|
|
@expires = make_expires(sec)
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Create an expiry time. Called with:
|
|
|
|
#
|
|
|
|
# +true+:: the expiry time is the start of 1970 (i.e. expired).
|
|
|
|
# +nil+:: it is Tue Jan 19 03:14:07 GMT Standard Time 2038 (i.e. when
|
|
|
|
# UNIX clocks will die)
|
|
|
|
#
|
|
|
|
# otherwise it is +sec+ seconds into the
|
|
|
|
# future.
|
2003-10-05 08:23:33 -04:00
|
|
|
def make_expires(sec=nil)
|
|
|
|
case sec
|
|
|
|
when Numeric
|
|
|
|
Time.now + sec
|
|
|
|
when true
|
|
|
|
Time.at(1)
|
|
|
|
when nil
|
|
|
|
Time.at(2**31-1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Accessor method for the tuple.
|
2003-10-05 08:23:33 -04:00
|
|
|
def [](key)
|
|
|
|
@ary[key]
|
|
|
|
end
|
|
|
|
|
2004-04-06 11:26:25 -04:00
|
|
|
def fetch(key)
|
|
|
|
@ary.fetch(key)
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# The size of the tuple.
|
2003-10-05 08:23:33 -04:00
|
|
|
def size
|
|
|
|
@ary.size
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Create a new tuple from the supplied object (array-like).
|
2003-10-05 08:23:33 -04:00
|
|
|
def make_tuple(ary)
|
|
|
|
Rinda::Tuple.new(ary)
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
private
|
2004-02-17 17:29:07 -05:00
|
|
|
# Given +true+, +nil+, or +Numeric+, returns that (suitable input to
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 19:19:47 -04:00
|
|
|
# make_expires) and +nil+ (no actual +renewer+), else it return the
|
2004-02-17 17:29:07 -05:00
|
|
|
# time data from the supplied +renewer+.
|
2003-10-05 08:23:33 -04:00
|
|
|
def get_renewer(it)
|
|
|
|
case it
|
|
|
|
when Numeric, true, nil
|
|
|
|
return it, nil
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
return it.renew, it
|
|
|
|
rescue Exception
|
|
|
|
return it, nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
|
|
|
# The same as a TupleEntry but with methods to do matching.
|
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class TemplateEntry < TupleEntry
|
|
|
|
def initialize(ary, expires=nil)
|
|
|
|
super(ary, expires)
|
|
|
|
@template = Rinda::Template.new(ary)
|
|
|
|
end
|
|
|
|
|
|
|
|
def match(tuple)
|
|
|
|
@template.match(tuple)
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# An alias for #match.
|
2003-10-05 08:23:33 -04:00
|
|
|
def ===(tuple)
|
|
|
|
match(tuple)
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Create a new Template from the supplied object.
|
2003-10-05 08:23:33 -04:00
|
|
|
def make_tuple(ary)
|
|
|
|
Rinda::Template.new(ary)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 19:19:47 -04:00
|
|
|
# <i>Documentation?</i>
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class WaitTemplateEntry < TemplateEntry
|
|
|
|
def initialize(place, ary, expires=nil)
|
|
|
|
super(ary, expires)
|
|
|
|
@place = place
|
|
|
|
@cond = place.new_cond
|
|
|
|
@found = nil
|
|
|
|
end
|
|
|
|
attr_reader :found
|
|
|
|
|
|
|
|
def cancel
|
|
|
|
super
|
|
|
|
signal
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait
|
|
|
|
@cond.wait
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def read(tuple)
|
|
|
|
@found = tuple
|
|
|
|
signal
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def signal
|
|
|
|
@place.synchronize do
|
|
|
|
@cond.signal
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 19:19:47 -04:00
|
|
|
# <i>Documentation?</i>
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class NotifyTemplateEntry < TemplateEntry
|
|
|
|
def initialize(place, event, tuple, expires=nil)
|
|
|
|
ary = [event, Rinda::Template.new(tuple)]
|
|
|
|
super(ary, expires)
|
|
|
|
@queue = Queue.new
|
|
|
|
@done = false
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def notify(ev)
|
|
|
|
@queue.push(ev)
|
|
|
|
end
|
|
|
|
|
|
|
|
def pop
|
|
|
|
raise RequestExpiredError if @done
|
|
|
|
it = @queue.pop
|
|
|
|
@done = true if it[0] == 'close'
|
|
|
|
return it
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def each
|
|
|
|
while !@done
|
|
|
|
it = pop
|
|
|
|
yield(it)
|
|
|
|
end
|
|
|
|
rescue
|
|
|
|
ensure
|
|
|
|
cancel
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
|
|
|
# TupleBag is an unordered collection of tuples. It is the basis
|
|
|
|
# of Tuplespace.
|
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class TupleBag
|
|
|
|
def initialize
|
|
|
|
@hash = {}
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
|
|
|
def has_expires?
|
|
|
|
@hash.each do |k, v|
|
|
|
|
v.each do |tuple|
|
|
|
|
return true if tuple.expires
|
|
|
|
end
|
|
|
|
end
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Add the object to the TupleBag.
|
2003-10-05 08:23:33 -04:00
|
|
|
def push(ary)
|
|
|
|
size = ary.size
|
|
|
|
@hash[size] ||= []
|
|
|
|
@hash[size].push(ary)
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Remove the object from the TupleBag.
|
2003-10-05 08:23:33 -04:00
|
|
|
def delete(ary)
|
|
|
|
size = ary.size
|
|
|
|
@hash.fetch(size, []).delete(ary)
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Finds all tuples that match the template and are alive.
|
2003-10-05 08:23:33 -04:00
|
|
|
def find_all(template)
|
|
|
|
@hash.fetch(template.size, []).find_all do |tuple|
|
|
|
|
tuple.alive? && template.match(tuple)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Finds a template that matches and is alive.
|
2003-10-05 08:23:33 -04:00
|
|
|
def find(template)
|
|
|
|
@hash.fetch(template.size, []).find do |tuple|
|
|
|
|
tuple.alive? && template.match(tuple)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Finds all tuples in the TupleBag which when treated as
|
|
|
|
# templates, match the supplied tuple and are alive.
|
2003-10-05 08:23:33 -04:00
|
|
|
def find_all_template(tuple)
|
|
|
|
@hash.fetch(tuple.size, []).find_all do |template|
|
|
|
|
template.alive? && template.match(tuple)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Delete tuples which are not alive from the TupleBag. Returns
|
|
|
|
# the list of tuples so deleted.
|
2003-10-05 08:23:33 -04:00
|
|
|
def delete_unless_alive
|
|
|
|
deleted = []
|
|
|
|
@hash.keys.each do |size|
|
|
|
|
ary = []
|
|
|
|
@hash[size].each do |tuple|
|
|
|
|
if tuple.alive?
|
|
|
|
ary.push(tuple)
|
|
|
|
else
|
|
|
|
deleted.push(tuple)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
@hash[size] = ary
|
|
|
|
end
|
|
|
|
deleted
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
|
|
|
# The Tuplespace manages access to the tuples it contains,
|
* dln.c, io.c, pack.c, lib/benchmark.rb, lib/cgi.rb, lib/csv.rb,
lib/date.rb, lib/ftools.rb, lib/getoptlong.rb, lib/logger.rb,
lib/matrix.rb, lib/monitor.rb, lib/set.rb, lib/thwait.rb,
lib/timeout.rb, lib/yaml.rb, lib/drb/drb.rb, lib/irb/workspace.rb,
lib/net/ftp.rb, lib/net/http.rb, lib/net/imap.rb, lib/net/pop.rb,
lib/net/telnet.rb, lib/racc/parser.rb, lib/rinda/rinda.rb,
lib/rinda/tuplespace.rb, lib/shell/command-processor.rb,
lib/soap/rpc/soaplet.rb, lib/test/unit/testcase.rb,
lib/test/unit/testsuite.rb: typo fix.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6178 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2004-04-18 19:19:47 -04:00
|
|
|
# ensuring mutual exclusion requirements are met.
|
2004-02-17 17:29:07 -05:00
|
|
|
#
|
2003-10-05 08:23:33 -04:00
|
|
|
class TupleSpace
|
|
|
|
include DRbUndumped
|
|
|
|
include MonitorMixin
|
2004-02-17 17:29:07 -05:00
|
|
|
def initialize(period=60)
|
2003-10-05 08:23:33 -04:00
|
|
|
super()
|
|
|
|
@bag = TupleBag.new
|
|
|
|
@read_waiter = TupleBag.new
|
|
|
|
@take_waiter = TupleBag.new
|
|
|
|
@notify_waiter = TupleBag.new
|
2004-02-17 17:29:07 -05:00
|
|
|
@period = period
|
2005-02-28 10:41:14 -05:00
|
|
|
@keeper = nil
|
2003-10-05 08:23:33 -04:00
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Put a tuple into the tuplespace.
|
2003-10-05 08:23:33 -04:00
|
|
|
def write(tuple, sec=nil)
|
|
|
|
entry = TupleEntry.new(tuple, sec)
|
2005-02-28 10:41:14 -05:00
|
|
|
start_keeper
|
2003-10-05 08:23:33 -04:00
|
|
|
synchronize do
|
|
|
|
if entry.expired?
|
|
|
|
@read_waiter.find_all_template(entry).each do |template|
|
|
|
|
template.read(tuple)
|
|
|
|
end
|
|
|
|
notify_event('write', entry.value)
|
|
|
|
notify_event('delete', entry.value)
|
|
|
|
else
|
|
|
|
@bag.push(entry)
|
|
|
|
@read_waiter.find_all_template(entry).each do |template|
|
|
|
|
template.read(tuple)
|
|
|
|
end
|
|
|
|
@take_waiter.find_all_template(entry).each do |template|
|
|
|
|
template.signal
|
|
|
|
end
|
|
|
|
notify_event('write', entry.value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
entry
|
|
|
|
end
|
|
|
|
|
2004-02-17 17:29:07 -05:00
|
|
|
# Remove an entry from the Tuplespace.
|
2003-10-05 08:23:33 -04:00
|
|
|
def take(tuple, sec=nil, &block)
|
|
|
|
move(nil, tuple, sec, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def move(port, tuple, sec=nil)
|
|
|
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
|
|
|
yield(template) if block_given?
|
2005-02-28 10:41:14 -05:00
|
|
|
start_keeper
|
2003-10-05 08:23:33 -04:00
|
|
|
synchronize do
|
|
|
|
entry = @bag.find(template)
|
|
|
|
if entry
|
|
|
|
port.push(entry.value) if port
|
|
|
|
@bag.delete(entry)
|
|
|
|
notify_event('take', entry.value)
|
|
|
|
return entry.value
|
|
|
|
end
|
2004-02-15 05:07:18 -05:00
|
|
|
raise RequestExpiredError if template.expired?
|
2003-10-05 08:23:33 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
@take_waiter.push(template)
|
|
|
|
while true
|
|
|
|
raise RequestCanceledError if template.canceled?
|
|
|
|
raise RequestExpiredError if template.expired?
|
|
|
|
entry = @bag.find(template)
|
|
|
|
if entry
|
|
|
|
port.push(entry.value) if port
|
|
|
|
@bag.delete(entry)
|
|
|
|
notify_event('take', entry.value)
|
|
|
|
return entry.value
|
|
|
|
end
|
|
|
|
template.wait
|
|
|
|
end
|
|
|
|
ensure
|
|
|
|
@take_waiter.delete(template)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read(tuple, sec=nil)
|
|
|
|
template = WaitTemplateEntry.new(self, tuple, sec)
|
|
|
|
yield(template) if block_given?
|
2005-02-28 10:41:14 -05:00
|
|
|
start_keeper
|
2003-10-05 08:23:33 -04:00
|
|
|
synchronize do
|
|
|
|
entry = @bag.find(template)
|
|
|
|
return entry.value if entry
|
2004-02-15 05:07:18 -05:00
|
|
|
raise RequestExpiredError if template.expired?
|
2003-10-05 08:23:33 -04:00
|
|
|
|
|
|
|
begin
|
|
|
|
@read_waiter.push(template)
|
|
|
|
template.wait
|
|
|
|
raise RequestCanceledError if template.canceled?
|
|
|
|
raise RequestExpiredError if template.expired?
|
|
|
|
return template.found
|
|
|
|
ensure
|
|
|
|
@read_waiter.delete(template)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_all(tuple)
|
|
|
|
template = WaitTemplateEntry.new(self, tuple, nil)
|
|
|
|
synchronize do
|
|
|
|
entry = @bag.find_all(template)
|
|
|
|
entry.collect do |e|
|
|
|
|
e.value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def notify(event, tuple, sec=nil)
|
|
|
|
template = NotifyTemplateEntry.new(self, event, tuple, sec)
|
|
|
|
synchronize do
|
|
|
|
@notify_waiter.push(template)
|
|
|
|
end
|
|
|
|
template
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
private
|
|
|
|
def keep_clean
|
|
|
|
synchronize do
|
|
|
|
@read_waiter.delete_unless_alive.each do |e|
|
|
|
|
e.signal
|
|
|
|
end
|
|
|
|
@take_waiter.delete_unless_alive.each do |e|
|
|
|
|
e.signal
|
|
|
|
end
|
|
|
|
@notify_waiter.delete_unless_alive.each do |e|
|
|
|
|
e.notify(['close'])
|
|
|
|
end
|
|
|
|
@bag.delete_unless_alive.each do |e|
|
|
|
|
notify_event('delete', e.value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
2003-10-05 08:23:33 -04:00
|
|
|
def notify_event(event, tuple)
|
|
|
|
ev = [event, tuple]
|
|
|
|
@notify_waiter.find_all_template(ev).each do |template|
|
|
|
|
template.notify(ev)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-02-28 10:41:14 -05:00
|
|
|
def start_keeper
|
|
|
|
return if @keeper && @keeper.alive?
|
|
|
|
@keeper = Thread.new do
|
|
|
|
while need_keeper?
|
|
|
|
keep_clean
|
|
|
|
sleep(@period)
|
2003-10-05 08:23:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2005-02-28 10:41:14 -05:00
|
|
|
|
|
|
|
def need_keeper?
|
|
|
|
return true if @bag.has_expires?
|
|
|
|
return true if @read_waiter.has_expires?
|
|
|
|
return true if @take_waiter.has_expires?
|
|
|
|
return true if @notify_waiter.has_expires?
|
|
|
|
end
|
2003-10-05 08:23:33 -04:00
|
|
|
end
|
|
|
|
end
|