lib/openwfe/expool/expstorage.rb in openwferu-0.9.14 vs lib/openwfe/expool/expstorage.rb in openwferu-0.9.15

- old
+ new

@@ -46,17 +46,60 @@ require 'openwfe/flowexpressionid' module OpenWFE # + # This module contains the observe_expool method which binds the + # storage to the expression pool. + # It also features a to_s method for the expression storages including + # it. + # + module ExpressionStorageBase + + def observe_expool + + get_expression_pool.add_observer(:update) do |channel, fei, fe| + ldebug { ":update for #{fei}" } + self[fei] = fe + end + get_expression_pool.add_observer(:remove) do |channel, fei| + ldebug { ":delete for #{fei}" } + self.delete(fei) + end + end + + def to_s + + s = "\n\n==== #{self.class} ====" + + self.each do |k, v| + s << "\n" + if v.kind_of?(RawExpression) + s << "*raw" + else + s << " " + end + #s << v.to_s + s << v.fei.to_s + s << " key/value mismatch !" if k != v.fei + end + s << "\n==== . ====\n" + + s + end + end + + # # This cache uses a LruHash (Least Recently Used) to store expressions. # If an expression is not cached, the 'real storage' is consulted. # The real storage is supposed to be the service named # "expressionStorage.1" # class CacheExpressionStorage - include ServiceMixin, OwfeServiceLocator + include ServiceMixin + include OwfeServiceLocator + include ExpressionStorageBase # # under 20 stored expressions, the unit tests for the # CachedFilePersistedEngine do fail because the persistent storage # behind the cache hasn't the time to flush its work queue. @@ -80,21 +123,11 @@ @cache = LruHash.new(size) @real_storage = nil - # - # expstorage observes expool : - - get_expression_pool.add_observer(:update) do |channel, fei, fe| - ldebug { ":update for #{fei}" } - self[fei] = fe - end - get_expression_pool.add_observer(:remove) do |channel, fei| - ldebug { ":delete for #{fei}" } - self.delete(fei) - end + observe_expool end def [] (fei) #ldebug { "[] size is #{@cache.size}" } @@ -169,18 +202,10 @@ def real_each (wfid_prefix=nil, &block) get_real_storage.each(wfid_prefix, &block) end - # - # Displays a human-friendly view on this storage - # - def to_s - - expstorage_to_s(self) - end - protected # # Returns the "real storage" i.e. the storage that does the real # persistence behind this "cache storage". @@ -199,39 +224,21 @@ # # Memory consuming in-memory storage. # No memory limit, puts everything in a Hash # class InMemoryExpressionStorage < Hash - include ServiceMixin, OwfeServiceLocator + include ServiceMixin + include OwfeServiceLocator + include ExpressionStorageBase def initialize (service_name, application_context) service_init(service_name, application_context) - # - # expstorage observes expool : - - get_expression_pool.add_observer(:update) do |channel, fei, fe| - #ldebug { ":update for #{fei}" } - self[fei] = fe - end - get_expression_pool.add_observer(:remove) do |channel, fei| - #ldebug { ":delete for #{fei}" } - self.delete fei - end + observe_expool end - #def []= (fei, fe) - # super fei.hash, fe - #end - #def [] (fei) - # super fei.hash - #end - #def delete (fei) - # super fei.hash - #end - alias :purge :clear # # Allows to pass a block to each expressions of a given kind (type). # @@ -256,39 +263,10 @@ super(&block) end end - def to_s - expstorage_to_s(self) - end - alias :real_each :each - end - - # - # a small help method for expression storages... - # - # TODO : put that in a module ! - # - def expstorage_to_s (expstorage) - - s = "\n\n==== #{expstorage.class} ====" - - expstorage.each do |k, v| - s << "\n" - if v.kind_of?(RawExpression) - s << "*raw" - else - s << " " - end - #s << v.to_s - s << v.fei.to_s - s << " key/value mismatch !" if k != v.fei - end - s << "\n==== . ====\n" - - s end end