indexing description: "Origo service" license: "MIT license (see ../../license.txt)" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class O_SERVICE feature {NONE} -- Initialization make (a_configuration: O_SERVICE_ADVERTISEMENT; a_logger: L4E_LOGGER) is -- Create new Origo service using `a_configuration' require Configuration_valid: a_configuration /= Void and a_configuration.is_valid local role_equality_tester: KL_EQUALITY_TESTER [O_SERVICE_ROLE_ADVERTISEMENT] string_equality_tester: KL_EQUALITY_TESTER [STRING] do create roles.make_default create string_equality_tester roles.set_key_equality_tester (string_equality_tester) create role_equality_tester roles.set_equality_tester (role_equality_tester) configuration := a_configuration logger := a_logger end feature -- Access configuration: O_SERVICE_ADVERTISEMENT p2p_module: O_P2P_MODULE feature -- Basic operations start_all is -- Start all service roles local cursor: DS_HASH_TABLE_CURSOR [O_SERVICE_ROLE_ADVERTISEMENT, STRING] do logger.info ("Starting all service roles for service: " + configuration.type.out + "/" + configuration.name) from cursor := roles.new_cursor cursor.start until cursor.after loop start_role (cursor.key) cursor.forth end end start_role (a_role: STRING) is -- Start service `a_role' require Role_valid: a_role /= Void and has_role (a_role) deferred end suspend_all is -- Suspend all service roles local cursor: DS_HASH_TABLE_CURSOR [O_SERVICE_ROLE_ADVERTISEMENT, STRING] do logger.info ("Suspending all service roles for service: " + configuration.type.out + "/" + configuration.name) from cursor := roles.new_cursor cursor.start until cursor.after loop suspend_role (cursor.key) cursor.forth end end suspend_role (a_role: STRING) is -- Suspend service `a_role' require Role_valid: a_role /= Void and has_role (a_role) deferred end register (a_p2p_module: O_P2P_MODULE) is -- Register service at core using `a_p2p_module' require P2p_module_set: a_p2p_module /= Void do p2p_module := a_p2p_module p2p_module.register (Current) ensure P2p_module_set: p2p_module = a_p2p_module end unregister is -- Register service at core using `a_p2p_module' require P2p_module_set: p2p_module /= Void do p2p_module.unregister (Current) p2p_module := Void ensure P2p_module_unref: p2p_module = Void end publish_configuration is -- Publish configuration to core require P2p_module_set: p2p_module /= Void do p2p_module.publish_configuration (Current) end process_network_message (a_msg: O_SERVICE_CONTROL_MESSAGE) is -- Process incoming control message `a_msg' require Message_valid: a_msg /= Void and a_msg.is_valid do logger.debugging ("Received control message, command: " + a_msg.control_command.out) inspect a_msg.control_command when {O_SERVICE_CONTROL_MESSAGE}.command_request_status_start then if a_msg.service_role = Void then start_all elseif has_role (a_msg.service_role) then start_role (a_msg.service_role) end when {O_SERVICE_CONTROL_MESSAGE}.command_request_status_suspend then if a_msg.service_role = Void then suspend_all elseif has_role (a_msg.service_role) then suspend_role (a_msg.service_role) end end end feature -- Service Roles registered_roles: DS_LIST [O_SERVICE_ROLE_ADVERTISEMENT] -- Role advertisement for `a_role' do create {DS_ARRAYED_LIST [O_SERVICE_ROLE_ADVERTISEMENT]} Result.make_from_linear (roles) Result.set_equality_tester (roles.equality_tester) ensure Result_set: Result /= Void and Result.equality_tester /= Void end has_role (a_role: STRING): BOOLEAN is -- Is `a_role' registered? require Role_valid: a_role /= Void do Result := roles.has (a_role) end extend_role (a_role: O_SERVICE_ROLE_ADVERTISEMENT) is -- Extend service with `a_role' require Role_valid: a_role /= Void and a_role.is_valid do if not has_role (a_role.role) then roles.force (a_role, a_role.role) logger.debugging ("Extended service role: " + a_role.type.out + "/" + a_role.name + "/" + a_role.role) end ensure Role_registered: has_role (a_role.role) end prune_role (a_role: STRING) is -- Prune `a_role' from service require Role_valid: a_role /= Void do roles.remove (a_role) logger.debugging ("Pruned service role: " + configuration.type.out + "/" + configuration.name + "/" + a_role) ensure Role_pruned: not has_role (a_role) end feature {NONE} -- Implementation roles: DS_HASH_TABLE [O_SERVICE_ROLE_ADVERTISEMENT, STRING] logger: L4E_LOGGER invariant Configuration_set: configuration /= Void Logger_set: logger /= Void end