forked from gooddata/gooddata-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPollResult.java
More file actions
60 lines (50 loc) · 1.54 KB
/
PollResult.java
File metadata and controls
60 lines (50 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
* Copyright (C) 2004-2017, GoodData(R) Corporation. All rights reserved.
* This source code is licensed under the BSD-style license found in the
* LICENSE.txt file in the root directory of this source tree.
*/
package com.gooddata;
import java.util.concurrent.TimeUnit;
import static com.gooddata.util.Validate.notNull;
/**
* Represents the result retrieved by polling on the REST API.
*/
public final class PollResult<T> implements FutureResult<T> {
private final AbstractService service;
private final PollHandler<?,T> handler;
/**
* Creates a new instance of the result to be eventually retrieved by polling on the REST API.<p>
* For internal use by services employing polling.
*
* @param service this service
* @param handler poll handler
*/
public PollResult(final AbstractService service, final PollHandler<?, T> handler) {
this.service = notNull(service, "service");
this.handler = notNull(handler, "handler");
}
@Override
public boolean isDone() {
return handler.isDone() || service.pollOnce(handler);
}
@Override
public T get() {
return get(0, null);
}
@Override
public T get(final long timeout, final TimeUnit unit) {
if (handler.isDone()) {
return handler.getResult();
}
return service.poll(handler, timeout, unit);
}
/**
* Get URI used for polling
*
* @return URI string
*/
@Override
public String getPollingUri() {
return handler.getPollingUri();
}
}