Realms implement multi-tenant capabilities. A Strolch agent can have an arbitrary number of realms configured and each realm has its own data maps (Resources, Orders, Activities) and can be configured independently.
The RealmHandler is a StrolchComponent that manages the lifecycle of all configured realms. It provides access to
the realms by name.
A realm can run in one of the following modes:
Realms are mostly hidden from a developer as a StrolchTransaction exposes all important operations needed to access
Strolch objects. A developer will however need to configure the realms for their specific project.
The configuration in the StrolchConfiguration.xml file is as follows:
<Component>
<name>RealmHandler</name>
<api>li.strolch.agent.api.RealmHandler</api>
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
<depends>PrivilegeHandler</depends>
<Properties>
<!-- one of EMPTY, TRANSIENT, CACHED-->
<dataStoreMode>TRANSIENT</dataStoreMode>
<dataStoreFile>StrolchModel.xml</dataStoreFile>
</Properties>
</Component>
A multi-realm configuration allows defining different settings for each realm:
<Component>
<name>RealmHandler</name>
<api>li.strolch.agent.api.RealmHandler</api>
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
<Properties>
<realms>defaultRealm, cachedRealm</realms>
<dataStoreMode>TRANSIENT</dataStoreMode>
<dataStoreFile>DefaultRealm.xml</dataStoreFile>
<dataStoreMode.cachedRealm>CACHED</dataStoreMode.cachedRealm>
<dataStoreMode.emptyRealm>EMPTY</dataStoreMode.emptyRealm>
</Properties>
</Component>
If a realm uses the CACHED mode, the PersistenceHandler must be configured. Each realm can have its own database
connection:
<Component>
<name>PersistenceHandler</name>
<api>li.strolch.persistence.api.PersistenceHandler</api>
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
<Properties>
<db.url.cachedRealm>jdbc:postgresql://localhost/testdb</db.url.cachedRealm>
<db.username.cachedRealm>user</db.username.cachedRealm>
<db.password.cachedRealm>password</db.password.cachedRealm>
</Properties>
</Component>
Accessing a realm is done via the ComponentContainer. However, it is recommended to interact with the model via
transactions.
StrolchRealm realm = container.getRealm(StrolchConstants.DEFAULT_REALM);
try(
StrolchTransaction tx = realm.openTx(certificate, "Action", false)){
// ...
}