[Minor] cleanup formatting
This commit is contained in:
parent
1d151822e0
commit
a684877410
|
@ -40,23 +40,29 @@ Registering for updates is done by registering an Observer on the
|
||||||
ObserverHandler of the realm itself:
|
ObserverHandler of the realm itself:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
ObserverHandler observerHandler = container.getRealm(StrolchConstants.DEFAULT_REALM).getObserverHandler();
|
public class Example {
|
||||||
observerHandler.registerObserver(Tags.RESOURCE, new Observer() {
|
public static void main(String[] args) {
|
||||||
|
|
||||||
@Override
|
ObserverHandler observerHandler = container
|
||||||
public void update(String key, List<StrolchRootElement> elements) {
|
.getRealm(StrolchConstants.DEFAULT_REALM).getObserverHandler();
|
||||||
logger.info(elements.size() + " resources were updated!");
|
observerHandler.registerObserver(Tags.RESOURCE, new Observer() {
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void remove(String key, List<StrolchRootElement> elements) {
|
public void update(String key, List<StrolchRootElement> elements) {
|
||||||
logger.info(elements.size() + " resources were removed!");
|
logger.info(elements.size() + " resources were updated!");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(String key, List<StrolchRootElement> elements) {
|
public void remove(String key, List<StrolchRootElement> elements) {
|
||||||
logger.info(elements.size() + " resources were added!");
|
logger.info(elements.size() + " resources were removed!");
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
@Override
|
||||||
|
public void add(String key, List<StrolchRootElement> elements) {
|
||||||
|
logger.info(elements.size() + " resources were added!");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ following shows defining two policies on a Resource, a PlanningPolicy, an
|
||||||
ExecutionPolicy in XML:
|
ExecutionPolicy in XML:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<Resource ...>
|
<Resource Id="myResource" Name="My Resource" Type="MyType">
|
||||||
...
|
...
|
||||||
<Policies>
|
<Policies>
|
||||||
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
<Policy Type="PlanningPolicy" Value="key:SimplePlanning" />
|
||||||
|
@ -42,62 +42,66 @@ ExecutionPolicy in XML:
|
||||||
</Resource>
|
</Resource>
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% notice tip %}} Note how the PlanningPolicy has a value of key:SimplePlanning
|
{{% notice tip %}} Note how the `PlanningPolicy` has a value of `key:SimplePlanning`
|
||||||
and the ExecutionPolicy defines a reference to an actual class. {{% /notice %}}
|
and the `ExecutionPolicy` defines a reference to an actual class. {{% /notice %}}
|
||||||
|
|
||||||
To use the PolicyHandler, it must be configured in the StrolchConfiguration.xml
|
To use the `PolicyHandler`, it must be configured in the `StrolchConfiguration.xml`
|
||||||
as follows:
|
as follows:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
<StrolchConfiguration>
|
||||||
<Component>
|
<env id="dev">
|
||||||
<name>PolicyHandler</name>
|
<Component>
|
||||||
<api>li.strolch.policy.PolicyHandler</api>
|
<name>PolicyHandler</name>
|
||||||
<impl>li.strolch.policy.DefaultPolicyHandler</impl>
|
<api>li.strolch.policy.PolicyHandler</api>
|
||||||
<Properties>
|
<impl>li.strolch.policy.DefaultPolicyHandler</impl>
|
||||||
<readPolicyFile>true</readPolicyFile>
|
<Properties>
|
||||||
<policyConfigFile>StrolchPolicies.xml</policyConfigFile>
|
<readPolicyFile>true</readPolicyFile>
|
||||||
</Properties>
|
<policyConfigFile>StrolchPolicies.xml</policyConfigFile>
|
||||||
</Component>
|
</Properties>
|
||||||
|
</Component>
|
||||||
|
</env>
|
||||||
|
</StrolchConfiguration>
|
||||||
```
|
```
|
||||||
|
|
||||||
And this policy handler implementation requires a file where the lookups for the
|
And this policy handler implementation requires a file where the lookups for the
|
||||||
policies is defined, e.g.:
|
policies is defined, e.g.:
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
|
|
||||||
<StrolchPolicies>
|
<StrolchPolicies>
|
||||||
|
<PolicyType Type="PlanningPolicy" Api="li.strolch.policytest.TestPlanningPolicy">
|
||||||
<PolicyType Type="PlanningPolicy"
|
<Policy Key="SimplePlanning" Class="li.strolch.policytest.TestSimplePlanningPolicy"/>
|
||||||
Api="li.strolch.policytest.TestPlanningPolicy">
|
|
||||||
<Policy Key="SimplePlanning"
|
|
||||||
Class="li.strolch.policytest.TestSimplePlanningPolicy"/>
|
|
||||||
</PolicyType>
|
</PolicyType>
|
||||||
|
<PolicyType Type="ExecutionPolicy" Api="li.strolch.execution.policy.ExecutionPolicy">
|
||||||
<PolicyType Type="ConfirmationPolicy"
|
<Policy Key="SimulatedExecution" Class="li.strolch.execution.policy.RandomDurationExecution"/>
|
||||||
Api="li.strolch.policytest.TestConfirmationPolicy">
|
</PolicyType>
|
||||||
<Policy Key="NoConfirmation"
|
<PolicyType Type="ConfirmationPolicy" Api="li.strolch.policytest.TestConfirmationPolicy">
|
||||||
Class="li.strolch.policytest.TestNoConfirmationPolicy"/>
|
<Policy Key="NoConfirmation" Class="li.strolch.policytest.TestNoConfirmationPolicy"/>
|
||||||
</PolicyType>
|
</PolicyType>
|
||||||
|
|
||||||
</StrolchPolicies>
|
</StrolchPolicies>
|
||||||
```
|
```
|
||||||
|
|
||||||
Now at runtime we can access the policies:
|
Now at runtime we can access the policies:
|
||||||
|
|
||||||
```java
|
```java
|
||||||
PolicyHandler policyHandler=getComponent(PolicyHandler.class);
|
public class MyService extends AbstractService<ServiceArgument, ServiceResult> {
|
||||||
|
@Override
|
||||||
|
protected ServiceResult internalDoService(ServiceArgument arg) throws Exception {
|
||||||
|
try (StrolchTransaction tx = openArgOrUserTx(arg)) {
|
||||||
|
Resource res = tx.getResourceBy("MyType", "myTestResource");
|
||||||
|
|
||||||
try(StrolchTransaction tx=openTx()){
|
PolicyDef planningPolicyDef = res.getPolicyDef(PlanningPolicy.class);
|
||||||
Resource res=tx.getResourceBy("TestType","MyTestResource");
|
PlanningPolicy planningPolicy = tx.getPolicy(planningPolicyDef);
|
||||||
PolicyDefs policyDefs=res.getPolicyDefs();
|
planningPolicy.plan(...);
|
||||||
|
|
||||||
PolicyDef planningPolicyDef=policyDefs.getPolicyDef("PlanningPolicy");
|
PolicyDef executionPolicyDef = res.getPolicyDef(ExecutionPolicy.class);
|
||||||
PlanningPolicy planningPolicy=policyHandler.getPolicy(planningPolicyDef,tx);
|
ExecutionPolicy executionPolicy = tx.getPolicy(executionPolicyDef);
|
||||||
planningPolicy.plan(...);
|
executionPolicy.toExecution(...);
|
||||||
|
|
||||||
PolicyDef executionPolicyDef=res.getPolicyDefs().getPolicyDef("ExecutionPolicy");
|
tx.commitOnClose();
|
||||||
ExecutionPolicy executionPolicy=policyHandler.getPolicy(executionPolicyDef,tx);
|
}
|
||||||
executionPolicy.execute(...);
|
|
||||||
|
return ServiceResult.success();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
Loading…
Reference in New Issue