Class: Rinda::NotifyTemplateEntry
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
TemplateEntry ,
TupleEntry
|
|
Instance Chain:
self,
TemplateEntry ,
TupleEntry ,
DRbUndumped
|
|
Inherits: |
Rinda::TemplateEntry
|
Defined in: | lib/rinda/tuplespace.rb |
Overview
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]]
Class Method Summary
-
.new(place, event, tuple, expires = nil) ⇒ NotifyTemplateEntry
constructor
Creates a new
NotifyTemplateEntry
that watchesplace
forevent
s that matchtuple
.
TupleEntry
- Inherited
.new | Creates a |
Instance Attribute Summary
TupleEntry
- Inherited
#alive? | A TupleEntry is dead when it is canceled or expired. |
#canceled? | Returns the canceled status. |
#expired? | Has this tuple expired? (true/false). |
#expires |
Instance Method Summary
-
#each
Yields event/tuple pairs until this
NotifyTemplateEntry
expires. -
#notify(ev)
Called by
TupleSpace
to notify thisNotifyTemplateEntry
of a new event. -
#pop
Retrieves a notification.
TemplateEntry
- Inherited
#=== | Alias for TemplateEntry#match. |
#match | Matches this |
#make_tuple |
TupleEntry
- Inherited
#[] | Retrieves |
#cancel | Marks this |
#fetch | Fetches |
#make_expires |
|
#make_tuple | Creates a |
#renew | Reset the expiry time according to |
#size | The size of the tuple. |
#value | Return the object which makes up the tuple itself: the Array or Hash. |
#get_renewer | Returns a valid argument to make_expires and the renewer or nil. |
Constructor Details
.new(place, event, tuple, expires = nil) ⇒ NotifyTemplateEntry
Creates a new NotifyTemplateEntry
that watches place
for event
s that match tuple
.
Instance Method Details
#each
Yields event/tuple pairs until this NotifyTemplateEntry
expires.
# File 'lib/rinda/tuplespace.rb', line 273
def each # :yields: event, tuple while !@done it = pop yield(it) end rescue ensure cancel end
#notify(ev)
Called by TupleSpace
to notify this NotifyTemplateEntry
of a new event.
# File 'lib/rinda/tuplespace.rb', line 255
def notify(ev) @queue.push(ev) end
#pop
Retrieves a notification. Raises RequestExpiredError when this NotifyTemplateEntry
expires.
# File 'lib/rinda/tuplespace.rb', line 263
def pop raise RequestExpiredError if @done it = @queue.pop @done = true if it[0] == 'close' return it end