o
    `šj  ã                   @   sn   d dl Z d dlZd dlmZ d dlmZ d dlmZ G dd„ deƒZ	G dd„ deƒZ
e  d	g d
¢¡Zde_dS )é    N)Úerrors)ÚFuture)ÚTimerc                       sB   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡ fdd„Zdd	d
„Z‡  ZS )ÚFutureProduceResult)Útopic_partitionÚ_latchc                    s   t ƒ  ¡  || _t ¡ | _d S ©N)ÚsuperÚ__init__r   Ú	threadingÚEventr   )Úselfr   ©Ú	__class__© úS/home/djax/ivt_ai_plugin/venv/lib/python3.10/site-packages/kafka/producer/future.pyr
      s   
zFutureProduceResult.__init__c                    ó   t ƒ  |¡}| j ¡  |S r   )r	   Úsuccessr   Úset)r   ÚvalueÚretr   r   r   r      ó   
zFutureProduceResult.successc                    r   r   )r	   Úfailurer   r   )r   Úerrorr   r   r   r   r      r   zFutureProduceResult.failureNc                 C   s   | j  |¡p
| j  ¡ S r   )r   ÚwaitÚis_set)r   Útimeoutr   r   r   r      s   zFutureProduceResult.waitr   )	Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r
   r   r   r   Ú__classcell__r   r   r   r   r   	   s    r   c                       s>   e Zd ZdZdZ‡ fdd„Zdd„ Zdd„ Zdd
d„Z‡  Z	S )ÚFutureRecordMetadataaÊ  An asynchronous handle to the result of a single :meth:`~kafka.KafkaProducer.send`.

    :meth:`~kafka.KafkaProducer.send` returns one of these immediately,
    before the record has been transmitted to the broker. Call :meth:`get`
    to block until the record is acknowledged and obtain its
    :class:`RecordMetadata`, or register callbacks via
    :meth:`~kafka.future.Future.add_callback` /
    :meth:`~kafka.future.Future.add_errback` to be notified without
    blocking. The future resolves successfully once the containing batch is
    acknowledged according to the producer's ``acks`` configuration, or
    fails with the relevant exception (for example
    :class:`~kafka.errors.KafkaTimeoutError`).
    )Ú_produce_futureÚargsc                    s6   t ƒ  ¡  || _||||||f| _| | j| j¡ d S r   )r	   r
   r#   r$   Ú
_add_cb_ebÚ_produce_successr   )r   Úproduce_futureÚbatch_indexÚtimestamp_msÚchecksumÚserialized_key_sizeÚserialized_value_sizeÚserialized_header_sizer   r   r   r
   /   s   
zFutureRecordMetadata.__init__c              
   C   s˜   |\}}}| j \}}}}}	}
|d ur|  ||ƒ¡ d S |d ur%|dkr%|}|dkr1|d ur1||7 }| jj}t|d |d ||||||	|
ƒ	}|  |¡ d S )Néÿÿÿÿr   é   )r$   r   r#   r   ÚRecordMetadatar   )r   ÚresultÚoffsetÚproduce_timestamp_msÚrecord_exceptions_fnr(   r)   r*   r+   r,   r-   ÚtpÚmetadatar   r   r   r&   6   s    
ÿþz%FutureRecordMetadata._produce_successc           
      C   sN   | j }|| _ | j\}}}}}}	||||||	f| _| | j| j¡ |j ¡  dS )aÎ  Rebind this future to a new produce future with a new batch index.

        Used when a batch is split due to MESSAGE_TOO_LARGE. The original
        FutureRecordMetadata is rebound to the new (smaller) batch's future.

        This must be called from the sender thread while the old produce_future
        has not been completed. Any user thread blocked in get() on the old
        produce_future's latch will be woken and will re-wait on the new one.
        N)r#   r$   r%   r&   r   r   r   )
r   Únew_produce_futureÚnew_batch_indexÚold_produce_futureÚ_r)   r*   ÚskÚsvÚshr   r   r   ÚrebindL   s   
zFutureRecordMetadata.rebindNc                 C   sb   t |dur	|d ndƒ}| js'|js'| j |j¡s!t d|f ¡‚| js'|jr|  ¡ r.| j	‚| j
S )z6Wait for up to timeout seconds for future to complete.Niè  z"Timeout after waiting for %s secs.)r   Úis_doneÚexpiredr#   r   Útimeout_secsÚErrorsÚKafkaTimeoutErrorÚfailedÚ	exceptionr   )r   r   Útimerr   r   r   Úget`   s   ÿþzFutureRecordMetadata.getr   )
r   r   r   Ú__doc__r    r
   r&   r>   rG   r!   r   r   r   r   r"       s    r"   r0   )	ÚtopicÚ	partitionr   r2   Ú	timestampr*   r+   r,   r-   a4  Metadata about a record that has been acknowledged by the broker.

Returned by :meth:`FutureRecordMetadata.get`, which resolves once the
batch containing the record has been acknowledged according to the
producer's ``acks`` configuration.

Keyword Arguments:
    topic (str): The topic the record was appended to.
    partition (int): The partition the record was appended to.
    topic_partition (TopicPartition): The ``(topic, partition)`` the record
        was appended to.
    offset (int): The offset of the record in the topic partition, or -1 if
        the broker did not assign one (e.g. ``acks=0``).
    timestamp (int): The timestamp of the record, in milliseconds since the
        epoch (UTC). For CreateTime this is the producer-supplied timestamp;
        for LogAppendTime it is the broker-assigned timestamp.
    checksum (int): Deprecated. The CRC32 checksum of the record, or None.
        Removed in message format v2 (Kafka 0.11+).
    serialized_key_size (int): The size of the serialized, uncompressed key
        in bytes, or -1 if the key is None.
    serialized_value_size (int): The size of the serialized, uncompressed
        value in bytes, or -1 if the value is None.
    serialized_header_size (int): The size of the serialized, uncompressed
        headers in bytes, or -1 if there are no headers.
)Úcollectionsr   Úkafkar   rB   Úkafka.futurer   Ú
kafka.utilr   r   r"   Ú
namedtupler0   rH   r   r   r   r   Ú<module>   s    Pÿ
