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 ./diningTo run examples use:
run ./calc Main run ./dining Main run ./dining Main fast run ./sort Main run ./sort SortingBenchmark
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import org.taj.ajava.lang.*;
public class AComponent extends Actor
{
protected Component component;
private FrameKeyListener keyListener;
public final ComponentAccessor getComponent;
public final Event OnKeyTyped = new Event();
public AComponent(Component c)
{
getComponent = new ComponentAccessor(c);
component = c;
keyListener = new FrameKeyListener();
component.addKeyListener(keyListener);
}
public static class ComponentAccessor extends Actor
{
private Component c;
public ComponentAccessor(Component c)
{
this.c = c;
}
public static class Get
{
}
private static class GetRequestMessage extends org.taj.ajava.runtime.ActorRequestMessage
{
public Get value;
public GetRequestMessage(final org.taj.ajava.lang.Actor rsvp, final int reqId)
{
super(rsvp, reqId);
}
}
private void react_0(GetRequestMessage requestMessage)
{
Get g = requestMessage.value;
{
Response responseMessage = new Response(requestMessage);
responseMessage.value = c;
requestMessage.sendReply(responseMessage);
return;
}
}
public void deliver(GetRequestMessage requestMessage)
{
bufferMessage(new org.taj.ajava.runtime.ActorMessage(requestMessage, 0));
}
protected void react(GetRequestMessage requestMessage)
{
react_0(requestMessage);
}
public static class Request
{
public static GetRequestMessage create(final org.taj.ajava.lang.Actor rsvp, final int reqId, final Get value)
{
GetRequestMessage m = new GetRequestMessage(rsvp, reqId);
m.value = value;
return m;
}
}
public static class Response extends org.taj.ajava.runtime.ActorResponseMessage
{
public Component value;
private Response(final org.taj.ajava.runtime.ActorRequestMessage request)
{
super(request);
}
}
protected void processMessage(org.taj.ajava.runtime.ActorMessage msg)
{
switch (msg.reactorId) {
case 0:
{
react_0(((GetRequestMessage)msg.payload));
return;
}
default:
{
super.processMessage(msg);
return;
}
}
}
}
private class FrameKeyListener extends KeyAdapter
{
public void keyTyped(KeyEvent e)
{
OnKeyTyped.deliver(new KeyboardEvent(e.getKeyChar()));
}
}
}