class_docstr: Router that performs longest prefix matches on incoming routes.
class_docstr_tok: ["Router","that","performs","longest","prefix","matches","on","incoming","routes","."]
code: def update_routes(
      self, endpoints: Dict[EndpointTag, EndpointInfo]
  ) -> None:
      logger.info(
          f"Got updated endpoints: {endpoints}.",
          extra={"log_to_stderr": False},
      )
  
      existing_handles = set(self.handles.keys())
      routes = []
      route_info = {}
      app_to_is_cross_language = {}
      for endpoint, info in endpoints.items():
          routes.append(info.route)
          route_info[info.route] = endpoint
          app_to_is_cross_language[
              endpoint.app
          ] = info.app_is_cross_language
          if endpoint in self.handles:
              existing_handles.remove(endpoint)
          else:
              handle = self._get_handle(
                  endpoint.name, endpoint.app
              ).options(
                  # Streaming codepath isn't supported for Java.
                  stream=not info.app_is_cross_language,
                  use_new_handle_api=True,
                  _prefer_local_routing=RAY_SERVE_PROXY_PREFER_LOCAL_NODE_ROUTING,
              )
              handle._set_request_protocol(self._protocol)
              self.handles[endpoint] = handle
  
      # Clean up any handles that are no longer used.
      if len(existing_handles) > 0:
          logger.info(
              f"Deleting {len(existing_handles)} unused handles.",
              extra={"log_to_stderr": False},
          )
      for endpoint in existing_handles:
          del self.handles[endpoint]
  
      # Routes are sorted in order of decreasing length to enable longest
      # prefix matching.
      self.sorted_routes = sorted(
          routes, key=lambda x: len(x), reverse=True
      )
      self.route_info = route_info
      self.app_to_is_cross_language = app_to_is_cross_language
  
file_path: ray/python/ray/serve/_private/proxy_router.py
imports: import logging
  from abc import ABC, abstractmethod
  from typing import Callable, Dict, List, Optional, Tuple
  from ray.serve._private.common import ApplicationName, EndpointInfo, EndpointTag, RequestProtocol
  from ray.serve._private.constants import RAY_SERVE_PROXY_PREFER_LOCAL_NODE_ROUTING, SERVE_LOGGER_NAME
  from ray.serve.handle import RayServeHandle
label_desc: Use image node_id 2 for calling the LongestPrefixRouter obj's underlying member method code with example usage: obj.update_routes(endpoints) without return types