mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Use more specific ChronicleHashClosedException instead of IllegalStateException, when methods of ChronicleHash are called after hash.close(). Actualize ChronicleHash.close() javadoc.
This commit is contained in:
@@ -165,9 +165,10 @@ public interface ChronicleHash<K, E extends HashEntry<K>, SC extends HashSegment
|
||||
* collection. This could be a problem if, for example, you target rare garbage collections,
|
||||
* but load and drop {@code ChronicleHash}es regularly.
|
||||
*
|
||||
* <p>After this method call behaviour of <i>all</i> methods of {@code ChronicleMap}
|
||||
* or {@code ChronicleSet} is undefined. <i>Any</i> method call on the map might throw
|
||||
* <i>any</i> exception, or even JVM crash. Shortly speaking, don't call use map closing.
|
||||
* <p>After this method call, all methods, querying the {@code ChronicleHash}'s entries, {@link
|
||||
* #longSize()} and {@code size()}), throw {@link ChronicleHashClosedException}. {@link
|
||||
* #isOpen()} returns {@code false}, {@code close()} itself returns immediately without effects
|
||||
* (i. e. repetitive {@code close()}, even from concurrent threads, are safe).
|
||||
*/
|
||||
@Override
|
||||
void close();
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2012, 2016 higherfrequencytrading.com
|
||||
* Copyright (C) 2016 Roman Leventov
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.openhft.chronicle.hash;
|
||||
|
||||
/**
|
||||
* Thrown when a {@link ChronicleHash} is accessed after {@link ChronicleHash#close()}.
|
||||
*/
|
||||
public final class ChronicleHashClosedException extends IllegalStateException {
|
||||
private static final long serialVersionUID = 0L;
|
||||
|
||||
public ChronicleHashClosedException() {
|
||||
super("Access to ChronicleHash after close()");
|
||||
}
|
||||
}
|
||||
@@ -1002,7 +1002,7 @@ public abstract class VanillaChronicleHash<K,
|
||||
|
||||
private void checkOpen() {
|
||||
if (closed)
|
||||
throw new IllegalStateException("Access to ChronicleHash after close()");
|
||||
throw new ChronicleHashClosedException();
|
||||
}
|
||||
|
||||
protected void addContext(ChainingInterface context) {
|
||||
|
||||
@@ -20,6 +20,7 @@ package net.openhft.chronicle.hash.impl.stage.hash;
|
||||
import net.openhft.chronicle.core.Memory;
|
||||
import net.openhft.chronicle.core.OS;
|
||||
import net.openhft.chronicle.hash.ChronicleHash;
|
||||
import net.openhft.chronicle.hash.ChronicleHashClosedException;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Arrays;
|
||||
@@ -65,7 +66,7 @@ public abstract class ThreadLocalState {
|
||||
if (contextLock == CONTEXT_LOCKED_LOCALLY)
|
||||
return false;
|
||||
if (contextLock == CONTEXT_CLOSED)
|
||||
throw new IllegalStateException("Access to ChronicleHash after close()");
|
||||
throw new ChronicleHashClosedException();
|
||||
throw new AssertionError("Unknown context lock state: " + contextLock);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user