strolch/li.strolch.website/www.strolch.li/documentation-realms.html

214 lines
9.4 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="google-site-verification" content="CPhbjooaiTdROm7Vs4E7kuHZvBfkeLUtonGgcVUbTL8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="ico/favicon.ico">
<title>Strolch: Realms</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="css/custom.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --><!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script><![endif]-->
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<a class="navbar-brand" href="index.html">Strolch</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="index.html">Overview</a></li>
<li><a href="api.html">API</a></li>
<li class="active"><a href="documentation.html">Documentation</a></li>
<li><a href="tutorial.html">Tutorial</a></li>
<li><a href="downloads.html">Downloads</a></li>
<li><a href="development.html">Development</a></li>
<li><a href="blog.html">Blog</a></li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="page-header">
<h1 class="page-title">Documentation: Realms</h1>
<p class="lead page-description">This page discusses Strolch Realms</p>
</div>
<div class="content">
<p>Realms implement multi-tenant capabilities. A Strolch agent can have an arbitrary number of realms configured
and each realm has its own persistence configuration, allowing to separate mandates completely.</p>
A realm can run in one of the following modes:
<ul>
<li>EMPTY <br/> 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 <br/> 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 <br/> 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>
<li>TRANSACTIONAL <br/> In this mode no data is kept in-memory and every query, and element retrieval is
passed to the persistence layer to be retrieved from the underlying database. This is similar to typical
Java applications where JPA is used.
</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 CACHED or TRANSACTIONAL, 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>
<pre>
&lt;StrolchConfiguration&gt;
&lt;env id="dev"&gt;
...
&lt;Component&gt;
&lt;name&gt;RealmHandler&lt;/name&gt;
&lt;api&gt;li.strolch.agent.api.RealmHandler&lt;/api&gt;
&lt;impl&gt;li.strolch.agent.impl.DefaultRealmHandler&lt;/impl&gt;
&lt;depends&gt;PrivilegeHandler&lt;/depends&gt;
&lt;!-- if CACHED or TRANSACTIONAL: --&gt;
&lt;!--depends&gt;PersistenceHandler&lt;/depends--&gt;
&lt;Properties&gt;
&lt;dataStoreMode&gt;EMPTY|TRANSIENT|CACHED|TRANSACTIONAL&lt;/dataStoreMode&gt;
&lt;dataStoreFile&gt;StrolchModel.xml&lt;/dataStoreFile&gt;
&lt;/Properties&gt;
&lt;/Component&gt;
...
&lt;/env&gt;
&lt;/StrolchConfiguration&gt;
</pre>
<p>A multi-realm configuration would be as follows. Note how the <code>defaultRealm</code> is still enabled, and
has its configuration as before. Further the PostgreSQL <code>PersistenceHandler</code> is configured to
show how the realms are connected to the persistence handler:</p>
<pre>
&lt;StrolchConfiguration&gt;
&lt;env id="dev"&gt;
...
&lt;Component&gt;
&lt;name&gt;RealmHandler&lt;/name&gt;
&lt;api&gt;li.strolch.agent.api.RealmHandler&lt;/api&gt;
&lt;impl&gt;li.strolch.agent.impl.DefaultRealmHandler&lt;/impl&gt;
&lt;depends&gt;PrivilegeHandler&lt;/depends&gt;
&lt;depends&gt;PersistenceHandler&lt;/depends&gt;
&lt;Properties&gt;
&lt;realms&gt;defaultRealm, cachedRealm, transactionalRealm&lt;/realms&gt;
&lt;dataStoreMode&gt;TRANSIENT&lt;/dataStoreMode&gt;
&lt;dataStoreFile&gt;DefaultRealm.xml&lt;/dataStoreFile&gt;
&lt;dataStoreMode.transactionalRealm&gt;TRANSACTIONAL&lt;/dataStoreMode.transactionalRealm&gt;
&lt;dataStoreMode.cachedRealm&gt;CACHED&lt;/dataStoreMode.cachedRealm&gt;
&lt;dataStoreMode.emptyRealm&gt;EMPTY&lt;/dataStoreMode.emptyRealm&gt;
&lt;/Properties&gt;
&lt;/Component&gt;
&lt;Component&gt;
&lt;name&gt;PersistenceHandler&lt;/name&gt;
&lt;api&gt;li.strolch.persistence.api.PersistenceHandler&lt;/api&gt;
&lt;impl&gt;li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler&lt;/impl&gt;
&lt;Properties&gt;
&lt;allowSchemaCreation&gt;true&lt;/allowSchemaCreation&gt;
&lt;allowSchemaDrop&gt;true&lt;/allowSchemaDrop&gt;
&lt;db.url.transactionalRealm&gt;jdbc:postgresql://localhost/testdb1&lt;/db.url.transactionalRealm&gt;
&lt;db.username.transactionalRealm&gt;testuser1&lt;/db.username.transactionalRealm&gt;
&lt;db.password.transactionalRealm&gt;test&lt;/db.password.transactionalRealm&gt;
&lt;db.pool.maximumPoolSize.transactionalRealm&gt;1&lt;/db.pool.maximumPoolSize.transactionalRealm&gt;
&lt;db.url.cachedRealm&gt;jdbc:postgresql://localhost/testdb2&lt;/db.url.cachedRealm&gt;
&lt;db.username.cachedRealm&gt;testuser2&lt;/db.username.cachedRealm&gt;
&lt;db.password.cachedRealm&gt;test&lt;/db.password.cachedRealm&gt;
&lt;db.pool.maximumPoolSize.cachedRealm&gt;1&lt;/db.pool.maximumPoolSize.cachedRealm&gt;
&lt;/Properties&gt;
&lt;/Component&gt;
...
&lt;/env&gt;
&lt;/StrolchConfiguration&gt;
</pre>
<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>
<pre>
ComponentContainer container = getAgent().getContainer();
StrolchRealm realm = container.getRealm(StrolchConstants.DEFAULT_REALM);
try(StrolchTransaction tx = realm.openTx()) {
Resource resource = tx.getResourceBy("TestType", "MyTestResource");
...
}
</pre>
<!-- content here -->
</div>
<!-- /.content -->
<div id="footer">
<div class="container">
<p class="text-muted">&copy; Strolch / <a href="mailto:eitch@eitchnet.ch">Robert von Burg</a> / Hosting by
<a href="http://www.eitchnet.ch">eitchnet.ch</a></p>
</div>
</div>
</div>
<!-- /.container -->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual xsd as needed -->
<script src="js/bootstrap.min.js"></script>
<!-- Piwik -->
<script type="text/javascript">
var _paq = _paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function () {
var u = (("https:" == document.location.protocol) ? "https" : "http") + "://piwik.eitchnet.ch/";
_paq.push(['setTrackerUrl', u + 'piwik.php']);
_paq.push(['setSiteId', 2]);
var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
g.type = 'text/javascript';
g.defer = true;
g.async = true;
g.src = u + 'piwik.js';
s.parentNode.insertBefore(g, s);
})();
</script>
<noscript><p><img src="http://piwik.eitchnet.ch/piwik.php?idsite=2" style="border:0;" alt=""/></p></noscript>
<!-- End Piwik Code -->
</body>
</html>