public final class StampedConfig extends java.lang.Object implements ConcurrentCommentedConfig
StampedLock.
Unlike SynchronizedConfig, StampedConfig allows multiple concurrent reads.
It should also perform better under contention.
| Modifier and Type | Class and Description |
|---|---|
static class |
StampedConfig.Accumulator
A CommentedConfig that allows to quickly accumulate values before a
replaceContentBy(Accumulator). |
CommentedConfig.EntryUnmodifiableCommentedConfig.CommentNode| Constructor and Description |
|---|
StampedConfig() |
StampedConfig(ConfigFormat<?> configFormat,
java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
add(java.util.List<java.lang.String> path,
java.lang.Object value)
Adds a config value.
|
<R> R |
bulkCommentedRead(java.util.function.Function<? super UnmodifiableCommentedConfig,R> action)
Performs multiple reads as a single atomic operation, and returns a value.
|
<R> R |
bulkCommentedUpdate(java.util.function.Function<? super CommentedConfig,R> action)
Performs multiple reads and writes as a single atomic operation and returns a value.
|
<R> R |
bulkRead(java.util.function.Function<? super UnmodifiableConfig,R> action)
Performs multiple reads as a single atomic operation and returns a value.
|
<R> R |
bulkUpdate(java.util.function.Function<? super Config,R> action)
Performs multiple reads and writes as a single atomic operation and returns a value.
|
void |
clear()
Removes all values from the config.
|
void |
clearComments()
Removes all the comments from the config.
|
java.util.Map<java.lang.String,java.lang.String> |
commentMap()
Returns a Map view of the config's comments.
|
ConfigFormat<?> |
configFormat()
Returns the config's format.
|
boolean |
contains(java.util.List<java.lang.String> path)
Checks if the config contains a value at some path.
|
boolean |
containsComment(java.util.List<java.lang.String> path)
Checks if the config contains a comment at some path.
|
StampedConfig |
createSubConfig()
Creates a new sub config of this config, as created when a subconfig's creation is
implied by
Config.set(List, Object) or Config.add(List, Object). |
java.util.Set<? extends CommentedConfig.Entry> |
entrySet()
Returns a view of the entries contained in the configuration.
|
boolean |
equals(java.lang.Object obj) |
java.lang.String |
getComment(java.util.List<java.lang.String> path)
Gets a comment from the config.
|
<T> T |
getRaw(java.util.List<java.lang.String> path)
Gets a value from the config.
|
StampedConfig.Accumulator |
newAccumulator()
Creates a new accumulator with the same
Supplier<Map> and ConfigFormat as this config. |
StampedConfig.Accumulator |
newAccumulatorCopy()
Creates a deep copy of this config into an
StampedConfig.Accumulator. |
void |
putAll(UnmodifiableConfig other)
Copies all the values of a config into this config.
|
void |
putAllComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> comments)
Puts the comments in the given map to this config.
|
void |
putAllComments(UnmodifiableCommentedConfig other)
Puts the comments in the given config to this config.
|
<T> T |
remove(java.util.List<java.lang.String> path)
Removes a value from the config.
|
void |
removeAll(UnmodifiableConfig other)
Removes all the values of the given config from this config.
|
java.lang.String |
removeComment(java.util.List<java.lang.String> path)
Removes a comment from the config.
|
void |
replaceContentBy(StampedConfig.Accumulator newContent)
Atomically replaces the content of this config by the content of the specified accumulator.
|
void |
replaceContentBy(StampedConfig newContent)
Atomically replaces the content of this config by the content of the specified config.
|
<T> T |
set(java.util.List<java.lang.String> path,
java.lang.Object value)
Sets a config value.
|
java.lang.String |
setComment(java.util.List<java.lang.String> path,
java.lang.String value)
Sets a config comment.
|
int |
size()
Gets the size of the config.
|
java.lang.String |
toString() |
java.util.Map<java.lang.String,java.lang.Object> |
valueMap()
Returns a Map view of the config's values.
|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbulkCommentedRead, bulkCommentedUpdatechecked, concurrentCopy, concurrentCopy, concurrentCopy, concurrentCopy, copy, copy, copy, copy, copy, copy, copy, copy, fake, inMemory, inMemoryConcurrent, of, of, ofConcurrent, removeComment, setComment, unmodifiable, wrapcontainsComment, fake, getComment, getComments, getComments, getOptionalComment, getOptionalCommentbulkRead, bulkUpdateadd, addAll, getDefaultMapCreator, getDefaultMapCreator, inMemoryUniversal, inMemoryUniversalConcurrent, isInsertionOrderPreserved, of, of, ofConcurrent, remove, set, setInsertionOrderPreserved, update, updateapply, apply, contains, get, get, getByte, getByte, getByteOrElse, getByteOrElse, getChar, getChar, getCharOrElse, getCharOrElse, getEnum, getEnum, getEnum, getEnum, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getEnumOrElse, getInt, getInt, getIntOrElse, getIntOrElse, getIntOrElse, getIntOrElse, getLong, getLong, getLongOrElse, getLongOrElse, getLongOrElse, getLongOrElse, getOptional, getOptional, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalEnum, getOptionalInt, getOptionalInt, getOptionalLong, getOptionalLong, getOrElse, getOrElse, getOrElse, getOrElse, getRaw, getShort, getShort, getShortOrElse, getShortOrElse, isEmpty, isNull, isNullpublic StampedConfig()
public StampedConfig(ConfigFormat<?> configFormat, java.util.function.Supplier<java.util.Map<java.lang.String,java.lang.Object>> mapSupplier)
public void replaceContentBy(StampedConfig newContent)
newContent - the new content (cannot be used anymore after this)public void replaceContentBy(StampedConfig.Accumulator newContent)
newContent - the new content (cannot be used anymore after this)public StampedConfig.Accumulator newAccumulator()
Supplier<Map> and ConfigFormat as this config.
See StampedConfig.Accumulator for more information.public StampedConfig.Accumulator newAccumulatorCopy()
StampedConfig.Accumulator.public int size()
UnmodifiableConfigsize in interface UnmodifiableConfigpublic StampedConfig createSubConfig()
ConfigConfig.set(List, Object) or Config.add(List, Object).createSubConfig in interface CommentedConfigcreateSubConfig in interface ConcurrentCommentedConfigcreateSubConfig in interface ConcurrentConfigcreateSubConfig in interface Configpublic ConfigFormat<?> configFormat()
UnmodifiableConfigconfigFormat in interface UnmodifiableConfigpublic java.util.Map<java.lang.String,java.lang.Object> valueMap()
UnmodifiableConfigvalueMap in interface ConfigvalueMap in interface UnmodifiableConfigpublic void clear()
Configpublic <T> T getRaw(java.util.List<java.lang.String> path)
UnmodifiableConfigNullObject.NULL_OBJECT to null.getRaw in interface UnmodifiableConfigT - the value's typepath - the value's path, each element of the list is a different part of the path.null if there is no such value.public boolean contains(java.util.List<java.lang.String> path)
UnmodifiableConfigcontains in interface UnmodifiableConfigpath - the path to check, each element of the list is a different part of the path.true if the path is associated with a value, false if it's not.public boolean add(java.util.List<java.lang.String> path,
java.lang.Object value)
Configpublic <T> T remove(java.util.List<java.lang.String> path)
Configpublic <T> T set(java.util.List<java.lang.String> path,
java.lang.Object value)
Configpublic void putAll(UnmodifiableConfig other)
Configpublic void removeAll(UnmodifiableConfig other)
Configpublic void clearComments()
CommentedConfigclearComments in interface CommentedConfigpublic java.lang.String removeComment(java.util.List<java.lang.String> path)
CommentedConfigremoveComment in interface CommentedConfigpath - the comment's path, each element of the list is a different part of the path.nullpublic java.lang.String setComment(java.util.List<java.lang.String> path,
java.lang.String value)
CommentedConfigsetComment in interface CommentedConfigpath - the comment's path, each element of the list is a different part of the path.value - the comment to setnullpublic boolean containsComment(java.util.List<java.lang.String> path)
UnmodifiableCommentedConfigcontainsComment in interface UnmodifiableCommentedConfigpath - the path to check, each element of the list is a different part of the path.true if the path is associated with a comment, false if it's not.public java.lang.String getComment(java.util.List<java.lang.String> path)
UnmodifiableCommentedConfiggetComment in interface UnmodifiableCommentedConfigpath - the comment's path, each element of the list is a different part of the path.null if there is none.public java.util.Map<java.lang.String,java.lang.String> commentMap()
CommentedConfigThe comment map contains only the comments of the direct elements of the configuration, not the comments of their sub-elements.
commentMap in interface CommentedConfigcommentMap in interface UnmodifiableCommentedConfigpublic void putAllComments(UnmodifiableCommentedConfig other)
CommentedConfigThe comments are copied recursively, but missing sub-configurations are NOT created.
putAllComments in interface CommentedConfigother - the config to copy its commentspublic void putAllComments(java.util.Map<java.lang.String,UnmodifiableCommentedConfig.CommentNode> comments)
CommentedConfigputAllComments in interface CommentedConfigcomments - the comments to setpublic boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Objectpublic java.util.Set<? extends CommentedConfig.Entry> entrySet()
The returned Set provides iterators that do not reflect entries that are removed or added during iteration. Each iterator obtained from the Set provides a list of entries that existed at the time of its creation, and allow to read their latest value.
entrySet in interface CommentedConfigentrySet in interface ConfigentrySet in interface UnmodifiableCommentedConfigentrySet in interface UnmodifiableConfigpublic <R> R bulkRead(java.util.function.Function<? super UnmodifiableConfig,R> action)
ConcurrentConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not change during the entire operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
String combined = config.bulkUpdate(conf -> {
String a = conf.get("a");
String b = conf.get("b");
return a + b;
// note that we use `conf` and not `config`!
});
bulkRead in interface ConcurrentCommentedConfigbulkRead in interface ConcurrentConfigR - the type of the function's resultaction - a function to execute on the configuration viewpublic <R> R bulkUpdate(java.util.function.Function<? super Config,R> action)
ConcurrentConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not be concurrently modified by other threads during the entire bulk operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
String combined = config.bulkUpdate(conf -> {
String a = conf.get("a");
String b = conf.get("b");
String combined = a + b;
conf.set("combined", combined);
return combined;
// note that we use `conf` and not `config`!
});
If you only have to read the configuration, prefer to use ConcurrentConfig.bulkRead(Function),
since it may provide a better performance.
bulkUpdate in interface ConcurrentCommentedConfigbulkUpdate in interface ConcurrentConfigR - the type of the function's resultaction - a function to execute on the configuration viewpublic <R> R bulkCommentedRead(java.util.function.Function<? super UnmodifiableCommentedConfig,R> action)
ConcurrentCommentedConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not change during the entire operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
config.bulkCommentedRead(conf -> {
Object value = conf.get("a.b.c");
String comment = conf.getComment("a.b.c");
// note that we use `conf` and not `config`!
});
If you don't need access to the comments, prefer to use ConcurrentCommentedConfig.bulkRead(Function),
sine it may provide a better performance.
bulkCommentedRead in interface ConcurrentCommentedConfigR - the type of the function's resultaction - a function to execute on the configuration viewpublic <R> R bulkCommentedUpdate(java.util.function.Function<? super CommentedConfig,R> action)
ConcurrentCommentedConfigIt is guaranteed that the content of the config, accessed through the provided "view", will not be concurrently modified by other threads during the entire bulk operation. The configuration must be used exclusively through the object passed to the consumer (the "view"), not with the original reference. After the bulk operation, the view cannot be used anymore.
Here is an example:
Object value = config.bulkCommentedUpdate(conf -> {
Object value = conf.get("a.b.c");
String comment = conf.getComment("a.b.c");
conf.setComment("a.b.c", comment + "\nAdditional comment here.");
// note that we use `conf` and not `config`!
return value;
});
If you don't need access to the comments, prefer to use ConcurrentCommentedConfig.bulkUpdate(Function),
since it may provide a better performance. Also, if you only have to read the configuration,
prefer to use ConcurrentCommentedConfig.bulkCommentedRead(Function).
bulkCommentedUpdate in interface ConcurrentCommentedConfigR - the type of the function's resultaction - a function to execute on the configuration view