ix/examples/index.html 100644 151 144 4536 7210476032 13370 0 ustar jeff aiai
File: ix/examples/index.html Author: Jeff Daltonix/examples/PicoISim.java 100644 151 144 16074 7210510113 13717 0 ustar jeff aiai /* Author: Jeff DaltonUpdated: Mon Nov 27 15:22:02 2000 by Jeff Dalton This directory contains a simple version of an I-X framework plus examples of its use. PicoIX.java A "very small" IX that provides simple definitions of classes Issue, IssueHandler, Constraint, ConstraintManager, ConstraintAssociator, IX_System and Controller. They are defined as static classes within the PicoIX class, so that the whole thing can go in one file, and they have been designed so that the framework can be modified and extended in a object-oriented way. PicoIXTest1.java A simple example that shows how to define issue handlers, create an IX_System that uses those handlers, and tell the system of "events" that become Issues. It also shows one of the ways to use PicoIX when writing an application: refer to PicoIX classes using qualified names such as PicoIX.Issue. PicoIXTest2.java Another simple example. It shows how to define and use new Controller and IssueHandler subclasses. It also shows the other way to use PicoIX: define a PicoIX subclass that contains the application. PicoISim.java Shows how to extend PicoIX for a particular application type, in this case discrete event simulation. PicoISimTest1.java A very simple simulation example. PicoISimTest2.java An example that shows one way to extend PicoISim to create a simulator that treats each tick of simulated time as one second of real time. PicoISimTest3.java A more elaborate example that involves simple resource constraints and a corresponding constraint-manager. SimResource.java An example constraint / constraint-manager pair suitable for use with PicoISim, defined as local (static) classes within a containing class.
*
* It also shows how to use PicoIX by defining a PicoIX subclass
* that contains the application.
*/
public class PicoIXTest2 extends PicoIX {
/**
* Main program.
*/
public static void main(String[] argv) {
IX_System example = new IX_System(new TestController(), null);
example.addIssueHandlers(makeTestIssueHandlers());
example.setListener(new IX_SystemListener());
example.start();
example.newEvent
(new Issue("twice", new Issue("return", "hello")));
example.newEvent
(new Issue("stop"));
}
/**
* A Controller that supports pushIssue().
*/
static class TestController extends Controller {
TestController() {}
protected void pushIssue(Issue i) { // move to subclass /\/
Debug.noteln("Pushing", i);
issues.pushElement(i);
}
}
/**
* IssueHandlers that can use pushIssue().
*/
static abstract class TestIssueHandler extends IssueHandler {
TestIssueHandler(Object verb) {
super(verb);
}
void pushIssue(Issue i) {
((TestController)system.controller).pushIssue(i);
}
}
/**
* Create issue handlers as "instant" subclasses of TestIssueHandler.
*/
static Object[] makeTestIssueHandlers() {
return new Object[] {
// Post an issue twice.
new TestIssueHandler("twice") {
void handleIssue(Issue i) {
pushIssue((Issue)i.object);
pushIssue((Issue)i.object);
}
},
// Send something to the listener.
new TestIssueHandler("return") {
void handleIssue(Issue i) {
system.notifyListener(i.object);
}
},
// Stop the system.
new TestIssueHandler("stop") {
void handleIssue(Issue i) {
system.stop();
}
}
};
}
}
ix/examples/SimResource.java 100644 151 144 5546 7207516525 14510 0 ustar jeff aiai /* Author: Jeff Dalton