From 22a725b8be1352f6a1f7f40714f97afa96ca2d6f Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Wed, 27 Feb 2013 21:49:42 +0100 Subject: [PATCH] Added a way to call a callback on launched and stopped for Nino connector --- .../connectors/nino/src/wgi_nino_connector.e | 14 +++++++ .../nino/wsf_nino_service_launcher.e | 42 +++++++++++++++---- 2 files changed, 47 insertions(+), 9 deletions(-) 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 81ed0265..e66ebbd5 100644 --- a/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e +++ b/library/server/ewsgi/connectors/nino/src/wgi_nino_connector.e @@ -23,6 +23,10 @@ feature {NONE} -- Initialization create cfg.make create server.make (cfg) + + -- Callbacks + create on_launched_actions + create on_stopped_actions end make_with_base (a_service: like service; a_base: like base) @@ -69,6 +73,14 @@ feature -- Status report -- Listening port. --| 0: not launched +feature -- Callbacks + + on_launched_actions: ACTION_SEQUENCE [TUPLE [WGI_CONNECTOR]] + -- Actions triggered when launched + + on_stopped_actions: ACTION_SEQUENCE [TUPLE [WGI_CONNECTOR]] + -- Actions triggered when stopped + feature -- Element change on_launched (a_port: INTEGER) @@ -76,11 +88,13 @@ feature -- Element change do launched := True port := a_port + on_launched_actions.call ([Current]) end on_stopped -- Server stopped do + on_stopped_actions.call ([Current]) launched := False port := 0 end diff --git a/library/server/wsf/connector/nino/wsf_nino_service_launcher.e b/library/server/wsf/connector/nino/wsf_nino_service_launcher.e index 1ee7f150..7fa62a9e 100644 --- a/library/server/wsf/connector/nino/wsf_nino_service_launcher.e +++ b/library/server/wsf/connector/nino/wsf_nino_service_launcher.e @@ -34,7 +34,12 @@ create feature {NONE} -- Initialization initialize + local + conn: like connector do + create on_launched_actions + create on_stopped_actions + port_number := 80 --| Default, but quite often, this port is already used ... base_url := "" @@ -64,14 +69,15 @@ feature {NONE} -- Initialization verbose := l_verbose_str.as_lower.same_string ("true") end end - create connector.make (Current) - 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) + create conn.make (Current) + conn.on_launched_actions.extend (agent on_launched) + conn.on_stopped_actions.extend (agent on_stopped) + connector := conn + conn.set_base (base_url) + if single_threaded then + conn.configuration.set_force_single_threaded (True) end + conn.configuration.set_is_verbose (verbose) end feature -- Execution @@ -104,8 +110,26 @@ feature -- Execution end end +feature -- Callback + + on_launched_actions: ACTION_SEQUENCE [TUPLE [WGI_CONNECTOR]] + -- Actions triggered when launched + + on_stopped_actions: ACTION_SEQUENCE [TUPLE [WGI_CONNECTOR]] + -- Actions triggered when stopped + feature {NONE} -- Implementation + on_launched (conn: WGI_CONNECTOR) + do + on_launched_actions.call ([conn]) + end + + on_stopped (conn: WGI_CONNECTOR) + do + on_stopped_actions.call ([conn]) + end + port_number: INTEGER server_name: detachable READABLE_STRING_8 @@ -123,11 +147,11 @@ feature -- Status report launchable: BOOLEAN do - Result := Precursor and port_number > 0 + Result := Precursor and port_number >= 0 end ;note - copyright: "2011-2012, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" + copyright: "2011-2013, Jocelyn Fiat, Javier Velilla, Eiffel Software and others" license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)" source: "[ Eiffel Software