indexing description: "Interface for module loaded by a peer group" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class P2P_MODULE inherit P2P_CONSTANTS feature -- Access module_id: P2P_ID peer_group: P2P_PEERGROUP implementation_advertisement: P2P_MODULE_IMPLEMENTATION_ADVERTISEMENT logger: L4E_LOGGER feature -- Status report module_status: INTEGER Initializing: INTEGER is 0 -- When module gets/is constructed Init_failed: INTEGER is 1 -- When module construction failed Start_ok: INTEGER is 2 -- When module is successfully running Start_failed: INTEGER is 3 -- When start process failed Suspended: INTEGER is 4 -- When module is suspended (and ready to stop or start again) Suspending: INTEGER is 5 -- When module is stopping (internal status) Stop_ok: INTEGER is 6 -- When module is stopped and can't be started again feature {NONE} -- Initialization init (group: like peer_group; an_id: like module_id; advertisement: like implementation_advertisement) is -- Initialize module require Group_valid: group /= Void Configuration_valid: group.configuration /= Void and group.configuration.is_valid Id_valid: an_id /= Void Advertisement_valid: advertisement /= Void Dependencies_met: check_dependencies (group) do peer_group := group module_id := an_id implementation_advertisement := advertisement logger := group.logger logger.debugging ("module: Initializing module, id: " + an_id.out) end feature -- Basic operations start (args: ARRAY [STRING]) is -- Start module require Init_ok: module_status = initializing or module_status = suspended deferred ensure Status_set: module_status = start_ok or module_status = start_failed end suspend is -- Suspend service require Start_ok: module_status = start_ok deferred ensure Status_set: module_status = suspended end stop is -- Stop module in any case require Start_suspended: module_status = suspended deferred ensure Status_set: module_status = stop_ok end feature {NONE} -- Implementation check_dependencies (a_parent: P2P_PEERGROUP): BOOLEAN is -- Are all needed dependencies met? require Parent_group_valid: a_parent /= Void deferred end invariant Group_valid: peer_group /= Void Id_valid: module_id /= Void Advertisement_valid: implementation_advertisement /= Void end