90 |
QUEUE = "queue_slot" |
QUEUE = "queue_slot" |
91 |
STACK = "stack_slot" |
STACK = "stack_slot" |
92 |
PROC = "proc_slot" |
PROC = "proc_slot" |
93 |
|
HASH = "hash_slot" |
94 |
|
|
95 |
# True if notify method propagates to parent.notify, default=true |
# True if notify method propagates to parent.notify, default=true |
96 |
attr_accessor :propagate_notifications |
attr_accessor :propagate_notifications |
283 |
end |
end |
284 |
|
|
285 |
## |
## |
286 |
# Clears the stack or queue depending on the slot type |
# calls hash.put if this is a hash slot |
287 |
|
# |
288 |
|
def put(key, value) |
289 |
|
return self.hash.put(key,value) |
290 |
|
end |
291 |
|
|
292 |
|
## |
293 |
|
# calls hash.get if this is a hash slot |
294 |
|
# |
295 |
|
def get(key) |
296 |
|
return self.hash.get(key) |
297 |
|
end |
298 |
|
|
299 |
|
## |
300 |
|
# removes a key if this is a hash slot |
301 |
|
# |
302 |
|
def remove(key) |
303 |
|
return self.hash.remove |
304 |
|
end |
305 |
|
|
306 |
|
## |
307 |
|
# Clears the stack or queue or hash depending on the slot type |
308 |
# |
# |
309 |
def clear |
def clear |
310 |
return self.queue.clear if is_queue_slot? |
return self.queue.clear if is_queue_slot? |
311 |
return self.stack.clear if is_stack_slot? |
return self.stack.clear if is_stack_slot? |
312 |
|
return self.hash.clear if is_hash_slot? |
313 |
end |
end |
314 |
|
|
315 |
## |
## |
320 |
def count |
def count |
321 |
return self.queue.count if is_queue_slot? |
return self.queue.count if is_queue_slot? |
322 |
return self.stack.count if is_stack_slot? |
return self.stack.count if is_stack_slot? |
323 |
|
return self.hash.count if is_hash_slot? |
324 |
end |
end |
325 |
|
|
326 |
## |
## |
401 |
end |
end |
402 |
|
|
403 |
## |
## |
404 |
|
# Retrieves the HashWrapper object if this is a hash slot |
405 |
|
# |
406 |
|
# return:: [FreeBASE::DataBus::HashWrapper] The HashWrapper object of this Hash slot |
407 |
|
# raise:: [RuntimeException] If this slot is not a Hash slot |
408 |
|
# |
409 |
|
def hash |
410 |
|
check_type(HASH) |
411 |
|
@hash = HashWrapper.new(self) unless @hash |
412 |
|
return @hash |
413 |
|
end |
414 |
|
|
415 |
|
## |
416 |
|
# Checks if this is a Hash slot |
417 |
|
# |
418 |
|
# return:: [Boolean] true if this is a Hash slot |
419 |
|
# |
420 |
|
def is_hash_slot? |
421 |
|
return @type==HASH |
422 |
|
end |
423 |
|
|
424 |
|
## |
425 |
# Checks to see if the type of slot is as specified. If the type is not defined, the |
# Checks to see if the type of slot is as specified. If the type is not defined, the |
426 |
# type is set to the supplied type. |
# type is set to the supplied type. |
427 |
# |
# |
764 |
end |
end |
765 |
|
|
766 |
## |
## |
767 |
|
# The HashWrapper holds the Hash object for the Hash slot |
768 |
|
# |
769 |
|
# Usage:: |
770 |
|
# p = HashWrapper.new(self) |
771 |
|
# p.put(key, value) |
772 |
|
# p.get(key) #=> value |
773 |
|
# |
774 |
|
class HashWrapper |
775 |
|
## |
776 |
|
# Create the ProcWrapper object |
777 |
|
# |
778 |
|
# slot:: [FreeBASE::DataBus::Slot] The slot this proc wrapper belongs to. |
779 |
|
# |
780 |
|
def initialize(slot) |
781 |
|
@slot = slot |
782 |
|
@hash = {} |
783 |
|
end |
784 |
|
|
785 |
|
## |
786 |
|
# Sets the hash |
787 |
|
# |
788 |
|
# hash:: [Hash] The Hash to store |
789 |
|
# |
790 |
|
def set_hash(hash) |
791 |
|
@hash=hash |
792 |
|
@slot.notify(:notify_hash_set) |
793 |
|
end |
794 |
|
|
795 |
|
## |
796 |
|
# Clears the hash |
797 |
|
# |
798 |
|
def clear() |
799 |
|
@hash = {} |
800 |
|
@slot.notify(:notify_hash_cleared) |
801 |
|
end |
802 |
|
|
803 |
|
## |
804 |
|
# Removes an item from the hash |
805 |
|
# |
806 |
|
# key:: [key] The key to remove |
807 |
|
# |
808 |
|
def remove(key) |
809 |
|
return @hash.remove[key] |
810 |
|
@slot.notify(:notify_hash_remove) |
811 |
|
end |
812 |
|
|
813 |
|
## |
814 |
|
# Gets the value |
815 |
|
# |
816 |
|
# key:: [Object] The key |
817 |
|
# return:: [Object] The value of the specified key |
818 |
|
# |
819 |
|
def get(key) |
820 |
|
return @hash[key] |
821 |
|
end |
822 |
|
|
823 |
|
## |
824 |
|
# Sets the value of the supplied key |
825 |
|
# |
826 |
|
# key:: [Object] The key |
827 |
|
# value:: [Object] The value |
828 |
|
# |
829 |
|
def put(key, value) |
830 |
|
@hash[key]=value |
831 |
|
@slot.notify(:notify_hash_put) |
832 |
|
end |
833 |
|
|
834 |
|
## |
835 |
|
# Return the number of objects in the hash |
836 |
|
# |
837 |
|
# return:: [Integer] The number of objects |
838 |
|
# |
839 |
|
def count |
840 |
|
return @hash.size |
841 |
|
end |
842 |
|
|
843 |
|
end |
844 |
|
|
845 |
|
## |
846 |
# The Adapter is a helper class that allows for connecting slot |
# The Adapter is a helper class that allows for connecting slot |
847 |
# values together (in a Thread-safe way) so that changes to |
# values together (in a Thread-safe way) so that changes to |
848 |
# one (or more) slots would result in automatic updates to |
# one (or more) slots would result in automatic updates to |