Sha256: 70fe834f60e9cbcfdab144bf23ba6734bfed8ff38a3097c7913705a097aebdcb

Contents?: true

Size: 1.55 KB

Versions: 1

Compression:

Stored size: 1.55 KB

Contents

# = Server filter
#
# code:
# George Moschovitis  <gm@navel.gr>
#
# (c) 20024 Navel, all rights reserved.
# $Id: filter.rb 71 2004-10-18 10:50:22Z 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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nitro-0.1.2 lib/n/server/filter.rb