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

wz2cool / local-queue / #38

01 Feb 2025 12:36PM UTC coverage: 91.85% (-0.02%) from 91.871%
#38

push

web-flow
Merge pull request #6 from wz2cool/0.1.2

0.1.2

113 of 127 new or added lines in 9 files covered. (88.98%)

586 of 638 relevant lines covered (91.85%)

0.92 hits per line

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

84.38
/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 isClosed = false;
1✔
24

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

46
    public boolean isClosed() {
47
        return this.isClosed;
1✔
48
    }
49

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

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

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

77
    // region logger
78

79
    private void logDebug(String format) {
80
        if (logger.isDebugEnabled()) {
1✔
NEW
81
            logger.debug(format);
×
82
        }
83
    }
1✔
84

85
    // endregion
86
}
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