Pattern: Shutdown Flag
Problem: An agent should consider a shutdown flag presence.
Solution: The solution is to use a modified Boolean Flag Pattern, where the flag specific operation is to break the loop for reading an n-tuple, i.e. the Agent Life Cycle pattern.
(life cycle, boolean flag and shutdown flag patterns)
loop do
begin
read or take n-tuple with timeout t1
rescue Rinda::RequestExpiredError
begin
read the shutdown flag with timeout t2
break # stop listening for the n-tuple
rescue Rinda::RequestExpiredError
# ignore a situation when there is no shutdown flag
end
next # repeat the loop
end
process n-tuple end
Example:
(life cycle, boolean flag and shutdown flag patterns)
loop do
begin
t = ts.take [:plus, nil, nil], 10
rescue Rinda::RequestExpiredError
begin
ts.read [:end], 1
break # stop listening for the n-tuple
rescue Rinda::RequestExpiredError
# ignore a situation when there is no shutdown flag
end
next # repeat the loop
end
res = t[1] + t[2] ts.write [:result, res] end
Comments(0)