I - Input typeO - Output typepublic abstract class RxUseCase<I,O>
extends java.lang.Object
RxUseCase has a standard interface of passing and getting data. It: - operates with the Request parameter, which wraps the input required by the use-case - emits a Response object which encapsulates either a successful output or the failure returned by the use-case This enables another way of describing use-cases as entities which act as a standard input - standard output proxies to the outside world.
| Constructor and Description |
|---|
RxUseCase() |
| Modifier and Type | Method and Description |
|---|---|
static void |
addDecorator(UseCaseDecorator decorator)
Add a global decorator for use-cases.
|
io.reactivex.Observable<Response<O>> |
create()
Create use-case observable without passing any input.
|
io.reactivex.Observable<Response<O>> |
create(I input)
Create use-case observable with input.
|
io.reactivex.Observable<Response<O>> |
create(Request<I> request)
Create use-case observable passing a
Request parameter. |
<T extends RxUseCase<I,O>> |
decorateWith(java.util.Collection<UseCaseDecorator> decorators)
Decorate this use-case with a list of
UseCaseDecorator implementations. |
<T extends RxUseCase<I,O>> |
decorateWith(UseCaseDecorator decorator)
Add a
UseCaseDecorator to the list of items decorating this use-case. |
<T extends RxUseCase<I,O>> |
decorateWithNothing()
Remove all the decorators previously set for this use-case including
the global ones.
|
protected abstract io.reactivex.Observable<Response<O>> |
execute(I input)
Create use-case observable with input.
|
static <I,O> RxUseCase<I,O> |
fromAsynchronous(Asynchronous<I,O> operation)
Create a use-case from a
Asynchronous operation. |
static <I,O> RxUseCase<I,O> |
fromContinuous(Continuous<I,O> operation)
Create a use-case from a
Continuous operation. |
static <I,O> RxUseCase<I,O> |
fromSource(RxSource<I,O> source)
Create a use-case from an implementation of
RxSource. |
static <I,O> RxUseCase<I,O> |
fromSynchronous(Synchronous<I,O> operation)
Create a use-case from a
Synchronous operation. |
Response<O> |
get()
Get use-case response.
|
Response<O> |
get(I input)
Get use-case response for the input.
|
Response<O> |
get(Request<I> request)
Get use-case response passing a
Request parameter. |
protected io.reactivex.Observable<Response<O>> |
justFail(java.lang.String code,
java.lang.String message)
Emit the passed code and message wrapped into a
Response. |
protected io.reactivex.Observable<Response<O>> |
justSucceed(O output)
Emit the passed object wrapped into a
Response. |
<T extends RxUseCase<I,O>> |
origin(java.lang.String origin)
Set the originator of the use-case
|
static void |
removeDecorator(UseCaseDecorator decorator)
Remove a global decorator of use-cases.
|
protected static <O> io.reactivex.Observable<Response<O>> |
safeCreate(io.reactivex.ObservableOnSubscribe<Response<O>> subscriber)
Create an
Observable using a SafeEmitter. |
protected static <I,O> io.reactivex.Observable<Response<O>> |
toRx(Asynchronous<I,O> operation,
I input)
Transform an
Asynchronous operation into an Observable. |
protected static <I,O> io.reactivex.Observable<Response<O>> |
toRx(Continuous<I,O> operation,
I input)
Transform a
Continuous operation into an Observable. |
protected static <I,O> io.reactivex.Observable<Response<O>> |
toRx(Synchronous<I,O> operation,
I input)
Transform a
Synchronous operation into an Observable. |
public final io.reactivex.Observable<Response<O>> create()
create(Object) passing null as input.
The sole purpose of this method is to simplify the use-case usage
when no input is required by the use-case.public final io.reactivex.Observable<Response<O>> create(I input)
Request object
and passed to the create(Request) method.input - Use-case inputpublic final io.reactivex.Observable<Response<O>> create(Request<I> request)
Request parameter.
This method is the entry point to the logic/mechanism/action
that this use-case represents.
Typically the subscription to the returned Observable
will trigger the execution of the use-case.request - Use-case requestpublic final Response<O> get()
get(Object) passing null as input.
The sole purpose of this method is to simplify the use-case usage
when no input is required by the use-case.public final Response<O> get(I input)
Request object
and passed to the get(Request) method.input - Use-case inputpublic final Response<O> get(Request<I> request)
Request parameter.
This method is pointing to the entry point to the logic/mechanism/action
that this use-case represents.
It is useful in situations when the response of the use-case
is required to be retrieved in a blocking manner.
The method will block until the first item is emitted by create(Request),
return it. See Observable.blockingFirst() for reference.request - Use-case requestprotected abstract io.reactivex.Observable<Response<O>> execute(I input)
create(), create(Object), create(Request) methods.
Implement it to define the logic/mechanism/action that this use-case represents.input - Use-case inputprotected io.reactivex.Observable<Response<O>> justSucceed(O output)
Response.
Utility method that builds and returns an Observable
that emits a successful Response wrapping the output.output - Use-case outputprotected io.reactivex.Observable<Response<O>> justFail(java.lang.String code, java.lang.String message)
Response.
Utility method that builds and returns an Observable
that emits a failure Response wrapping the passed
error code and error messagecode - Error codemessage - Error messagepublic final <T extends RxUseCase<I,O>> T origin(java.lang.String origin)
T - Type of this use-caseorigin - Originatorpublic final <T extends RxUseCase<I,O>> T decorateWith(java.util.Collection<UseCaseDecorator> decorators)
UseCaseDecorator implementations.
Effectively, the use-case observable returned from execute(Object) method
will be decorated in a chain manner with items in this list.
The order of elements in the passed list is important because the decorators
may decide to pre and post-process streams, for ex. by filtering out the emission
of certain elements.
NOTE: Invoking this method will disable the global decorators for this instance
of this use-case.
See UseCaseDecorator for reference
T - Type of this use-casedecorators - List of decoratorspublic final <T extends RxUseCase<I,O>> T decorateWith(UseCaseDecorator decorator)
UseCaseDecorator to the list of items decorating this use-case.
NOTE: Invoking this method will disable the global decorators for this instance
of this use-case.
Please see decorateWith(Collection) and UseCaseDecorator
for referenceT - Type of this use-casedecorator - Decorator of use-casepublic final <T extends RxUseCase<I,O>> T decorateWithNothing()
T - Type of this use-casepublic static void addDecorator(UseCaseDecorator decorator)
execute(Object) method
will be decorated by this item, unless they define local UseCaseDecorator
or clear the decoration mechanism, see decorateWith(Collection),
decorateWith(UseCaseDecorator) and decorateWithNothing() for this.decorator - Global decoratorpublic static void removeDecorator(UseCaseDecorator decorator)
decorator - Global decoratorpublic static <I,O> RxUseCase<I,O> fromSynchronous(Synchronous<I,O> operation)
Synchronous operation.
This method will wrap the logic / action / mechanism defined
in the operation into an instance of RxUseCase.
See Synchronous for reference.
I - Input typeO - Output typeoperation - Use-case operationpublic static <I,O> RxUseCase<I,O> fromAsynchronous(Asynchronous<I,O> operation)
Asynchronous operation.
This method will wrap the logic / action / mechanism defined
in the operation into an instance of RxUseCase.
See Asynchronous for reference.
I - Input typeO - Output typeoperation - Use-case operationpublic static <I,O> RxUseCase<I,O> fromContinuous(Continuous<I,O> operation)
Continuous operation.
This method will wrap the logic / action / mechanism defined
in the operation into an instance of RxUseCase.
See Continuous for reference.
I - Input typeO - Output typeoperation - Use-case operationpublic static <I,O> RxUseCase<I,O> fromSource(RxSource<I,O> source)
RxSource.
This method will wrap the logic / action / mechanism defined
in the source into an instance of RxUseCase.
It is useful for situations when extending RxUseCase class
is not an option, and the other operations are not suitable.
See RxSource for reference.
I - Input typeO - Output typesource - Observable sourceprotected static <I,O> io.reactivex.Observable<Response<O>> toRx(Synchronous<I,O> operation, I input)
Synchronous operation into an Observable.I - Input typeO - Output typeoperation - Use-case operationinput - Operation inputprotected static <I,O> io.reactivex.Observable<Response<O>> toRx(Asynchronous<I,O> operation, I input)
Asynchronous operation into an Observable.I - Input typeO - Output typeoperation - Use-case operationinput - Operation inputprotected static <I,O> io.reactivex.Observable<Response<O>> toRx(Continuous<I,O> operation, I input)
Continuous operation into an Observable.I - Input typeO - Output typeoperation - Use-case operationinput - Operation inputprotected static <O> io.reactivex.Observable<Response<O>> safeCreate(io.reactivex.ObservableOnSubscribe<Response<O>> subscriber)
Observable using a SafeEmitter.
This will allow invocations of Emitter.onNext(Object),
Emitter.onNext(Object) and Emitter.onNext(Object)
without first verifying the ObservableEmitter.isDisposed() status.
See SafeEmitter for reference.
O - Output typesubscriber - OnSubscribe hook