public class ServiceCall<T> extends Object
Call implementation that wraps original Retrofit call to provide functionality that
supports association of ServiceCallback with the related service along with service request.
Each instance of service call need to be created with the original call via #ServiceCall(Call)
constructor along with id of the corresponding service via withServiceId(int). The provided
service id is than attached to the callback when enqueue(ServiceCallback) is called
along with the request id which this method returns. Subclasses may implement requestId()
to generate custom unique id for a specific request. In such case, do not forget to properly override
also clone() method.
| Constructor and Description |
|---|
ServiceCall(<any> call)
Creates a new instance of ServiceCall with the given original Retrofit call.
|
| Modifier and Type | Method and Description |
|---|---|
void |
cancel() |
<any> |
clone()
Creates a new clone of this service call with the original Retrofit call also cloned
and with the same service id as specified via
withServiceId(int) (if any). |
void |
enqueue(<any> callback) |
String |
enqueue(ServiceCallback<T> callback)
Like
#enqueue(Callback), but this method also obtains and returns unique id of this
asynchronous request so it may be later identified through the associated service objects:
ServiceCallback which results to either ServiceResponse or ServiceError. |
<any> |
execute() |
boolean |
isCanceled() |
boolean |
isExecuted() |
Request |
request() |
protected String |
requestId()
Called to obtain a unique id for the current service request that has been requested to be
executed asynchronously via
enqueue(ServiceCallback). |
ServiceCall<T> |
withServiceId(int serviceId)
Specifies id of the service to be this call associated with.
|
public ServiceCall(@NonNull <any> call)
call - The Retrofit call to which will be this service call delegating its methods.public ServiceCall<T> withServiceId(int serviceId)
ServiceCallback when enqueue(ServiceCallback) is called
and the callback does not have service id attached yet.serviceId - Id of the desired service to be this call associated with.UnsupportedOperationException - If service id for this call has been already specified.public <any> execute()
throws IOException
IOException@NonNull public String enqueue(@NonNull ServiceCallback<T> callback)
#enqueue(Callback), but this method also obtains and returns unique id of this
asynchronous request so it may be later identified through the associated service objects:
ServiceCallback which results to either ServiceResponse or ServiceError.
Also id of the service specified for this service call will be attached to the callback if it has no service id attached yet.
callback - The desired callback that should be notified when service requests is finished.ServiceObject.getServiceId(),
ServiceObject.getRequestId()@NonNull protected String requestId()
enqueue(ServiceCallback).
This implementation returns a string representation of the current time in milliseconds as
Long.toString(System.currentTimeMillis()).
public void enqueue(<any> callback)
public boolean isExecuted()
public void cancel()
public boolean isCanceled()
public Request request()
public <any> clone()
withServiceId(int) (if any).