Class RpcResultBuilder<T>

    • Method Detail

      • 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
      • success

        public static <T> @NonNull RpcResultBuilder<T> success​(Builder<T> builder)
        Returns a builder for a successful result.
        Parameters:
        builder - builder for 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​(RpcError.ErrorType errorType,
                                                 String 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​(RpcError.ErrorType errorType,
                                                 String 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​(RpcError.ErrorType errorType,
                                                   String 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​(RpcError.ErrorType errorType,
                                                   String 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
      • withResult

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

        public @NonNull RpcResultBuilder<T> withWarning​(RpcError.ErrorType errorType,
                                                        String 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​(RpcError.ErrorType errorType,
                                                        String 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​(RpcError.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​(RpcError.ErrorType errorType,
                                                      String 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​(RpcError.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​(RpcError.ErrorType errorType,
                                                      String 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
      • 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