Class: N::ServerFilter
- Inherits:
-
Object
- Object
- N::ServerFilter
- Defined in:
- lib/n/server/filter.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#next_filter ⇒ Object
readonly
the next filter in the pipeline.
Instance Method Summary collapse
-
#<<(next_filter = nil) ⇒ Object
set the filters next (next_filter).
-
#initialize(next_filter = nil) ⇒ ServerFilter
constructor
set the filters next.
-
#process(request) ⇒ Object
override this method to implement your filter.
-
#process_next(request) ⇒ Object
process the next filter in the pipeline.
Constructor Details
#initialize(next_filter = nil) ⇒ ServerFilter
set the filters next.
example: LogFilter.new(TimeFilter.new(PageFilter.new))
39 40 41 |
# File 'lib/n/server/filter.rb', line 39 def initialize(next_filter = nil) @next_filter = next_filter end |
Instance Attribute Details
#next_filter ⇒ Object (readonly)
the next filter in the pipeline.
32 33 34 |
# File 'lib/n/server/filter.rb', line 32 def next_filter @next_filter end |
Instance Method Details
#<<(next_filter = nil) ⇒ Object
set the filters next (next_filter).
example: LogFilter.new << TimeFilter.new << PageFilter.new
48 49 50 |
# File 'lib/n/server/filter.rb', line 48 def << (next_filter = nil) @next_filter = next_filter end |
#process(request) ⇒ Object
override this method to implement your filter.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/n/server/filter.rb', line 54 def process(request) # preprocessing comes here... # walk the pipeline return process_next(request) # postprocessing comes here... # return the result... end |
#process_next(request) ⇒ Object
process the next filter in the pipeline
67 68 69 70 71 72 73 |
# File 'lib/n/server/filter.rb', line 67 def process_next(request) if @next_filter return @next_filter.process(request) else return nil end end |