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

wz2cool / local-queue / #66

04 Feb 2025 08:39AM UTC coverage: 91.822% (-0.5%) from 92.337%
#66

push

web-flow
Merge pull request #10 from wz2cool/0.2.2

0.2.2

20 of 25 new or added lines in 1 file covered. (80.0%)

1 existing line in 1 file now uncovered.

741 of 807 relevant lines covered (91.82%)

0.92 hits per line

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

82.93
/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
import java.util.Optional;
13
import java.util.concurrent.atomic.AtomicBoolean;
14

15
/**
16
 * 位置存储
17
 *
18
 * @author frank
19
 */
20
public class PositionStore implements IStore<String, Long> {
21

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

25
    private final AtomicBoolean isClosing = new AtomicBoolean(false);
1✔
26
    private final AtomicBoolean isClosed = new AtomicBoolean(false);
1✔
27
    private final Object closeLocker = new Object();
1✔
28

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

50
    @Override
51
    public boolean isClosed() {
52
        return this.isClosed.get();
1✔
53
    }
54

55
    @Override
56
    public void put(String key, Long value) {
57
        if (isClosing.get()) {
1✔
UNCOV
58
            throw new IORuntimeException("PositionStore is closing");
×
59
        }
60
        this.map.put(key, value);
1✔
61
    }
1✔
62

63
    @Override
64
    public Optional<Long> get(String key) {
65
        if (isClosing.get()) {
1✔
66
            throw new IORuntimeException("PositionStore is closing");
×
67
        }
68
        return Optional.ofNullable(this.map.get(key));
1✔
69
    }
70

71
    @Override
72
    public synchronized void close() {
73
        synchronized (closeLocker) {
1✔
74
            try {
75
                logDebug("[close] start");
1✔
76
                if (isClosing.get()) {
1✔
77
                    logDebug("[close] is closing");
×
78
                    return;
×
79
                }
80
                isClosing.set(true);
1✔
81
                if (!this.map.isClosed()) {
1✔
82
                    this.map.close();
1✔
83
                }
84
                isClosed.set(true);
1✔
85
            } finally {
86
                logDebug("[close] end");
1✔
87
            }
1✔
88
        }
1✔
89
    }
1✔
90

91
    // region logger
92

93
    private void logDebug(String format) {
94
        if (logger.isDebugEnabled()) {
1✔
95
            logger.debug(format);
×
96
        }
97
    }
1✔
98

99
    // endregion
100
}
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