
    &`i                         d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	 d dl
mZ d dlmZmZ d dlmZ dZ e j        e          Z G d	 d
          ZdS )    N)AnyDictOptional)cloudpickle)DeploymentIDEndpointInfo)SERVE_LOGGER_NAME)LongPollHostLongPollNamespace)KVStoreBasezserve-endpoint-state-checkpointc                       e Zd ZdZdedefdZd ZdefdZ	d Z
d	 Zd
edee         fdZdededdfdZdedee         fdZdeeeeef         f         fdZdeddfdZdS )EndpointStatezManages all state for endpoints in the system.

    This class is *not* thread safe, so any state-modifying methods should be
    called with a lock held.
    kv_storelong_poll_hostc                     || _         || _        t                      | _        | j                             t
                    }|t          j        |          | _        |                                  d S N)		_kv_store_long_poll_hostdict
_endpointsgetCHECKPOINT_KEYr   loads_notify_route_table_changed)selfr   r   
checkpoints       u/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/serve/_private/endpoint_state.py__init__zEndpointState.__init__   sa    !-<@FF^''77
!)/
;;DO((*****    c                 D    | j                             t                     d S r   )r   deleter   r   s    r   shutdownzEndpointState.shutdown!   s    n-----r   returnc                 D    | j                             t                    du S )zReturns whether the endpoint checkpoint has been deleted.

        Get the endpoint checkpoint from the kv store. If it is None, then it has been
        deleted.
        N)r   r   r   r"   s    r   is_ready_for_shutdownz#EndpointState.is_ready_for_shutdown$   s     ~!!.11T99r   c                 t    | j                             t          t          j        | j                             d S r   )r   putr   r   dumpsr   r"   s    r   _checkpointzEndpointState._checkpoint,   s-    >;+<T_+M+MNNNNNr   c                 \    | j                             t          j        | j        i           d S r   )r   notify_changedr   ROUTE_TABLEr   r"   s    r   r   z)EndpointState._notify_route_table_changed/   s4    ++*DO<	
 	
 	
 	
 	
r   routec                 b    | j                                         D ]\  }}|j        |k    r|c S d S r   r   itemsr.   )r   r.   endpointinfos       r   _get_endpoint_for_routez%EndpointState._get_endpoint_for_route4   sE    "o3355 	  	 NHdzU"" # tr   r2   endpoint_infoNc                 t   | j                             |          |k    rdS |                     |j                  }|I||k    rCt                              d|j         d|j         d|j         d|j         d	           | j         |= || j         |<   |                                  |                                  dS )zCreate or update the given endpoint.

        This method is idempotent - if the endpoint already exists it will be
        updated to match the given parameters. Calling this twice with the same
        arguments is a no-op.
        Nzroute_prefix "z)" is currently registered to deployment "z ". Re-registering route_prefix "z" to deployment "z".)	r   r   r4   r.   loggerdebugnamer*   r   )r   r2   r5   existing_route_endpoints       r   update_endpointzEndpointState.update_endpoint;   s     ?x((M99F"&">">}?R"S"S".3Jh3V3VLL1!4 1 1-D-I1 10=0C1 1  (}1 1 1    78$1!((*****r   c                 <    || j         v r| j         |         j        S d S r   )r   r.   r   r2   s     r   get_endpoint_routez EndpointState.get_endpoint_routeW   s$    t&&?8,22tr   c                 `    i }| j                                         D ]\  }}d|j        i||<   |S )Nr.   r0   )r   	endpointsr2   r3   s       r   get_endpointszEndpointState.get_endpoints\   sF    	"o3355 	 	NHd#Ih r   c                 |    || j         vrd S | j         |= |                                  |                                  d S r   )r   r*   r   r=   s     r   delete_endpointzEndpointState.delete_endpointd   sJ     4?**FOH%((*****r   )__name__
__module____qualname____doc__r   r
   r   r#   boolr&   r*   r   strr   r   r4   r   r;   r>   r   r   rA   rC    r   r   r   r      sS        	+ 	+l 	+ 	+ 	+ 	+. . .:t : : : :O O O
 
 

S Xl5K    +$+5A+	+ + + +8< HSM    
tL$sCx.$@A    	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+r   r   )loggingtypingr   r   r   rayr   ray.serve._private.commonr   r   ray.serve._private.constantsr	   ray.serve._private.long_pollr
   r   #ray.serve._private.storage.kv_storer   r   	getLoggerr7   r   rJ   r   r   <module>rS      s     & & & & & & & & & &       @ @ @ @ @ @ @ @ : : : : : : H H H H H H H H ; ; ; ; ; ;2		,	-	-^+ ^+ ^+ ^+ ^+ ^+ ^+ ^+ ^+ ^+r   