# code: # * George Moschovitis # # (c) 20024 Navel, all rights reserved. # $Id: filters.rb 111 2004-10-27 09:30:19Z gmosx $ require "socket" require "thread" require "sync" module N # == Filter # # A server serves client requests by feeding the request/request pair # to a pipeline of processing filters. This is not a simple linear pipeline. # Instead it is what we call a 'folding' (hierarchical) pipeline: each # filter encapsulates the next. In effect, the pipeline is a generalized # filter! # # === Design: # # Filters are NOT singleton classes. This way we can assign one filter # class to multiple resources, and keep statistics and metrics for # each resource. # A filter may contain state (attributes) for example metrics. # class ServerFilter # the next filter in the pipeline. attr_reader :next_filter # set the filters next. # # example: # LogFilter.new(TimeFilter.new(PageFilter.new)) def initialize(next_filter = nil) @next_filter = next_filter end # set the filters next (next_filter). # # example: # LogFilter.new << TimeFilter.new << PageFilter.new def << (next_filter = nil) @next_filter = next_filter end # override this method to implement your filter. def process(request) # preprocessing comes here... # walk the pipeline return process_next(request) # postprocessing comes here... # return the result... end # process the next filter in the pipeline def process_next(request) if @next_filter return @next_filter.process(request) else return nil end end end end # module