Made DEFAULT_SERVICE_LAUNCHER more flexible for the user.

This commit is contained in:
Jocelyn Fiat
2011-12-15 13:30:19 +01:00
parent b6784ee35c
commit bfa620eee3
7 changed files with 262 additions and 120 deletions

View File

@@ -29,6 +29,8 @@ feature {NONE} -- Implementation
create connector.make_with_base (app, a_base_url) create connector.make_with_base (app, a_base_url)
end end
feature -- Access
connector: WGI_NINO_CONNECTOR connector: WGI_NINO_CONNECTOR
-- Web server connector -- Web server connector
@@ -65,6 +67,12 @@ feature -- Status settings
configuration.set_is_verbose (b) configuration.set_is_verbose (b)
end end
set_base_url (s: detachable READABLE_STRING_8)
-- Set base_url to `s'
do
connector.set_base (s)
end
feature -- Server feature -- Server
listen (a_port: INTEGER) listen (a_port: INTEGER)

View File

@@ -58,7 +58,7 @@ feature -- Access
feature -- Access feature -- Access
base: detachable STRING base: detachable READABLE_STRING_8
-- Root url base -- Root url base
feature -- Status report feature -- Status report

View File

@@ -31,7 +31,7 @@ feature {NONE} -- Initialization
feature -- Access feature -- Access
base: detachable STRING base: detachable READABLE_STRING_8
-- Root url base -- Root url base
feature -- Element change feature -- Element change

View File

@@ -2,7 +2,7 @@ note
description: "[ description: "[
Component to launch the service using the default connector Component to launch the service using the default connector
which is CGI for this class CGI for this class
How-to: How-to:
@@ -21,40 +21,35 @@ class
DEFAULT_SERVICE_LAUNCHER DEFAULT_SERVICE_LAUNCHER
inherit inherit
WSF_SERVICE DEFAULT_SERVICE_LAUNCHER_I
create create
make,
make_and_launch, make_and_launch,
make_and_launch_with_options make_and_launch_with_options
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_and_launch (a_action: like action) initialize
local
cgi: WGI_CGI_CONNECTOR
do do
action := a_action create connector.make (Current)
create cgi.make (Current)
cgi.launch
end
make_and_launch_with_options (a_action: like action; a_options: ARRAY [detachable TUPLE [name: READABLE_STRING_GENERAL; value: detachable ANY]])
do
make_and_launch (a_action)
end end
feature -- Execution feature -- Execution
action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] launch
-- Action to be executed on request incoming
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do do
action.call ([req, res]) if attached connector as conn then
conn.launch
end
end end
note feature -- Status report
connector: detachable WGI_CGI_CONNECTOR
-- Default service name
;note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[

View File

@@ -2,7 +2,7 @@ note
description: "[ description: "[
Component to launch the service using the default connector Component to launch the service using the default connector
which is libFCGI for this class libFCGI for this class
How-to: How-to:
@@ -21,40 +21,35 @@ class
DEFAULT_SERVICE_LAUNCHER DEFAULT_SERVICE_LAUNCHER
inherit inherit
WSF_SERVICE DEFAULT_SERVICE_LAUNCHER_I
create create
make,
make_and_launch, make_and_launch,
make_and_launch_with_options make_and_launch_with_options
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_and_launch (a_action: like action) initialize
local
conn: WGI_LIBFCGI_CONNECTOR
do do
action := a_action create connector.make (Current)
create conn.make (Current)
conn.launch
end
make_and_launch_with_options (a_action: like action; a_options: ARRAY [detachable TUPLE [name: READABLE_STRING_GENERAL; value: detachable ANY]])
do
make_and_launch (a_action)
end end
feature -- Execution feature -- Execution
action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] launch
-- Action to be executed on request incoming
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do do
action.call ([req, res]) if attached connector as conn then
conn.launch
end
end end
note feature -- Status report
connector: detachable WGI_LIBCGI_CONNECTOR
-- Default service name
;note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[

View File

@@ -2,26 +2,16 @@ note
description: "[ description: "[
Component to launch the service using the default connector Component to launch the service using the default connector
which is Eiffel Web Nino for this class Eiffel Web Nino for this class
How-to:
s: DEFAULT_SERVICE_LAUNCHER The Nino default connector support options:
create s.make_and_launch (agent execute)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
-- ...
end
You can also provide specific options that might be relevant
only for specific connectors such as
create s.make_and_launch_and_options (agent execute, <<["port", 8099]>>)
The Nino default connector support:
port: numeric such as 8099 (or equivalent string as "8099") port: numeric such as 8099 (or equivalent string as "8099")
base: base_url (very specific to standalone server) base: base_url (very specific to standalone server)
verbose: to display verbose output, useful for Nino verbose: to display verbose output, useful for Nino
force_single_threaded: use only one thread, useful for Nino
check DEFAULT_SERVICE_LAUNCHER_I for more documentation
]" ]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
@@ -30,32 +20,27 @@ class
DEFAULT_SERVICE_LAUNCHER DEFAULT_SERVICE_LAUNCHER
inherit inherit
WSF_SERVICE DEFAULT_SERVICE_LAUNCHER_I
redefine
launchable
end
create create
make,
make_and_launch, make_and_launch,
make_and_launch_with_options make_and_launch_with_options
feature {NONE} -- Initialization feature {NONE} -- Initialization
make_and_launch (a_action: like action) initialize
do
action := a_action
launch (80, "", False)
end
make_and_launch_with_options (a_action: like action; a_options: ARRAY [detachable TUPLE [name: READABLE_STRING_GENERAL; value: detachable ANY]])
local local
port_number: INTEGER l_name: detachable READABLE_STRING_GENERAL
base_url: STRING
verbose: BOOLEAN
l_name: READABLE_STRING_GENERAL
do do
action := a_action
port_number := 80 --| Default, but quite often, this port is already used ... port_number := 80 --| Default, but quite often, this port is already used ...
base_url := "" base_url := ""
if attached options as opts then
across across
a_options as opt opts as opt
loop loop
if attached opt.item as l_opt_item then if attached opt.item as l_opt_item then
l_name := l_opt_item.name l_name := l_opt_item.name
@@ -72,6 +57,12 @@ feature {NONE} -- Initialization
if attached {READABLE_STRING_GENERAL} l_opt_item.value as l_base_str then if attached {READABLE_STRING_GENERAL} l_opt_item.value as l_base_str then
base_url := l_base_str.as_string_8 base_url := l_base_str.as_string_8
end end
elseif l_name.same_string ("force_single_threaded") then
if attached {BOOLEAN} l_opt_item.value as l_single_threaded then
single_threaded := l_single_threaded
elseif attached {READABLE_STRING_GENERAL} l_opt_item.value as l_single_threaded_str then
single_threaded := l_single_threaded_str.as_lower.same_string ("true")
end
elseif l_name.same_string ("verbose") then elseif l_name.same_string ("verbose") then
if attached {BOOLEAN} l_opt_item.value as l_verbose then if attached {BOOLEAN} l_opt_item.value as l_verbose then
verbose := l_verbose verbose := l_verbose
@@ -81,39 +72,54 @@ feature {NONE} -- Initialization
end end
end end
end end
launch (port_number, base_url, verbose)
end end
create connector.make (Current)
launch (a_port: INTEGER; a_base: STRING; a_verbose: BOOLEAN)
-- Launch service with `a_port', `a_base' and `a_verbose' value
require
a_port_valid: a_port > 0
local
app: NINO_SERVICE
do
create app.make_custom (agent wgi_execute, a_base)
app.set_is_verbose (a_verbose)
debug ("nino")
if a_verbose then
print ("Example: start a Nino web server on port " + a_port.out +
", %Nand reply Hello World for any request such as http://localhost:" + a_port.out + "/" + a_base + "%N")
end
end
app.listen (a_port)
end end
feature -- Execution feature -- Execution
action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] launch
-- Action to be executed on request incoming -- <Precursor/>
-- using `port_number', `base_url', `verbose' and `single_threaded'
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do do
action.call ([req, res]) if attached connector as conn then
conn.set_base (base_url)
if single_threaded then
conn.configuration.set_force_single_threaded (True)
end
conn.configuration.set_is_verbose (verbose)
debug ("nino")
if verbose then
print ("Example: start a Nino web server on port " + port_number.out +
", %Nand reply Hello World for any request such as http://localhost:" + port_number.out + "/" + base_url + "%N")
end
end
conn.configuration.http_server_port := port_number
conn.launch
end
end end
note feature {NONE} -- Implementation
port_number: INTEGER
base_url: READABLE_STRING_8
verbose: BOOLEAN
single_threaded: BOOLEAN
feature -- Status report
connector: detachable WGI_NINO_CONNECTOR
-- Default connector
launchable: BOOLEAN
do
Result := Precursor and port_number > 0
end
;note
copyright: "2011-2011, Eiffel Software and others" copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[ source: "[

View File

@@ -0,0 +1,138 @@
note
description: "[
Component to launch the service using the default connector
How-to:
s: DEFAULT_SERVICE_LAUNCHER
create s.make_and_launch (agent execute)
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
do
-- ...
end
You can also provide specific options that might be relevant
only for specific connectors such as
For instance, you can use
create s.make_and_launch_and_options (agent execute, <<["port", 8099]>>)
And if Nino is the default connector it will support:
port: numeric such as 8099 (or equivalent string as "8099")
base: base_url (very specific to standalone server)
force_single_threaded: use only one thread, useful for Nino
verbose: to display verbose output, useful for Nino
]"
date: "$Date$"
revision: "$Revision$"
deferred class
DEFAULT_SERVICE_LAUNCHER_I
inherit
WSF_SERVICE
feature {NONE} -- Initialization
frozen make (a_action: like action; a_options: like options)
do
action := a_action
options := a_options
initialize
ensure
action_set: action = a_action
options_set: options = a_options
launchable: launchable
end
frozen make_and_launch (a_action: like action)
do
make (a_action, Void)
launch
end
frozen make_and_launch_with_options (a_action: like action; a_options: attached like options)
require
a_options_attached: a_options /= Void
do
make (a_action, a_options)
launch
end
initialize
-- Initialize Current using `options' if attached
-- and build the connector
require
action_set: action /= Void
deferred
ensure
connector_attached: connector /= Void
end
feature -- Status report
launchable: BOOLEAN
-- Is default service launchable?
do
Result := connector /= Void
end
connector: detachable WGI_CONNECTOR
-- Connector associated to current default service
deferred
end
connector_name: READABLE_STRING_8
-- Connector's name associated to current default service
do
if attached connector as conn then
Result := conn.name
else
check
connector_attached: False
end
Result := ""
end
end
feature -- Execution
launch
-- Launch default service
require
launchable: launchable
deferred
end
feature {NONE} -- Implementation
options: detachable ARRAY [detachable TUPLE [name: READABLE_STRING_GENERAL; value: detachable ANY]]
-- Custom options which might be support (or not) by the default service
action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]]
-- Action to be executed on request incoming
feature {NONE} -- Implementation: Execution
execute (req: WSF_REQUEST; res: WSF_RESPONSE)
-- <Precursor>
do
action.call ([req, res])
end
invariant
connector_attached: connector /= Void
note
copyright: "2011-2011, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end