Class RpcResultBuilder<T>
java.lang.Object
org.opendaylight.yangtools.yang.common.RpcResultBuilder<T>
- Type Parameters:
T
- the result value type
- All Implemented Interfaces:
Mutable
A builder for creating RpcResult instances.
- Author:
- Thomas Pantelis
-
Method Summary
Modifier and TypeMethodDescriptionbuild()
Build the resultingRpcResult
.@NonNull FluentFuture<RpcResult<T>>
Builds RpcResult and wraps it in a Future.static <T> @NonNull RpcResultBuilder<T>
failed()
Returns a builder for a failed result.static <T> @NonNull RpcResultBuilder<T>
Returns a builder from another RpcResult.static @NonNull RpcError
Creates an RpcError with severity ERROR for reuse.static @NonNull RpcError
newError
(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause) Creates an RpcError with severity ERROR for reuse.static @NonNull RpcError
newWarning
(ErrorType errorType, ErrorTag tag, String message) Creates an RpcError with severity WARNING for reuse.static @NonNull RpcError
newWarning
(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause) Creates an RpcError with severity WARNING for reuse.static <T> @NonNull RpcResultBuilder<T>
status
(boolean success) Returns a builder based on the given status.static <T> @NonNull RpcResultBuilder<T>
success()
Returns a builder for a successful result.static <T> @NonNull RpcResultBuilder<T>
success
(T result) Returns a builder for a successful result.@NonNull RpcResultBuilder<T>
Adds an error to the result.@NonNull RpcResultBuilder<T>
Adds an error to the result.@NonNull RpcResultBuilder<T>
Adds an error to the result.@NonNull RpcResultBuilder<T>
withError
(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause) Adds an error to the result.@NonNull RpcResultBuilder<T>
withResult
(T result) Sets the value of the result.@NonNull RpcResultBuilder<T>
withRpcError
(RpcError error) Adds an RpcError.withRpcErrors
(Collection<? extends RpcError> rpcErrors) Adds RpcErrors.@NonNull RpcResultBuilder<T>
withWarning
(ErrorType errorType, ErrorTag tag, String message) Adds a warning to the result.@NonNull RpcResultBuilder<T>
withWarning
(ErrorType errorType, ErrorTag tag, String message, String applicationTag, String info, Throwable cause) Adds a warning to the result.
-
Method Details
-
success
Returns a builder for a successful result. -
success
Returns a builder for a successful result.- Parameters:
result
- the result value
-
failed
Returns a builder for a failed result. -
status
Returns a builder based on the given status.- Parameters:
success
- true if successful, false otherwise.
-
from
Returns a builder from another RpcResult.- Parameters:
other
- the other RpcResult.
-
newError
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. SeeRpcError.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. SeeRpcError.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
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. SeeRpcError.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. SeeRpcError.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
Sets the value of the result.- Parameters:
result
- the result value
-
withWarning
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. SeeRpcError.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. SeeRpcError.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
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
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. SeeRpcError.getTag()
for a list of suggested values.message
- a string suitable for human display that describes the error condition.
-
withError
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. SeeRpcError.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
Adds an RpcError.- Parameters:
error
- the RpcError
-
withRpcErrors
Adds RpcErrors.- Parameters:
rpcErrors
- the list of RpcErrors
-
build
Build the resultingRpcResult
.- Returns:
- An RpcResult instance
-
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()))
withrpcResult.buildFuture()
- Returns:
- Future for RpcResult built by RpcResultBuilder
-