ActiveJava

Copyright Tristan Aubrey-Jones May 2008.

Abstract: A project investigating and developing an implicitly concurrent programming language, based on a metaphor taken from the physical world is reported. Uses a programming paradigm where programs consist of systems of autonomous agents, or active objects which communicate via message passing. A language enhancing Java with actors and linear types is presented. Example programs are written, compiled, and executed to evaluate the usefulness of the language. The language found to provide a familiar notation for implicit parallelism, and a compelling new model for concurrency, combining the performance of shared variables with the elegance of message passing.

Introductory Slides (PDF), Report (PDF),
ActiveJava compiler prototype (ajavac), ActiveJava runtime library (ajava_lang).

Examples:

calc - pocket calculator actor program
dining - dining philosophers actor program (never deadlocks)
sort - parallel quicksort implementation ("SortBenchmark" sorts 10,000 random integers using actors, java threads, and sequentially and compares)
To compile examples use:
compile.bat ./calc
compile.bat ./sort
compile.bat ./dining
To run examples use:
run ./calc Main
run ./dining Main
run ./dining Main fast
run ./sort Main
run ./sort SortingBenchmark

NumberBox.java

home Home   up Up   ( Download )


import javax.swing.*; import org.taj.ajava.lang.*; public class NumberBox extends AComponent { protected JTextField textField; private boolean reset = false; private boolean donePoint = false; public final Event OnOperation = new Event(); public NumberBox() { super(new JTextField(15)); textField = ((JTextField)component); textField.setHorizontalAlignment(JTextField.RIGHT); textField.setText("0"); } private void react_0(char c) { if (Character.isDigit(c)) { if (reset) { textField.setText("" + c); reset = false; } else if (textField.getText().equals("0")) { if (c != '0') textField.setText("" + c); } else { textField.setText(textField.getText() + "" + c); } } else if (c == '.' && !donePoint) { textField.setText(textField.getText() + '.'); donePoint = true; } } public void deliver(char c) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(new Character(c), 0)); } protected void react(char c) { react_0(c); } private void react_1(Calculator.Operation op) { op.operand = Double.parseDouble(textField.getText()); OnOperation.deliver(op); } public void deliver(Calculator.Operation op) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(op, 1)); } protected void react(Calculator.Operation op) { react_1(op); } private void react_2(double v) { textField.setText(Double.toString(v)); reset = true; donePoint = false; } public void deliver(double v) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(new Double(v), 2)); } protected void react(double v) { react_2(v); } protected void processMessage(org.taj.ajava.runtime.ActorMessage msg) { switch (msg.reactorId) { case 0: { react_0(((Character)msg.payload).charValue()); return; } case 1: { react_1(((Calculator.Operation)msg.payload)); return; } case 2: { react_2(((Double)msg.payload).doubleValue()); return; } default: { super.processMessage(msg); return; } } } }