4. The JActor jar file
● Download Jactor-3.1.0.zip from
https://sourceforge.net/projects/jactor/files/
● Extract jactor-3.1.0.jar from the zip file and copy
it to a new directory, GettingStarted.
● (The JActor version will change—current
version is 3.1.0.)
5. Create a Test Environment
● Create a j.bat file in the GettingStarted
directory:
del *.class
call javac -classpath jactor-3.1.0.jar *.java
call java -classpath .;jactor-3.1.0.jar GettingStarted
● The j.bat file can be used to run a test.
6. Basic Code Samples
● Hello world!
● Actor <==> Actor
● RP Games
● Parallel Programming
● Dependency Injection
● Exception Handling
● Loops
8. GettingStarted.java
(main)
import org.agilewiki.jactor.*;
public class GettingStarted {
public static void main(String[] args) throws Exception {
MailboxFactory mailboxFactory =
JAMailboxFactory.newMailboxFactory(10);
Mailbox mailbox = mailboxFactory.createMailbox();
JAFuture future = new JAFuture();
Test test = new Test();
test.initialize(mailbox);
Start.req.send(future, test);
mailboxFactory.close();
}
}
9. Test.java
(actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;
public class Test extends JLPCActor {
public void start(RP rp) throws Exception {
System.out.println("Hello world!");
rp.processResponse(null);
}
}
10. Start.java
(request)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;
public class Start extends Request<Object, Test> {
public static final Start req = new Start();
public void processRequest(JLPCActor targetActor, RP rp)
throws Exception {
Test a = (Test) targetActor;
a.start(rp);
}
public boolean isTargetType(Actor targetActor) {
return targetActor instanceof Test;
}
}
23. Test.java
(actor)
public class Test extends JLPCActor {
public void start(final RP rp) throws Exception {
Timer timer1 = new Timer();
timer1.initialize(
getMailboxFactory().createAsynchronousMailbox());
Timer timer2 = new Timer();
timer2.initialize(
getMailboxFactory().createAsynchronousMailbox());
final long t0 = System.currentTimeMillis();
RP prp = new RP() {
boolean pending = true;
public void processResponse(Object obj) throws Exception {
if (pending) pending = false;
else {
System.out.println(System.currentTimeMillis()-t0);
rp.processResponse(null);
}
}
};
(new Delay(1000)).send(this, timer1, prp);
(new Delay(1000)).send(this, timer2, prp);
}
}
24. Timer.java
(actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;
public class Timer extends JLPCActor {
public void delay(int ms, RP rp) throws Exception {
Thread.sleep(ms);
rp.processResponse(null);
}
}
25. Delay.java
(request)
public class Delay extends Request<Object, Timer> {
public final int ms;
public Delay(int ms) {
this.ms = ms;
}
public void processRequest(JLPCActor targetActor, RP rp)
throws Exception {
Timer a = (Timer) targetActor;
a.delay(ms, rp);
}
public boolean isTargetType(Actor targetActor) {
return targetActor instanceof Timer;
}
}
39. Test.java
(actor)
public class Test extends JLPCActor {
public void start(RP rp) throws Exception {
Printer printer = new Printer();
printer.initialize(getMailbox());
final int max = 5;
(new JAIterator() {
int i = 0;
protected void process(RP irp) throws Exception {
if (i == max) irp.processResponse("done");
else {
i += 1;
(new Print(""+i)).
send(Test.this, printer, irp);
}
}
}).iterate(rp);
}
}
43. Test.java
(actor)
import org.agilewiki.jactor.*;
import org.agilewiki.jactor.lpc.*;
public class Test extends JLPCActor {
public void start(RP rp) throws Exception {
Printer printer = new Printer();
printer.initialize(getMailbox());
SMBuilder smb = new SMBuilder();
smb._send(printer, new Print("a"));
smb._send(printer, new Print("b"));
smb._send(printer, new Print("c"));
smb.call(rp);
}
}