indexing description: "Represents an advertisement" author: "Beat Strasser " date: "$Date$" revision: "$Revision$" deferred class P2P_ADVERTISEMENT inherit P2P_XML_CACHE redefine initialize end P2P_CREATORS_SHARED undefine out end DT_SHARED_SYSTEM_CLOCK export {NONE} all undefine out end feature -- Access index_elements: DS_LIST [TUPLE [STRING, STRING]] is -- Indexable elements require Adv_valid: is_valid deferred ensure Result_set: Result /= Void end unique_id: STRING is -- Unique id. Void, if advertisement shouldn't/can't be indexed. require Valid: is_valid deferred end expiration_time: INTEGER_64 is -- Remote expiration time in ms (not included in document) local expiration_lifetime: DT_DATE_TIME do if lifetime_absolute /= Void then -- if expiration life time is longer than the life time, calculate max possible expiration expiration_lifetime := utc_system_clock.date_time_now expiration_lifetime.add_milliseconds (possible_expiration_time.as_integer_32) if expiration_lifetime > lifetime_absolute then Result := (lifetime_absolute - utc_system_clock.date_time_now).millisecond_count elseif possible_expiration_time > 0 then Result := possible_expiration_time else Result := {P2P_DISCOVERY_SERVICE}.default_expiration_time end elseif possible_expiration_time > 0 then Result := possible_expiration_time else Result := {P2P_DISCOVERY_SERVICE}.default_expiration_time end end lifetime_absolute: DT_DATE_TIME -- Absolute lifetime (not included in document) creation_time: DT_DATE_TIME -- Absolute creation time (not included in document) has_expired: BOOLEAN is -- Has advertisement exceeded its lifetime? do if lifetime_absolute /= Void then Result := utc_system_clock.date_time_now >= lifetime_absolute end end is_newer_than (a_time: DT_DATE_TIME): BOOLEAN is -- Is advertisement newer than the given `a_time'? require Time_valid: a_time /= Void do if creation_time /= Void then Result := creation_time > a_time end end feature -- Element change set_expiration_time (a_time_span: like expiration_time) is -- Set remote expiration `a_time_span' in ms require Time_span_valid: a_time_span > 0 do possible_expiration_time := a_time_span ensure Time_set: expiration_time <= a_time_span end set_lifetime_relative (a_time_span: like expiration_time) is -- Set lifetime (`a_time_span' in ms) relative to now require Time_valid: a_time_span >= 0 do lifetime_absolute := utc_system_clock.date_time_now lifetime_absolute.add_milliseconds (a_time_span.as_integer_32) ensure Time_set: lifetime_absolute /= Void end set_lifetime_absolute (seconds_since_epoch: INTEGER) is -- Set absolute lifetime (`a_time' milli seconds since epoch) do create lifetime_absolute.make_from_epoch (seconds_since_epoch) ensure Time_set: lifetime_absolute /= Void end set_lifetime_from (other: P2P_ADVERTISEMENT) is -- Set absolute lifetime (`a_time' milli seconds since epoch) require Other_valid: other /= Void and other.lifetime_absolute /= Void do lifetime_absolute := other.lifetime_absolute.twin ensure Time_set: lifetime_absolute /= Void end feature -- Comparison describe_same_identity (other: like Current): BOOLEAN is -- Do `Current' and `other' describe the same identity? require Valid: is_valid Other_valid: other /= Void and other.is_valid do Result := unique_id.is_equal (other.unique_id) end feature {NONE} -- Implementation possible_expiration_time: like expiration_time -- Theoretical possible expiration time (`expiration_time' is restricted to life time) attribute_handler (a_root_attribute: XM_ATTRIBUTE) is -- Advertisements don't have any attributes in the root element do end initialize is -- Set creation time do Precursor creation_time := utc_system_clock.date_time_now end end