Java源码示例:net.openhft.chronicle.hash.ChronicleHashClosedException
示例1
@Test(expected = ChronicleHashClosedException.class)
public void testCloseWithoutPersistedFile() {
MetricStore heapStore = new VarBitMetricStore();
long uuid1 = 1;
long ts = Instant.now().getEpochSecond();
double value = 100;
heapStore.addPoint(uuid1, ts, value);
OffHeapVarBitMetricStore offheapStore1 =
OffHeapVarBitMetricStore.toOffHeapStore(getSeriesMap(heapStore), testFileName, "");
assertEquals(1, offheapStore1.getSeriesMap().size());
List<Point> points = offheapStore1.getSeries(uuid1);
assertEquals(1, points.size());
assertEquals(ts, points.get(0).getTs());
assertEquals(value, points.get(0).getVal(), delta);
offheapStore1.close();
offheapStore1.getSeriesMap().size();
}
示例2
/**
* Returns {@code true} if this is the outer context lock in this thread, {@code false} if this
* is a nested context.
*/
public boolean lockContextLocally(ChronicleHash<?, ?, ?, ?> hash) {
// hash().isOpen() check guarantees no starvation of a thread calling chMap.close() and
// trying to close this context by closeContext() method below, while the thread owning this
// context frequently locks and unlocks it (e. g. in a loop). This is also the only check
// for chMap openness during the whole context usage lifecycle.
if (hash.isOpen() && MEMORY.compareAndSwapInt(this, CONTEXT_LOCK_OFFSET,
CONTEXT_UNLOCKED, CONTEXT_LOCKED_LOCALLY)) {
return true;
} else {
if (contextLock == CONTEXT_LOCKED_LOCALLY)
return false;
// Don't extract this hash().isOpen() and the one above, because they could return
// different results: the first (above) could return true, the second (below) - false.
if (contextLock == CONTEXT_CLOSED || !hash.isOpen())
throw new ChronicleHashClosedException(hash);
throw new AssertionError("Unknown context lock state: " + contextLock);
}
}
示例3
@Override
public Optional<V> put(final String key, final V value) {
try {
return super.put(key, value);
} catch (ChronicleHashClosedException e) {
LOG.warn("could not put on closed state repository", e);
return Optional.empty();
}
}
示例4
@Override
public Optional<V> get(final String key) {
try {
return super.get(key);
} catch (ChronicleHashClosedException e) {
LOG.warn("could not get on closed state repository", e);
return Optional.empty();
}
}
示例5
@Override
public long size() {
try {
return super.size();
} catch (final ChronicleHashClosedException e) {
LOG.warn("could not get size on closed state repository", e);
return 0;
}
}
示例6
@Test(expected = ChronicleHashClosedException.class)
public void testGetAfterCloseThrowsChronicleHashClosedException() throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.get(1);
}
示例7
@Test(expected = ChronicleHashClosedException.class)
public void testIterationAfterCloseThrowsChronicleHashClosedException()
throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.forEach((k, v) -> {
});
}
示例8
@Test(expected = ChronicleHashClosedException.class)
public void testSizeAfterCloseThrowsChronicleHashClosedException()
throws InterruptedException {
ChronicleMap<Integer, Integer> map =
ChronicleMap.of(Integer.class, Integer.class).entries(1).create();
Thread t = new Thread(() -> map.close());
t.start();
t.join();
map.size();
}
示例9
private void checkOpen() {
if (closed())
throw new ChronicleHashClosedException(chronicleHashIdentityString);
}