Class Rinda::TupleBag
In: lib/rinda/tuplespace.rb
Parent: Object

TupleBag is an unordered collection of tuples. It is the basis of Tuplespace.

Methods

Public Instance methods

Removes ary from the TupleBag.

[Source]

     # File lib/rinda/tuplespace.rb, line 318
318:     def delete(ary)
319:       size = ary.size
320:       @hash.fetch(size, []).delete(ary)
321:     end

Delete tuples which dead tuples from the TupleBag, returning the deleted tuples.

[Source]

     # File lib/rinda/tuplespace.rb, line 355
355:     def delete_unless_alive
356:       deleted = []
357:       @hash.keys.each do |size|
358:         ary = []
359:         @hash[size].each do |tuple|
360:           if tuple.alive?
361:             ary.push(tuple)
362:           else
363:             deleted.push(tuple)
364:           end
365:         end
366:         @hash[size] = ary
367:       end
368:       deleted
369:     end

Finds a live tuple that matches template.

[Source]

     # File lib/rinda/tuplespace.rb, line 335
335:     def find(template)
336:       @hash.fetch(template.size, []).find do |tuple|
337:         tuple.alive? && template.match(tuple)
338:       end
339:     end

Finds all live tuples that match template.

[Source]

     # File lib/rinda/tuplespace.rb, line 326
326:     def find_all(template)
327:       @hash.fetch(template.size, []).find_all do |tuple|
328:         tuple.alive? && template.match(tuple)
329:       end
330:     end

Finds all tuples in the TupleBag which when treated as templates, match tuple and are alive.

[Source]

     # File lib/rinda/tuplespace.rb, line 345
345:     def find_all_template(tuple)
346:       @hash.fetch(tuple.size, []).find_all do |template|
347:         template.alive? && template.match(tuple)
348:       end
349:     end

true if the TupleBag to see if it has any expired entries.

[Source]

     # File lib/rinda/tuplespace.rb, line 297
297:     def has_expires?
298:       @hash.each do |k, v|
299:         v.each do |tuple|
300:           return true if tuple.expires
301:         end
302:       end
303:       false
304:     end

Add ary to the TupleBag.

[Source]

     # File lib/rinda/tuplespace.rb, line 309
309:     def push(ary)
310:       size = ary.size
311:       @hash[size] ||= []
312:       @hash[size].push(ary)
313:     end

[Validate]