Let's create a system with one part that prints out the classic "Hello World".
The Hello World part:
package uhr.tutorial.system01;
import uhr.core.role.StateCommandable;
import uhr.core.role.StateCommandableAide;
import uhr.core.role.StateCommandableAideFactory;
public class PartA implements StateCommandable {
//---------- Internal Fields -------------------------------------
protected StateCommandableAide stateAide =
StateCommandableAideFactory.createAide("RunTest", this);
//---------- StateCommandable Implementation ---------------------
public StateCommandableAide getStateCommandableAide() {
return stateAide;
}
public void doStateCommand(String command) {
if (command.equals("RunTest")) {
System.out.println("Hello World");
}
}
} // End class
All systems require a pointer of some kind to what DK storage to use. We offer a very simple, non-database approach that uses what we call "class markers", or you can provide a custom DK storage mechansm, such as one that uses a host or database. A class marker is a Java class that marks the root directory containing the DK for the System Tree of containers and parts. For simplicity we will combine our marker class with the class that starts the system.
The marker and starter class:
package uhr.tutorial.system01;
import uhr.core.cell.NodeCreator;
/**
* This class is an example of how to start a system.
* The class also serves as the system marker class.
* Note the dk file mentioned in the url. It defines
* the root container's location.
*/
public class StartSystem {
public static void main(String args[]) {
String url = "classresource://uhr.tutorial.system01.StartSystem/_Container.dk";
new NodeCreator().createAndStartSystem(url);
}
} // End class
There's one more thing necessary for the minimal system - the DK the root container needs. This is in XML.
The Root Container DK:
<partdk>
<parts>
<part>
<name>HelloThere</name>
<type>uhr.tutorial.system01.PartA</type>
</part>
</parts>
<start_commands>
<invocation>
<part>HelloThere</part>
<command>RunTest</command>
</invocation>
</start_commands>
</partdk>
Notice the container DK has one part named "HelloThere". That same part name is used in the start_commands section to send the command "RunTest" to the part. To start the system enter:
java uhr.tutorial.system01.StartSystem
This naturally gives the expected output of "Hello World". If you've done all this yourself from scratch, congratulations on your first UHR system!!! Let's summarize what we learned here. A minimal system consists of:
Go to the next lesson.