• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

alibaba / jetcache / #405

16 Apr 2024 05:58AM UTC coverage: 0.0% (-88.9%) from 88.866%
#405

push

areyouok
add encoding to fix coverage report

0 of 5353 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/jetcache-core/src/main/java/com/alicp/jetcache/CacheResult.java
1
package com.alicp.jetcache;
2

3
import com.alicp.jetcache.anno.CacheConsts;
4

5
import java.time.Duration;
6
import java.util.concurrent.*;
7

8
/**
9
 * Created on 2016/9/28.
10
 *
11
 * @author huangli
12
 */
13
public class CacheResult {
14

15
    public static final String MSG_ILLEGAL_ARGUMENT = "illegal argument";
16

17
    private static Duration DEFAULT_TIMEOUT = CacheConsts.ASYNC_RESULT_TIMEOUT;
×
18

19
    public static final CacheResult SUCCESS_WITHOUT_MSG = new CacheResult(CacheResultCode.SUCCESS, null);
×
20
    public static final CacheResult PART_SUCCESS_WITHOUT_MSG = new CacheResult(CacheResultCode.PART_SUCCESS, null);
×
21
    public static final CacheResult FAIL_WITHOUT_MSG = new CacheResult(CacheResultCode.FAIL, null);
×
22
    public static final CacheResult FAIL_ILLEGAL_ARGUMENT = new CacheResult(CacheResultCode.FAIL, MSG_ILLEGAL_ARGUMENT);
×
23
    public static final CacheResult EXISTS_WITHOUT_MSG = new CacheResult(CacheResultCode.EXISTS, null);
×
24

25
    private volatile CacheResultCode resultCode;
26
    private volatile String message;
27
    private final CompletionStage<ResultData> future;
28

29
    private volatile Duration timeout = DEFAULT_TIMEOUT;
×
30

31
    public CacheResult(CompletionStage<ResultData> future) {
×
32
        this.future = future;
×
33
    }
×
34

35
    public CacheResult(CacheResultCode resultCode, String message) {
36
        this(CompletableFuture.completedFuture(new ResultData(resultCode, message, null)));
×
37
    }
×
38

39
    public CacheResult(Throwable ex) {
×
40
        future = CompletableFuture.completedFuture(new ResultData(ex));
×
41
    }
×
42

43
    public boolean isSuccess() {
44
        return getResultCode() == CacheResultCode.SUCCESS;
×
45
    }
46

47
    protected void waitForResult() {
48
        waitForResult(timeout);
×
49
    }
×
50

51
    public void waitForResult(Duration timeout) {
52
        if (resultCode != null) {
×
53
            return;
×
54
        }
55
        try {
56
            ResultData resultData = future.toCompletableFuture().get(
×
57
                    timeout.toMillis(), TimeUnit.MILLISECONDS);
×
58
            fetchResultSuccess(resultData);
×
59
        } catch (TimeoutException | InterruptedException | ExecutionException e) {
×
60
            fetchResultFail(e);
×
61
        }
×
62
    }
×
63

64
    protected void fetchResultSuccess(ResultData resultData) {
65
        message = resultData.getMessage();
×
66
        resultCode = resultData.getResultCode();
×
67
    }
×
68

69
    protected void fetchResultFail(Throwable e) {
70
        message = e.getClass() + ":" + e.getMessage();
×
71
        resultCode = CacheResultCode.FAIL;
×
72
    }
×
73

74
    public CacheResultCode getResultCode() {
75
        waitForResult();
×
76
        return resultCode;
×
77
    }
78

79
    public String getMessage() {
80
        waitForResult();
×
81
        return message;
×
82
    }
83

84
    public CompletionStage<ResultData> future() {
85
        return future;
×
86
    }
87

88
    public static void setDefaultTimeout(Duration defaultTimeout) {
89
        DEFAULT_TIMEOUT = defaultTimeout;
×
90
    }
×
91

92
    public void setTimeout(Duration timeout) {
93
        this.timeout = timeout;
×
94
    }
×
95
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc