Package org.zeromq
Class ZConfig
java.lang.Object
org.zeromq.ZConfig
Lets applications load, work with, and save configuration files. This is a minimal implementation of the ZeroMQ Property Language, which is a simple structured text format for configuration files.
Here is an example ZPL stream and corresponding config structure:
context iothreads = 1 verbose = 1 # Ask for a trace main type = zqueue # ZMQ_DEVICE type frontend option hwm = 1000 swap = 25000000 # 25MB bind = 'inproc://addr1' bind = 'ipc://addr2' backend bind = inproc://addr3
root Down = child | Across = next v context-->main | | | v | type=queue-->frontend-->backend | | | | | v | | bind=inproc://addr3 | v | option-->bind=inproc://addr1-->bind=ipc://addr2 | | | v | hwm=1000-->swap=25000000 v iothreads=1-->verbose=false
It can put and get values and save and load them to disk:
ZConfig conf = new ZConfig("root", null);
conf.put("/curve/public-key","abcdef");
String val = conf.get("/curve/public-key","fallback-defaultkey");
conf.save("test.cert");
ZConfig loaded = ZConfig.load("test.cert");
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static interface
static class
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addComment
(String comment) add commentprivate static ZConfig
child
(ZConfig parent, Matcher matcher, int currentLevel, String currentLine, AtomicInteger lineNumber) private void
fillValues
(String prefix, Map<String, String> values) getName()
static ZConfig
private static ZConfig
load
(ZConfig parent, List<String> content, int currentLevel, AtomicInteger lineNumber) boolean
pathExists
(String path) check if a value-path existsvoid
void
Saves the configuration to a file.private void
visit
(ZConfig startNode, ZConfig.IVisitor handler, int level)
-
Field Details
-
LEFT
- See Also:
-
PTRN_CONTAINER
-
PTRN_KEYVALUE
-
name
-
children
-
comments
-
value
-
-
Constructor Details
-
ZConfig
-
-
Method Details
-
getChild
-
getValues
-
fillValues
-
getName
-
getValue
-
getValue
-
pathExists
check if a value-path exists- Parameters:
path
-- Returns:
- true if value-path exists
-
addComment
add comment- Parameters:
comment
-
-
putValue
- Parameters:
path
-value
- set value of config item
-
putValues
-
visit
- Throws:
IOException
-
save
Saves the configuration to a file.This method will overwrite contents of existing file
- Parameters:
filename
- the path of the file to save the configuration into, or "-" to dump it to standard output- Returns:
- the saved file or null if dumped to the standard output
- Throws:
IOException
- if unable to save the file.
-
save
- Throws:
IOException
-
load
- Throws:
IOException
-
load
private static ZConfig load(ZConfig parent, List<String> content, int currentLevel, AtomicInteger lineNumber) -
child
private static ZConfig child(ZConfig parent, Matcher matcher, int currentLevel, String currentLine, AtomicInteger lineNumber)
-