A - Type of the API provided by the ServiceApiProvider implementation.public abstract class ServiceApiProvider<A> extends Object
ServiceApi
implementation. Each instance of ServiceApiProvider implementation can provide only single instance
of a specific ServiceApi. Already created api instance is cached within api provider due to
performance reasons. An instance of api can be obtained via getApi().
Implementations of ServiceApiProvider are required to implement onCreateApi() to
create a new instance of api that is specific for them. If there is required some additional set
up of api instance before it is returned to its users via getApi() than such set up
may be accomplished via onPrepareApi(Object) method.
Whenever an existing instance of api becomes invalid that api instance may be invalidated via call
to invalidateApi() which will result in call to onCreateApi() when
getApi() is next time invoked.
| Constructor and Description |
|---|
ServiceApiProvider() |
| Modifier and Type | Method and Description |
|---|---|
A |
getApi()
Returns the service api implementation specific for this api provider.
|
protected void |
invalidateApi()
Makes the current api implementation cached by this provider invalid so when
getApi()
is next time called a new instance of api will be requested via onCreateApi(). |
protected abstract A |
onCreateApi()
Invoked whenever
getApi() is called and there is no instance of api specific for this
provider instantiated whether due to first call to getApi() or due to invalidation
of the previous api instance via invalidateApi(). |
protected A |
onPrepareApi(A api)
Invoked whenever
getApi() is called to make some additional preparation of the given
api instance before it is returned to the user. |
@NonNull public final A getApi()
Subsequent calls to this method will return already created and cached instance of api.
@NonNull protected abstract A onCreateApi()
getApi() is called and there is no instance of api specific for this
provider instantiated whether due to first call to getApi() or due to invalidation
of the previous api instance via invalidateApi().onPrepareApi(Object)@NonNull protected A onPrepareApi(@NonNull A api)
getApi() is called to make some additional preparation of the given
api instance before it is returned to the user.api - The current api instance cached or just created by this provider.onCreateApi()protected void invalidateApi()
getApi()
is next time called a new instance of api will be requested via onCreateApi().onPrepareApi(Object)