Package com.contentful.java.cma
Class CMACallback<T>
- java.lang.Object
-
- com.contentful.java.cma.CMACallback<T>
-
- Type Parameters:
T- the type of object to be expected as a result. For methods that return a collection of resources it is required to useCMAArrayas the type.Callback can be cancelled at any point using the
cancel()method, that will prevent any future calls toonSuccess(T)andonFailure(RuntimeException).
public abstract class CMACallback<T> extends java.lang.ObjectCallback to be used with any of theCMAClientasynchronous methods.Implement the
onSuccess(T)method for cases where the request was successful, the result object should be delivered as a parameter.It is also possible, but not mandatory to override
onFailure(java.lang.RuntimeException)and provide an implementation for handling errors.
-
-
Constructor Summary
Constructors Constructor Description CMACallback()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcancel()Cancels this callback.booleanisCancelled()protected voidonFailure(java.lang.RuntimeException exception)Callback to be invoked in case the request was unsuccessful.protected abstract voidonSuccess(T result)Callback to be invoked in case the request was successful.
-
-
-
Method Detail
-
onSuccess
protected abstract void onSuccess(T result)
Callback to be invoked in case the request was successful.- Parameters:
result- result object
-
onFailure
protected void onFailure(java.lang.RuntimeException exception)
Callback to be invoked in case the request was unsuccessful.- Parameters:
exception-RuntimeExceptioninstance
-
cancel
public void cancel()
Cancels this callback. This will prevent any future calls toonSuccess(Object)andonFailure(RuntimeException)methods. This action cannot be reversed.
-
isCancelled
public boolean isCancelled()
- Returns:
- true in case this callback instance was previously canceled.
-
-