Class RpcInvocationEndedEvent

All Implemented Interfaces:
Serializable

public class RpcInvocationEndedEvent extends AbstractRpcInvocationEvent
Event fired through the service event bus once a client-to-server RPC invocation has been handled, whether it completed normally or threw. It is fired on the same thread as the matching RpcInvocationStartedEvent.

The event tells how long the invocation took and whether it threw, so a listener that times invocations needs no state of its own and no listener for the started or failed event.

Since:
25.3
See Also:
  • Constructor Details

    • RpcInvocationEndedEvent

      public RpcInvocationEndedEvent(UI ui, String type, int nodeId, String name)
      Creates a new event for an invocation that completed normally and whose duration was not measured.

      The event reports a zero duration and no error. Use RpcInvocationEndedEvent(UI, String, int, String, Duration, Throwable) to create an event with a measured duration or an error.

      Parameters:
      ui - the UI the invocation is handled against, not null
      type - the protocol-level invocation type, not null
      nodeId - the id of the targeted StateNode, or -1 if the invocation does not target a node
      name - a human-readable identifier for the invocation, or null if none applies
    • RpcInvocationEndedEvent

      public RpcInvocationEndedEvent(UI ui, String type, int nodeId, String name, Duration duration, Throwable error)
      Creates a new event carrying the measured duration of the invocation and the throwable it raised, if any.
      Parameters:
      ui - the UI the invocation is handled against, not null
      type - the protocol-level invocation type, not null
      nodeId - the id of the targeted StateNode, or -1 if the invocation does not target a node
      name - a human-readable identifier for the invocation, or null if none applies
      duration - the time from just before the started event was fired until the invocation was handled, not null
      error - the throwable raised by the invocation handler, or null if it completed normally
  • Method Details

    • getDuration

      public Duration getDuration()
      Gets how long the invocation took, measured from just before the RpcInvocationStartedEvent was fired until the invocation was handled. It includes the time the listeners of the started and failed events took, but not the time spent on this event.
      Returns:
      the duration, never negative
    • getError

      public Optional<Throwable> getError()
      Gets the throwable raised by the invocation handler, which is the one the matching RpcInvocationFailedEvent carried. An empty optional means the invocation completed normally.
      Returns:
      the throwable, or an empty optional if the invocation did not throw