Class PendingCall

java.lang.Object
ru.pathcreator.pyc.rpc.core.internal.PendingCall

public final class PendingCall extends Object
Слот состояния для одного ожидающего синхронного RPC-вызова.

Объект связывает caller thread, correlation id и результат ожидания: успешный response payload либо структурированную ошибку. Response payload копируется во внутренний direct buffer, который переиспользуется между вызовами и увеличивается только при необходимости.

State slot for one pending synchronous RPC call. It stores the caller thread, correlation identifier, and completion result: either a successful response payload or a structured failure.

Модель памяти / Memory model: данные результата записываются до volatile флага completed; ожидающий поток сначала читает completed, а затем безопасно читает остальные поля результата.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Создает пустой slot ожидающего RPC-вызова.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Завершает вызов ошибкой и пробуждает ожидающий поток.
    void
    Завершает вызов структурированной ошибкой и пробуждает ожидающий поток.
    void
    completeOk(org.agrona.DirectBuffer src, int offset, int length)
    Записывает успешный результат и пробуждает ожидающий поток.
    long
    Возвращает correlation id связанного запроса.
    int
    Возвращает ожидаемый response message type id.
    Возвращает исключение, сохраненное для вызова.
    Возвращает причину ошибочного завершения.
    boolean
    Проверяет, был ли вызов завершен.
    boolean
    Проверяет, завершился ли вызов ошибкой.
    void
    prepare(Thread caller, long correlationId)
    Подготавливает слот перед регистрацией в реестре ожидающих вызовов.
    void
    prepare(Thread caller, long correlationId, int expectedResponseTypeId)
    Подготавливает слот перед регистрацией в реестре ожидающих вызовов.
    void
    Сбрасывает слот перед возвратом в пул.
    org.agrona.MutableDirectBuffer
    Возвращает буфер с payload ответа.
    int
    Возвращает длину payload ответа.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • PendingCall

      public PendingCall()
      Создает пустой slot ожидающего RPC-вызова.

      Creates an empty pending RPC call slot.

  • Method Details

    • prepare

      public void prepare(Thread caller, long correlationId)
      Подготавливает слот перед регистрацией в реестре ожидающих вызовов.

      Prepares the slot before it is registered in the pending call registry.

      Parameters:
      caller - поток, который ожидает ответ / thread waiting for the response
      correlationId - идентификатор корреляции запроса / request correlation identifier
    • prepare

      public void prepare(Thread caller, long correlationId, int expectedResponseTypeId)
      Подготавливает слот перед регистрацией в реестре ожидающих вызовов.

      Prepares the slot before it is registered in the pending call registry.

      Parameters:
      caller - поток, который ожидает ответ / caller thread waiting for the response
      correlationId - идентификатор корреляции запроса / request correlation identifier
      expectedResponseTypeId - ожидаемый тип response message / expected response message type identifier
    • completeOk

      public void completeOk(org.agrona.DirectBuffer src, int offset, int length)
      Записывает успешный результат и пробуждает ожидающий поток.

      Payload ответа копируется во внутренний буфер, который при необходимости увеличивается. Обычно метод вызывается из receive path.

      Stores a successful result and unparks the waiting thread. The response payload is copied into the internal buffer, which grows when needed. The method is typically called from the receive path.

      Parameters:
      src - буфер-источник с payload ответа / source buffer containing the response payload
      offset - смещение payload в буфере-источнике / payload offset in the source buffer
      length - длина payload в байтах / payload length in bytes
    • completeFail

      public void completeFail(String reason)
      Завершает вызов ошибкой и пробуждает ожидающий поток.

      Completes the call with a failure and unparks the waiting thread.

      Parameters:
      reason - текстовая причина завершения / failure reason
    • completeFail

      public void completeFail(RpcException exception)
      Завершает вызов структурированной ошибкой и пробуждает ожидающий поток.

      Completes the call with a structured exception and unparks the waiting thread.

      Parameters:
      exception - ошибка для передачи caller-у / failure to propagate to the caller
    • isCompleted

      public boolean isCompleted()
      Проверяет, был ли вызов завершен.

      Checks whether the call has completed.

      Returns:
      true, если вызов завершен / true if the call is completed
    • isFailed

      public boolean isFailed()
      Проверяет, завершился ли вызов ошибкой.

      Checks whether the call completed with a failure.

      Returns:
      true, если вызов завершился ошибкой / true if the call failed
    • failureReason

      public String failureReason()
      Возвращает причину ошибочного завершения.

      Returns the failure reason.

      Returns:
      причина ошибки или null, если ошибки нет / failure reason or null when there is no failure
    • failure

      public RpcException failure()
      Возвращает исключение, сохраненное для вызова.

      Returns the failure exception captured for the call.

      Returns:
      исключение ошибки или null, если ошибки нет / failure exception or null when there is no failure
    • correlationId

      public long correlationId()
      Возвращает correlation id связанного запроса.

      Returns the correlation identifier of the associated request.

      Returns:
      идентификатор корреляции / correlation identifier
    • expectedResponseTypeId

      public int expectedResponseTypeId()
      Возвращает ожидаемый response message type id.

      Returns the expected response message type identifier.

      Returns:
      ожидаемый идентификатор типа ответа / expected response message type identifier
    • responseBuffer

      public org.agrona.MutableDirectBuffer responseBuffer()
      Возвращает буфер с payload ответа.

      Caller должен читать этот буфер только после того, как isCompleted() вернул true.

      Returns the response payload buffer. The caller should read it only after isCompleted() returns true.

      Returns:
      буфер с payload ответа / response payload buffer
    • responseLength

      public int responseLength()
      Возвращает длину payload ответа.

      Returns the response payload length.

      Returns:
      длина payload ответа в байтах / response payload length in bytes
    • reset

      public void reset()
      Сбрасывает слот перед возвратом в пул.

      Resets the slot before returning it to the pool.