Class PendingCall
Объект связывает 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 -
Method Summary
Modifier and TypeMethodDescriptionvoidcompleteFail(String reason) Завершает вызов ошибкой и пробуждает ожидающий поток.voidcompleteFail(RpcException exception) Завершает вызов структурированной ошибкой и пробуждает ожидающий поток.voidcompleteOk(org.agrona.DirectBuffer src, int offset, int length) Записывает успешный результат и пробуждает ожидающий поток.longВозвращает correlation id связанного запроса.intВозвращает ожидаемый response message type id.failure()Возвращает исключение, сохраненное для вызова.Возвращает причину ошибочного завершения.booleanПроверяет, был ли вызов завершен.booleanisFailed()Проверяет, завершился ли вызов ошибкой.voidПодготавливает слот перед регистрацией в реестре ожидающих вызовов.voidПодготавливает слот перед регистрацией в реестре ожидающих вызовов.voidreset()Сбрасывает слот перед возвратом в пул.org.agrona.MutableDirectBufferВозвращает буфер с payload ответа.intВозвращает длину payload ответа.
-
Constructor Details
-
PendingCall
public PendingCall()Создает пустой slot ожидающего RPC-вызова.Creates an empty pending RPC call slot.
-
-
Method Details
-
prepare
Подготавливает слот перед регистрацией в реестре ожидающих вызовов.Prepares the slot before it is registered in the pending call registry.
- Parameters:
caller- поток, который ожидает ответ / thread waiting for the responsecorrelationId- идентификатор корреляции запроса / request correlation identifier
-
prepare
Подготавливает слот перед регистрацией в реестре ожидающих вызовов.Prepares the slot before it is registered in the pending call registry.
- Parameters:
caller- поток, который ожидает ответ / caller thread waiting for the responsecorrelationId- идентификатор корреляции запроса / request correlation identifierexpectedResponseTypeId- ожидаемый тип 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 payloadoffset- смещение payload в буфере-источнике / payload offset in the source bufferlength- длина payload в байтах / payload length in bytes
-
completeFail
Завершает вызов ошибкой и пробуждает ожидающий поток.Completes the call with a failure and unparks the waiting thread.
- Parameters:
reason- текстовая причина завершения / failure reason
-
completeFail
Завершает вызов структурированной ошибкой и пробуждает ожидающий поток.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, если вызов завершен /trueif the call is completed
-
isFailed
public boolean isFailed()Проверяет, завершился ли вызов ошибкой.Checks whether the call completed with a failure.
- Returns:
true, если вызов завершился ошибкой /trueif the call failed
-
failureReason
Возвращает причину ошибочного завершения.Returns the failure reason.
- Returns:
- причина ошибки или
null, если ошибки нет / failure reason ornullwhen there is no failure
-
failure
Возвращает исключение, сохраненное для вызова.Returns the failure exception captured for the call.
- Returns:
- исключение ошибки или
null, если ошибки нет / failure exception ornullwhen 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()returnstrue.- 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.
-