A service factory that produces new WEBrick::HTTPServer instances. Each new service is automatically registered with the registry, so that when the registry is shutdown, the servers will also be shutdown.
Methods
Public Instance methods
The factory method that produces new HTTPServer instances. It accepts two mandatory parameters: ‘servlets’ and ‘setup’. See the schema for this service for more information on the parameters.
[ show source ]
# File lib/copland/webrick/http-server-factory.rb, line 127
127: def create_instance( point, parms )
128: servlets = parms[ 'servlets' ]
129: setup = parms[ 'setup' ]
130:
131: options = build_options( setup )
132: logger = point.owner.registry.logs.get( point.full_name )
133:
134: options[ :Logger ] = logger
135: options[ :AccessLog ] = [
136: [ logger, ::WEBrick::AccessLog::COMMON_LOG_FORMAT ],
137: [ logger, ::WEBrick::AccessLog::REFERER_LOG_FORMAT ] ]
138:
139: auto_start = setup[ 'server.auto.start' ]
140:
141: server = ::WEBrick::HTTPServer.new( options )
142:
143: servlets.each do |servlet|
144: mount_point = servlet[ 'mount' ]
145: options = servlet[ 'options' ] || []
146:
147: if servlet[ 'class' ] && servlet[ 'service' ]
148: raise "'class' and 'service' both specified " +
149: "for servlet at #{mount_point} for #{point.full_name}"
150: end
151:
152: if servlet[ 'service' ]
153: handler = servlet[ 'service' ]
154: elsif servlet[ 'class' ]
155: handler = Copland::get_class( servlet[ 'class' ] )
156: else
157: raise "you must specify either 'service' or 'class' " +
158: "for servlet at #{mount_point} for #{point.full_name}"
159: end
160:
161: server.mount( mount_point, handler, *options )
162: end
163:
164: service = HTTPServerService.new( server )
165: service.start if auto_start
166:
167: point.owner.registry.add_listener( service )
168:
169: return service
170: end