Permalink
Browse files

Hello world example

  • Loading branch information...
1 parent fc8aafe commit 3b81c8c83aac914ea1a3c82c634ecf3ba46e1442 @laforge49 committed Apr 22, 2012
@@ -0,0 +1,29 @@
+package org.agilewiki.jid.basics;
+
+import org.agilewiki.jactor.Mailbox;
+import org.agilewiki.jactor.RP;
+import org.agilewiki.jid.Jid;
+
+public class HelloWorld extends Jid implements Main {
+ public HelloWorld(final Mailbox mailbox) {
+ super(mailbox);
+ }
+
+ /**
+ * The application method for processing requests sent to the actor.
+ *
+ * @param request A request.
+ * @param rp The response processor.
+ * @throws Exception Any uncaught exceptions raised while processing the request.
+ */
+ @Override
+ protected void processRequest(Object request, RP rp) throws Exception {
+ if (request.getClass() == Proc.class) {
+ System.out.println("Hello world!");
+ rp.processResponse(null);
+ return;
+ }
+
+ super.processRequest(request, rp);
+ }
+}
@@ -0,0 +1,35 @@
+package org.agilewiki.jid.basics;
+
+import junit.framework.TestCase;
+import org.agilewiki.jactor.*;
+import org.agilewiki.jactor.factory.JAFactory;
+import org.agilewiki.jactor.factory.NewActor;
+import org.agilewiki.jid.GetSerializedBytes;
+import org.agilewiki.jid.ReadableBytes;
+import org.agilewiki.jid.ResolvePathname;
+import org.agilewiki.jid.scalar.vlens.actor.RootJid;
+import org.agilewiki.jid.scalar.vlens.actor.SetActor;
+
+public class HelloWorldTest extends TestCase {
+ public void test()
+ throws Exception {
+ MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(1);
+ Mailbox mailbox = mailboxFactory.createMailbox();
+ JAFuture future = new JAFuture();
+ JAFactory factory = new JAFactory(mailbox);
+ factory.defineActorType("root", RootJid.class);
+ factory.defineActorType("hi", HelloWorld.class);
+
+ RootJid root = (RootJid) (new NewActor("root")).call(factory);
+ (new SetActor("hi")).send(future, root);
+ byte[] rootBytes = GetSerializedBytes.req.send(future, root);
+
+ ReadableBytes rb = new ReadableBytes(rootBytes, 0);
+ RootJid root2 = (RootJid) (new NewActor("root")).call(factory);
+ root2.load(rb);
+ Actor a = (new ResolvePathname("0")).send(future, root2);
+ Proc.req.send(future, a);
+
+ mailboxFactory.close();
+ }
+}
@@ -0,0 +1,6 @@
+package org.agilewiki.jid.basics;
+
+import org.agilewiki.jactor.lpc.TargetActor;
+
+public interface Main extends TargetActor {
+}
@@ -0,0 +1,13 @@
+package org.agilewiki.jid.basics;
+
+import org.agilewiki.jactor.Actor;
+import org.agilewiki.jactor.lpc.Request;
+
+public class Proc extends Request<Object, Main> {
+ public final static Proc req = new Proc();
+
+ @Override
+ public boolean isTargetType(Actor targetActor) {
+ return targetActor instanceof Main;
+ }
+}

0 comments on commit 3b81c8c

Please sign in to comment.