Configuration
This is the manual for older MicroStream versions (Version < 5.0).
The new documentation (Version >= 5.0) is located at:
The EmbeddedStorageManager is mostly created with factory methods of EmbeddedStorage, where the most common settings, like database directory or the root instance, can be configured.
1
EmbeddedStorageManager storageManager = EmbeddedStorage.start(
2
myRoot, // root object of entity graph
3
Paths.get("data-dir") // storage data directory
4
);
Copied!

Foundations

To achieve a more detailed customization, you can utilize the EmbeddedStorageFoundation factory type. It holds and creates on demand all the parts that form an EmbeddedStorageManager.
1
NioFileSystem fileSystem = NioFileSystem.New();
2
EmbeddedStorageManager storageManager = EmbeddedStorageFoundation.New()
3
.setConfiguration(
4
StorageConfiguration.Builder()
5
.setStorageFileProvider(
6
Storage.FileProviderBuilder(fileSystem)
7
.setDirectory(fileSystem.ensureDirectoryPath("storageDir"))
8
.createFileProvider()
9
)
10
.setChannelCountProvider(StorageChannelCountProvider.New(4))
11
.setBackupSetup(StorageBackupSetup.New(
12
fileSystem.ensureDirectoryPath("backupDir")
13
))
14
.createConfiguration()
15
)
16
.createEmbeddedStorageManager();
Copied!

External Configuration

The artifact storage.embedded.configuration provides a convenience layer for configuration purposes, as well as facilities to read external configuration.
pom.xml
1
<repositories>
2
<repository>
3
<id>microstream-releases</id>
4
<url>https://repo.microstream.one/repository/maven-public/</url>
5
</repository>
6
</repositories>
7
<dependencies>
8
<dependency>
9
<groupId>one.microstream</groupId>
10
<artifactId>storage.embedded.configuration</artifactId>
11
<version>04.01.00-MS-GA</version>
12
</dependency>
13
</dependencies>
Copied!
The Configuration type consolidates the most widely used parameters from the storage foundations in one place. It's output is an EmbeddedStorageFoundation from which a EmbeddedStorageManager can be created.
1
EmbeddedStorageManager storageManager = Configuration.Default()
2
.setBaseDirectoryInUserHome("data-dir")
3
.setBackupDirectory("backup-dir")
4
.setChannelCount(4)
5
.createEmbeddedStorageFoundation()
6
.createEmbeddedStorageManager();
Copied!
To read an external configuration use ConfigurationLoader and ConfigurationParser or the Load*() methods of Configuration. Currently XML and INI files are supported.
java (xml)
xml
java (ini)
ini
1
Configuration configuration = Configuration.LoadXml(
2
HelloWorld.class.getResource("/META-INF/microstream/storage.xml")
3
);
Copied!
1
<?xml version="1.0" encoding="UTF-8"?>
2
<properties>
3
<property name="baseDirectory" value ="data" />
4
<property name="channelCount" value ="4" />
5
</properties>
Copied!
1
Configuration configuration = Configuration.LoadIni(
2
HelloWorld.class.getResource("/META-INF/microstream/storage.ini")
3
);
Copied!
1
baseDirectory = data
2
channelCount = 4
Copied!
If you just use Configuration.Load() the default configuration file is used, which is either a file in the classpath root named microstream-storage.properties, or the path configured via the system property microstream.storage.configuration.path.
The full example can be found on GitHub.
If you use a different format, e.g. Json, just implement the ConfigurationParser in the likes of XmlConfigurationParser or IniConfigurationParser.
Last modified 6mo ago
Export as PDF
Copy link