From bfa620eee3bdd1ca03ef9ed713fe1067acdb74eb Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 15 Dec 2011 13:30:19 +0100 Subject: [PATCH] Made DEFAULT_SERVICE_LAUNCHER more flexible for the user. --- .../ewsgi/connectors/nino/src/nino_service.e | 8 + .../connectors/nino/src/wgi_nino_connector.e | 2 +- .../connectors/nino/src/wgi_nino_handler.e | 2 +- .../default/cgi/default_service_launcher.e | 35 ++-- .../libfcgi/default_service_launcher.e | 37 ++-- .../default/nino/default_service_launcher.e | 160 +++++++++--------- .../src/default/default_service_launcher_i.e | 138 +++++++++++++++ 7 files changed, 262 insertions(+), 120 deletions(-) create mode 100644 library/server/wsf/src/default/default_service_launcher_i.e diff --git a/library/server/ewsgi/connectors/nino/src/nino_service.e b/library/server/ewsgi/connectors/nino/src/nino_service.e index b63bffd0..cc3cf14a 100644 --- a/library/server/ewsgi/connectors/nino/src/nino_service.e +++ b/library/server/ewsgi/connectors/nino/src/nino_service.e @@ -29,6 +29,8 @@ feature {NONE} -- Implementation create connector.make_with_base (app, a_base_url) end +feature -- Access + connector: WGI_NINO_CONNECTOR -- Web server connector @@ -65,6 +67,12 @@ feature -- Status settings configuration.set_is_verbose (b) end + set_base_url (s: detachable READABLE_STRING_8) + -- Set base_url to `s' + do + connector.set_base (s) + end + feature -- Server listen (a_port: INTEGER) diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e index 621c6704..4de5fb99 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e @@ -58,7 +58,7 @@ feature -- Access feature -- Access - base: detachable STRING + base: detachable READABLE_STRING_8 -- Root url base feature -- Status report diff --git a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e index 80094443..07b683b2 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_handler.e @@ -31,7 +31,7 @@ feature {NONE} -- Initialization feature -- Access - base: detachable STRING + base: detachable READABLE_STRING_8 -- Root url base feature -- Element change diff --git a/library/server/wsf/default/cgi/default_service_launcher.e b/library/server/wsf/default/cgi/default_service_launcher.e index 53d7379e..d7f86a0b 100644 --- a/library/server/wsf/default/cgi/default_service_launcher.e +++ b/library/server/wsf/default/cgi/default_service_launcher.e @@ -2,7 +2,7 @@ note description: "[ Component to launch the service using the default connector - which is CGI for this class + CGI for this class How-to: @@ -21,40 +21,35 @@ class DEFAULT_SERVICE_LAUNCHER inherit - WSF_SERVICE + DEFAULT_SERVICE_LAUNCHER_I create + make, make_and_launch, make_and_launch_with_options feature {NONE} -- Initialization - make_and_launch (a_action: like action) - local - cgi: WGI_CGI_CONNECTOR + initialize do - action := a_action - 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) + create connector.make (Current) end feature -- Execution - action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] - -- Action to be executed on request incoming - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- + launch do - action.call ([req, res]) + if attached connector as conn then + conn.launch + end end -note +feature -- Status report + + connector: detachable WGI_CGI_CONNECTOR + -- Default service name + +;note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ diff --git a/library/server/wsf/default/libfcgi/default_service_launcher.e b/library/server/wsf/default/libfcgi/default_service_launcher.e index 70b5e7f3..b85229cf 100644 --- a/library/server/wsf/default/libfcgi/default_service_launcher.e +++ b/library/server/wsf/default/libfcgi/default_service_launcher.e @@ -2,7 +2,7 @@ note description: "[ Component to launch the service using the default connector - which is libFCGI for this class + libFCGI for this class How-to: @@ -21,40 +21,35 @@ class DEFAULT_SERVICE_LAUNCHER inherit - WSF_SERVICE + DEFAULT_SERVICE_LAUNCHER_I create + make, make_and_launch, make_and_launch_with_options feature {NONE} -- Initialization - make_and_launch (a_action: like action) - local - conn: WGI_LIBFCGI_CONNECTOR + initialize do - action := a_action - create conn.make (Current) - conn.launch + create connector.make (Current) 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 - + feature -- Execution - action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] - -- Action to be executed on request incoming - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- + launch do - action.call ([req, res]) + if attached connector as conn then + conn.launch + end end -note +feature -- Status report + + connector: detachable WGI_LIBCGI_CONNECTOR + -- Default service name + +;note copyright: "2011-2011, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ diff --git a/library/server/wsf/default/nino/default_service_launcher.e b/library/server/wsf/default/nino/default_service_launcher.e index fb883127..83e0c05c 100644 --- a/library/server/wsf/default/nino/default_service_launcher.e +++ b/library/server/wsf/default/nino/default_service_launcher.e @@ -2,26 +2,16 @@ note description: "[ 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 - 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: + The Nino default connector support options: port: numeric such as 8099 (or equivalent string as "8099") base: base_url (very specific to standalone server) 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$" revision: "$Revision$" @@ -30,90 +20,106 @@ class DEFAULT_SERVICE_LAUNCHER inherit - WSF_SERVICE + DEFAULT_SERVICE_LAUNCHER_I + redefine + launchable + end create + make, make_and_launch, make_and_launch_with_options feature {NONE} -- Initialization - make_and_launch (a_action: like action) - 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]]) + initialize local - port_number: INTEGER - base_url: STRING - verbose: BOOLEAN - l_name: READABLE_STRING_GENERAL + l_name: detachable READABLE_STRING_GENERAL do - action := a_action port_number := 80 --| Default, but quite often, this port is already used ... base_url := "" - across - a_options as opt - loop - if attached opt.item as l_opt_item then - l_name := l_opt_item.name - if l_name.same_string ("port") then - if attached {INTEGER} l_opt_item.value as l_port then - port_number := l_port - elseif - attached {READABLE_STRING_GENERAL} l_opt_item.value as l_port_str and then - l_port_str.is_integer - then - port_number := l_port_str.as_string_8.to_integer - end - elseif l_name.same_string ("base") then - if attached {READABLE_STRING_GENERAL} l_opt_item.value as l_base_str then - base_url := l_base_str.as_string_8 - end - elseif l_name.same_string ("verbose") then - if attached {BOOLEAN} l_opt_item.value as l_verbose then - verbose := l_verbose - elseif attached {READABLE_STRING_GENERAL} l_opt_item.value as l_verbose_str then - verbose := l_verbose_str.as_lower.same_string ("true") + if attached options as opts then + across + opts as opt + loop + if attached opt.item as l_opt_item then + l_name := l_opt_item.name + if l_name.same_string ("port") then + if attached {INTEGER} l_opt_item.value as l_port then + port_number := l_port + elseif + attached {READABLE_STRING_GENERAL} l_opt_item.value as l_port_str and then + l_port_str.is_integer + then + port_number := l_port_str.as_string_8.to_integer + end + elseif l_name.same_string ("base") then + if attached {READABLE_STRING_GENERAL} l_opt_item.value as l_base_str then + base_url := l_base_str.as_string_8 + 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 + if attached {BOOLEAN} l_opt_item.value as l_verbose then + verbose := l_verbose + elseif attached {READABLE_STRING_GENERAL} l_opt_item.value as l_verbose_str then + verbose := l_verbose_str.as_lower.same_string ("true") + end end end end end - launch (port_number, base_url, verbose) - end - - 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) + create connector.make (Current) end feature -- Execution - action: PROCEDURE [ANY, TUPLE [WSF_REQUEST, WSF_RESPONSE]] - -- Action to be executed on request incoming - - execute (req: WSF_REQUEST; res: WSF_RESPONSE) - -- + launch + -- + -- using `port_number', `base_url', `verbose' and `single_threaded' 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 -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" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ diff --git a/library/server/wsf/src/default/default_service_launcher_i.e b/library/server/wsf/src/default/default_service_launcher_i.e new file mode 100644 index 00000000..ab5c5418 --- /dev/null +++ b/library/server/wsf/src/default/default_service_launcher_i.e @@ -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) + -- + 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