code: private static Endpoint selectByPartition(final List<Endpoint> endpoints, final short partition) {
          if (partition >= 0) {
              int numEndpoints = endpoints.size();
              Endpoint endpoint = numEndpoints == 1 ? endpoints.get(0) : endpoints.get(partition % numEndpoints);
              if (endpoint != null && endpoint.isState(LifecycleState.CONNECTED) && endpoint.isFree()) {
                  return endpoint;
              }
              return null;
          } else {
              return selectFirstConnected(endpoints);
          }
      }
docs: Helper method to select the proper target endpoint by partition.
  
  @param endpoints the list of currently available endpoints.
  @param partition the partition of the incoming request.
  @return the selected endpoint, or null if no acceptable one found.