Search in sources :

Example 1 with ServerActor

use of co.paralleluniverse.actors.behaviors.ServerActor in project quasar by puniverse.

the class Server method main.

public static void main(String[] args) throws ExecutionException, InterruptedException {
    System.setProperty("galaxy.nodeId", Integer.toString(nodeId));
    System.setProperty("galaxy.port", Integer.toString(7050 + nodeId));
    System.setProperty("galaxy.slave_port", Integer.toString(8050 + nodeId));
    new Fiber(new ServerActor(new AbstractServerHandler<SumRequest, Integer, SumRequest>() {

        @Override
        public void init() throws SuspendExecution {
            super.init();
            Actor.currentActor().register("myServer");
            System.out.println(this.toString() + " is ready");
        }

        @Override
        public Integer handleCall(ActorRef<?> from, Object id, SumRequest m) {
            System.out.println(this.toString() + " is handling " + m);
            if (m.a == 0 && m.b == 0)
                ServerActor.currentServerActor().shutdown();
            return m.a + m.b;
        }
    })).start().join();
    System.exit(0);
}
Also used : ServerActor(co.paralleluniverse.actors.behaviors.ServerActor) ActorRef(co.paralleluniverse.actors.ActorRef) Fiber(co.paralleluniverse.fibers.Fiber) AbstractServerHandler(co.paralleluniverse.actors.behaviors.AbstractServerHandler)

Aggregations

ActorRef (co.paralleluniverse.actors.ActorRef)1 AbstractServerHandler (co.paralleluniverse.actors.behaviors.AbstractServerHandler)1 ServerActor (co.paralleluniverse.actors.behaviors.ServerActor)1 Fiber (co.paralleluniverse.fibers.Fiber)1