205 lines
8.5 KiB
HTML
205 lines
8.5 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="plc.html">PLC</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>
|
|
</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, 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>
|
|
<StrolchConfiguration>
|
|
<env id="dev">
|
|
...
|
|
<Component>
|
|
<name>RealmHandler</name>
|
|
<api>li.strolch.agent.api.RealmHandler</api>
|
|
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
|
<depends>PrivilegeHandler</depends>
|
|
<!-- if CACHED: -->
|
|
<!--depends>PersistenceHandler</depends-->
|
|
<Properties>
|
|
<dataStoreMode>EMPTY|TRANSIENT|CACHED</dataStoreMode>
|
|
<dataStoreFile>StrolchModel.xml</dataStoreFile>
|
|
</Properties>
|
|
</Component>
|
|
...
|
|
</env>
|
|
</StrolchConfiguration>
|
|
</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>
|
|
<StrolchConfiguration>
|
|
<env id="dev">
|
|
...
|
|
<Component>
|
|
<name>RealmHandler</name>
|
|
<api>li.strolch.agent.api.RealmHandler</api>
|
|
<impl>li.strolch.agent.impl.DefaultRealmHandler</impl>
|
|
<depends>PrivilegeHandler</depends>
|
|
<depends>PersistenceHandler</depends>
|
|
<Properties>
|
|
<realms>defaultRealm, cachedRealm</realms>
|
|
<dataStoreMode>TRANSIENT</dataStoreMode>
|
|
<dataStoreFile>DefaultRealm.xml</dataStoreFile>
|
|
<dataStoreMode.cachedRealm>CACHED</dataStoreMode.cachedRealm>
|
|
<dataStoreMode.emptyRealm>EMPTY</dataStoreMode.emptyRealm>
|
|
</Properties>
|
|
</Component>
|
|
|
|
<Component>
|
|
<name>PersistenceHandler</name>
|
|
<api>li.strolch.persistence.api.PersistenceHandler</api>
|
|
<impl>li.strolch.persistence.postgresql.PostgreSqlPersistenceHandler</impl>
|
|
<Properties>
|
|
<allowSchemaCreation>true</allowSchemaCreation>
|
|
<allowSchemaDrop>true</allowSchemaDrop>
|
|
|
|
<db.url.cachedRealm>jdbc:postgresql://localhost/testdb2</db.url.cachedRealm>
|
|
<db.username.cachedRealm>testuser2</db.username.cachedRealm>
|
|
<db.password.cachedRealm>test</db.password.cachedRealm>
|
|
<db.pool.maximumPoolSize.cachedRealm>1</db.pool.maximumPoolSize.cachedRealm>
|
|
</Properties>
|
|
</Component>
|
|
...
|
|
</env>
|
|
</StrolchConfiguration>
|
|
</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">© 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>
|