22
22
import java .util .List ;
23
23
24
24
/**
25
- * This class holds a single result of a batch call. {@code T} is the type of the result and {@code
26
- * E} is the type of the service-dependent exception thrown when a processing error occurs.
25
+ * This class holds a single result of a batch call. The class is not thread-safe.
26
+ *
27
+ * @param <T> the type of the result
28
+ * @param <E> the type of the service-dependent exception thrown when a processing error occurs
29
+ *
27
30
*/
28
31
public abstract class BatchResult <T , E extends BaseServiceException > {
29
32
@@ -44,7 +47,7 @@ public boolean completed() {
44
47
* Returns the result of this call.
45
48
*
46
49
* @throws IllegalStateException if the batch has not been completed yet
47
- * @throws E if an error occurred when processing this request
50
+ * @throws E if an error occurred when processing the batch request
48
51
*/
49
52
public T get () throws E {
50
53
checkState (completed (), "Batch has not been completed yet" );
@@ -60,18 +63,16 @@ public T get() throws E {
60
63
* @throws IllegalStateException if the batch has been completed already
61
64
*/
62
65
public void notify (Callback <T , E > callback ) {
63
- if (completed ) {
64
- throw new IllegalStateException ("The batch has been completed. All the calls to the notify()"
66
+ checkState (!completed , "The batch has been completed. All the calls to the notify()"
65
67
+ " method should be done prior to submitting the batch." );
66
- }
67
68
toBeNotified .add (callback );
68
69
}
69
70
70
71
/**
71
72
* Sets an error and status as completed. Notifies all callbacks.
72
73
*/
73
74
protected void error (E error ) {
74
- this .error = error ;
75
+ this .error = checkNotNull ( error ) ;
75
76
this .completed = true ;
76
77
for (Callback <T , E > callback : toBeNotified ) {
77
78
callback .error (error );
0 commit comments