Permalink
Browse files

new ContinuationTest

  • Loading branch information...
1 parent fb132ac commit 3b297535a13537721bfe0a6f3834b8e8ae41036f @laforge49 committed Dec 11, 2012
Showing with 56 additions and 0 deletions.
  1. +56 −0 src/test/java/org/agilewiki/jactor/continuation/ContinuationTest.java
@@ -0,0 +1,56 @@
+package org.agilewiki.jactor.continuation;
+
+import junit.framework.TestCase;
+import org.agilewiki.jactor.*;
+import org.agilewiki.jactor.lpc.JLPCActor;
+import org.agilewiki.jactor.lpc.Request;
+
+public class ContinuationTest extends TestCase {
+ public void test() throws Exception {
+ MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
+ try {
+ Driver driver = new Driver();
+ driver.initialize(mailboxFactory.createMailbox());
+ JAFuture future = new JAFuture();
+ System.out.println(">>> " + Doit.req.send(future, driver) + " <<<");
+ } finally {
+ mailboxFactory.close();
+ }
+ }
+}
+
+class Doit extends Request<String, Driver> {
+ public static Doit req = new Doit();
+
+ @Override
+ public boolean isTargetType(Actor targetActor) {
+ return targetActor instanceof Driver;
+ }
+
+ @Override
+ public void processRequest(JLPCActor targetActor, RP rp) throws Exception {
+ ((Driver) targetActor).doit(rp);
+ }
+}
+
+class Driver extends JLPCActor {
+ void doit(RP<String> rp) {
+ Continuation continuation = new Continuation(this, rp);
+ Application applicatin = new Application();
+ applicatin.continuation = continuation;
+ applicatin.start();
+ }
+}
+
+class Application extends Thread {
+ Continuation continuation;
+
+ @Override
+ public void run() {
+ try {
+ continuation.response("Hello world!");
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}

0 comments on commit 3b29753

Please sign in to comment.