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

Event.java

home Home   up Up   ( Download )


import java.util.*; import org.taj.ajava.lang.*; public class Event extends Actor { private List subscribers; public Event() { subscribers = new ArrayList(); } public static class Subscribe { Actor a; public Subscribe(Actor a) { this.a = a; } } private void react_0(Subscribe s) { subscribers.add(s.a); } public void deliver(Subscribe s) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(s, 0)); } protected void react(Subscribe s) { react_0(s); } public static class Unsubscribe { Actor a; public Unsubscribe(Actor a) { this.a = a; } } private void react_1(Unsubscribe s) { subscribers.remove(s.a); } public void deliver(Unsubscribe s) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(s, 1)); } protected void react(Unsubscribe s) { react_1(s); } private static class SendAll extends ListIterator { private Object msg; public SendAll(List list, Object msg) { super(list); this.msg = msg; } private void react_3(Object target) { Actor.sendMessage(target, msg); } public void deliver(Object target) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(target, 3)); } protected void react(Object target) { react_3(target); } protected void processMessage(org.taj.ajava.runtime.ActorMessage msg) { switch (msg.reactorId) { case 3: { react_3(((Object)msg.payload)); return; } default: { super.processMessage(msg); return; } } } } private void react_2(Object msg) { SendAll sndr = new SendAll(subscribers, msg); sndr.deliver(new ListIterator.Run()); } public void deliver(Object msg) { bufferMessage(new org.taj.ajava.runtime.ActorMessage(msg, 2)); } protected void react(Object msg) { react_2(msg); } protected void processMessage(org.taj.ajava.runtime.ActorMessage msg) { switch (msg.reactorId) { case 0: { react_0(((Subscribe)msg.payload)); return; } case 1: { react_1(((Unsubscribe)msg.payload)); return; } case 2: { react_2(((Object)msg.payload)); return; } default: { super.processMessage(msg); return; } } } }