<!doctype html><htmllang=enclass="js csstransforms3d"><head><metacharset=utf-8><metaname=viewportcontent="width=device-width,initial-scale=1"><metaname=generatorcontent="Hugo 0.80.0"><metaname=descriptioncontent="Strolch is a parameterized framework for use on servers and IoT"><metaname=authorcontent="Strolch"><linkrel=iconhref=/favicon.icotype=image/ico><title>Realms - Strolch</title><linkhref=/css/nucleus.css?1661758283rel=stylesheet><linkhref=/css/fontawesome-all.min.css?1661758283rel=stylesheet><linkhref=/css/hybrid.css?1661758283rel=stylesheet><linkhref=/css/featherlight.min.css?1661758283rel=stylesheet><linkhref=/css/perfect-scrollbar.min.css?1661758283rel=stylesheet><linkhref=/css/auto-complete.css?1661758283rel=stylesheet><linkhref=/css/atom-one-dark-reasonable.css?1661758283rel=stylesheet><linkhref=/css/theme.css?1661758283rel=stylesheet><linkhref=/css/hugo-theme.css?1661758283rel=stylesheet><linkhref=/css/theme-green.css?1661758283rel=stylesheet><scriptsrc=/js/jquery-3.3.1.min.js?1661758283></script><style>:root#header+#content>#left>#rlblock_left{display:none!important}</style></head><bodydata-url=/documentation/realms/><navid=sidebar><divid=header-wrapper><divid=header><aid=logohref=/><imgsrc=/logo.png></a></div><divclass=searchbox><labelfor=search-by><iclass="fas fa-search"></i></label><inputdata-search-inputid=search-bytype=searchplaceholder=Search...>
arbitrary number of realms configured and each realm has its own persistence
configuration, allowing to separate mandates completely.</p><p>A realm can run in one of the following modes:</p><ul><li>EMPTY
This is a transient data store mode, where no model changes are
persisted - they are only kept in memory. When the Strolch agent is
started, this realm is empty as no data is loaded.</li><li>TRANSIENT
This is the same as EMPTY, but with the difference that when the Strolch
agent is started, a model file is parsed and the in-memory realm is
populated with the elements parsed from the model file.</li><li>CACHED
In this mode, all data is stored in-memory, and any changes made are
written back to the persistence layer. This allows for fast in-memory
qeuries, but makes sure no data is lost when the agent is restarted.</li></ul><p>Realms are mostly hidden from a developer as a <code>StrolchTransaction</code> exposes
all important operations needed to access Strolch objects. A developer will
however need to configure the realms for their specific project. If the
project only requires one realm, then the <code>defaultRealm</code> can be used, where the
developer only is required to configure the mode and any relevant model file.</p><p>If the mode is <code>CACHED</code>, then the <code>PersistenceHandler</code> component is required to
be configured, so that the DAOs know how to access the underlying database.</p><p>The configuration in the <code>StrolchConfiguration.xml</code> file is as follows:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-xmldata-lang=xml><spanstyle=color:#f92672><StrolchConfiguration></span>
</code></pre></div><h2id=multi-realm>Multi-Realm</h2><p>A multi-realm configuration would be as follows.</p><divclass="notices tip"><p>Note how the defaultRealm is still enabled, and has its configuration as
before. Further the PostgreSQL PersistenceHandler is configured to show how the
realms are connected to the persistence handler:</p></div><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-xmldata-lang=xml><spanstyle=color:#f92672><StrolchConfiguration></span>
</code></pre></div><h2id=access-realm>Access realm</h2><p>Accessing a realm is done in multiple ways. Important is to note, that a user
should use the <code>StrolchTransaction</code> object, instead of accessing the Realm directly.</p><p>Opening a transaction is done from a <code>Service</code> by calling one of the
<code>openTx()</code>-methods. Nevertheless, the realm can be accessed as follows:</p><divclass=highlight><prestyle=color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4><codeclass=language-javadata-lang=java><spanstyle=color:#66d9ef>public</span><spanstyle=color:#66d9ef>class</span><spanstyle=color:#a6e22e>Example</span><spanstyle=color:#f92672>{</span>