Class RpcResultBuilder<T>

java.lang.Object
org.opendaylight.yangtools.yang.common.RpcResultBuilder<T>
Type Parameters:
T - the result value type
All Implemented Interfaces:
Mutable

public final class RpcResultBuilder<T> extends Object implements Mutable
A builder for creating RpcResult instances.
Author:
Thomas Pantelis
  • Method Details

    • success

      public static <T> @NonNull RpcResultBuilder<T> success()
      Returns a builder for a successful result.
    • success

      public static <T> @NonNull RpcResultBuilder<T> success(T result)
      Returns a builder for a successful result.
      Parameters:
      result - the result value
    • failed

      public static <T> @NonNull RpcResultBuilder<T> failed()
      Returns a builder for a failed result.
    • status

      public static <T> @NonNull RpcResultBuilder<T> status(boolean success)
      Returns a builder based on the given status.
      Parameters:
      success - true if successful, false otherwise.
    • from

      public static <T> @NonNull RpcResultBuilder<T> from(RpcResult<T> other)
      Returns a builder from another RpcResult.
      Parameters:
      other - the other RpcResult.
    • newError

      public static @NonNull RpcError newError(ErrorType errorType, ErrorTag tag, String message)
      Creates an RpcError with severity ERROR for reuse.
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      tag - a short string that identifies the general type of error condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the error condition.
      Returns:
      an RpcError
    • newError

      public static @NonNull RpcError newError(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause)
      Creates an RpcError with severity ERROR for reuse.
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      tag - a short string that identifies the general type of error condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the error condition.
      applicationTag - a short string that identifies the specific type of error condition.
      info - a string containing additional information to provide extended and/or implementation-specific debugging information.
      cause - the exception that triggered the error.
      Returns:
      an RpcError
    • newWarning

      public static @NonNull RpcError newWarning(ErrorType errorType, ErrorTag tag, String message)
      Creates an RpcError with severity WARNING for reuse.
      Parameters:
      errorType - the conceptual layer at which the warning occurred.
      tag - a short string that identifies the general type of warning condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the warning condition.
      Returns:
      an RpcError
    • newWarning

      public static @NonNull RpcError newWarning(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause)
      Creates an RpcError with severity WARNING for reuse.
      Parameters:
      errorType - the conceptual layer at which the warning occurred.
      tag - a short string that identifies the general type of warning condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the warning condition.
      applicationTag - a short string that identifies the specific type of warning condition.
      info - a string containing additional information to provide extended and/or implementation-specific debugging information.
      cause - the exception that triggered the warning.
      Returns:
      an RpcError
    • withResult

      public @NonNull RpcResultBuilder<T> withResult(T result)
      Sets the value of the result.
      Parameters:
      result - the result value
    • withWarning

      public @NonNull RpcResultBuilder<T> withWarning(ErrorType errorType, ErrorTag tag, String message)
      Adds a warning to the result.
      Parameters:
      errorType - the conceptual layer at which the warning occurred.
      tag - a short string that identifies the general type of warning condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the warning condition.
    • withWarning

      public @NonNull RpcResultBuilder<T> withWarning(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause)
      Adds a warning to the result.
      Parameters:
      errorType - the conceptual layer at which the warning occurred.
      tag - a short string that identifies the general type of warning condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the warning condition.
      applicationTag - a short string that identifies the specific type of warning condition.
      info - a string containing additional information to provide extended and/or implementation-specific debugging information.
      cause - the exception that triggered the warning.
    • withError

      public @NonNull RpcResultBuilder<T> withError(ErrorType errorType, String message)
      Adds an error to the result. The general error tag defaults to "operation-failed".
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      message - a string suitable for human display that describes the error condition.
    • withError

      public @NonNull RpcResultBuilder<T> withError(ErrorType errorType, ErrorTag tag, String message)
      Adds an error to the result.
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      tag - a short string that identifies the general type of error condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the error condition.
    • withError

      public @NonNull RpcResultBuilder<T> withError(ErrorType errorType, String message, Throwable cause)
      Adds an error to the result. The general error tag defaults to "operation-failed".
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      message - a string suitable for human display that describes the error condition.
      cause - the exception that triggered the error.
    • withError

      public @NonNull RpcResultBuilder<T> withError(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause)
      Adds an error to the result.
      Parameters:
      errorType - the conceptual layer at which the error occurred.
      tag - a short string that identifies the general type of error condition. See RpcError.getTag() for a list of suggested values.
      message - a string suitable for human display that describes the error condition.
      applicationTag - a short string that identifies the specific type of error condition.
      info - a string containing additional information to provide extended and/or implementation-specific debugging information.
      cause - the exception that triggered the error.
    • withRpcError

      public @NonNull RpcResultBuilder<T> withRpcError(RpcError error)
      Adds an RpcError.
      Parameters:
      error - the RpcError
    • withRpcErrors

      public RpcResultBuilder<T> withRpcErrors(Collection<? extends RpcError> rpcErrors)
      Adds RpcErrors.
      Parameters:
      rpcErrors - the list of RpcErrors
    • build

      public @NonNull RpcResult<T> build()
      Build the resulting RpcResult.
      Returns:
      An RpcResult instance
    • buildFuture

      public @NonNull FluentFuture<RpcResult<T>> buildFuture()
      Builds RpcResult and wraps it in a Future.

      This is a convenience method to assist those writing RPCs that produce immediate results. It allows you to replace FluentFuture.from(Futures.immediateFuture(rpcResult.build())) with rpcResult.buildFuture()

      Returns:
      Future for RpcResult built by RpcResultBuilder