Class Rinda::NotifyTemplateEntry
In: lib/rinda/tuplespace.rb
Parent: TemplateEntry

A NotifyTemplateEntry is returned by TupleSpace#notify and is notified of TupleSpace changes. You may receive either your subscribed event or the ‘close’ event when iterating over notifications.

See TupleSpace#notify_event for valid notification types.

Example

  ts = Rinda::TupleSpace.new
  observer = ts.notify 'write', [nil]

  Thread.start do
    observer.each { |t| p t }
  end

  3.times { |i| ts.write [i] }

Outputs:

  ['write', [0]]
  ['write', [1]]
  ['write', [2]]

Methods

each   new   notify   pop  

Public Class methods

Creates a new NotifyTemplateEntry that watches place for +event+s that match tuple.

[Source]

     # File lib/rinda/tuplespace.rb, line 246
246:     def initialize(place, event, tuple, expires=nil)
247:       ary = [event, Rinda::Template.new(tuple)]
248:       super(ary, expires)
249:       @queue = Queue.new
250:       @done = false
251:     end

Public Instance methods

Yields event/tuple pairs until this NotifyTemplateEntry expires.

[Source]

     # File lib/rinda/tuplespace.rb, line 274
274:     def each # :yields: event, tuple
275:       while !@done
276:         it = pop
277:         yield(it)
278:       end
279:     rescue 
280:     ensure
281:       cancel
282:     end

Called by TupleSpace to notify this NotifyTemplateEntry of a new event.

[Source]

     # File lib/rinda/tuplespace.rb, line 256
256:     def notify(ev)
257:       @queue.push(ev)
258:     end

Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry expires.

[Source]

     # File lib/rinda/tuplespace.rb, line 264
264:     def pop
265:       raise RequestExpiredError if @done
266:       it = @queue.pop
267:       @done = true if it[0] == 'close'
268:       return it
269:     end

[Validate]