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

wz2cool / local-queue / #40

02 Feb 2025 02:03PM UTC coverage: 91.757% (-0.09%) from 91.85%
#40

push

wz2cool
use closing

9 of 13 new or added lines in 4 files covered. (69.23%)

3 existing lines in 3 files now uncovered.

590 of 643 relevant lines covered (91.76%)

0.92 hits per line

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

85.29
/src/main/java/com/github/wz2cool/localqueue/impl/PositionStore.java
1
package com.github.wz2cool.localqueue.impl;
2

3
import com.github.wz2cool.localqueue.IStore;
4
import net.openhft.chronicle.core.io.IORuntimeException;
5
import net.openhft.chronicle.map.ChronicleMap;
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

9
import java.io.File;
10
import java.nio.file.Files;
11
import java.nio.file.Path;
12

13
/**
14
 * 位置存储
15
 *
16
 * @author frank
17
 */
18
public class PositionStore implements IStore<Long> {
19

20
    private final Logger logger = LoggerFactory.getLogger(this.getClass());
1✔
21
    private final ChronicleMap<String, Long> map;
22

23
    private volatile boolean isClosing = false;
1✔
24
    private volatile boolean isClosed = false;
1✔
25

26
    /**
27
     * 构造函数
28
     *
29
     * @param storeFile 存储文件
30
     */
31
    public PositionStore(final File storeFile) {
1✔
32
        try {
33
            Path dir = storeFile.toPath().getParent();
1✔
34
            if (!Files.exists(dir)) {
1✔
35
                Files.createDirectories(dir);
1✔
36
            }
37
            this.map = ChronicleMap.of(String.class, Long.class)
1✔
38
                    .name(storeFile.getName())
1✔
39
                    .averageKeySize(64)
1✔
40
                    .entries(10000)
1✔
41
                    .createPersistedTo(storeFile);
1✔
42
        } catch (Exception ex) {
×
43
            throw new IORuntimeException("[PositionStore.constructor] error", ex);
×
44
        }
1✔
45
    }
1✔
46

47
    @Override
48
    public boolean isClosed() {
49
        return this.isClosed;
1✔
50
    }
51

52
    @Override
53
    public void put(String key, Long value) {
54
        this.map.put(key, value);
1✔
55
    }
1✔
56

57
    @Override
58
    public Long get(String key) {
59
        return this.map.get(key);
1✔
60
    }
61

62
    @Override
63
    public void close() {
64
        try {
65
            logDebug("[close] start");
1✔
66
            if (isClosing) {
1✔
NEW
67
                logDebug("[close] is closing");
×
UNCOV
68
                return;
×
69
            }
70
            isClosing = true;
1✔
71
            if (!this.map.isClosed()) {
1✔
72
                this.map.close();
1✔
73
            }
74
            this.isClosed = true;
1✔
75
        } finally {
76
            logDebug("[close] end");
1✔
77
        }
1✔
78
    }
1✔
79

80
    // region logger
81

82
    private void logDebug(String format) {
83
        if (logger.isDebugEnabled()) {
1✔
84
            logger.debug(format);
×
85
        }
86
    }
1✔
87

88
    // endregion
89
}
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