Package akka.actor

Examples of akka.actor.ActorRef


  public static void main(String[] args) {
    final int iterations = 10000;
    int length = 100000;
    System.out.println("iterations=" + iterations + ", length=" + length + ", total=" + (iterations * length));

    ActorRef accumulator = actorOf(new UntypedActorFactory() {
      public UntypedActor create() {
        return new Accumulator(iterations);
      }
    }).start();

    // (0,99999), (100000,199999), (200000,299999), (300000,399999)...
    for (int x = 0; x < iterations; x++) {
      ActorRef worker = actorOf(Worker.class).start();
      int start = x * length;
      int end = (x + 1) * length - 1;
      worker.sendOneWay(new Range(start, end), accumulator);
    }
  }
View Full Code Here


import akka.actor.UntypedActor;
import akka.actor.UntypedActorFactory;

public class PublisherMain {
  public static void main(String[] args) {
    ActorRef publisher = actorOf(new UntypedActorFactory() {
      public UntypedActor create() {
        return new Publisher("tcp://*:5555", new StringFormat());
      }
    }).start();

    int count = 0;
    while (true) {
      publisher.sendOneWay("Message " + count++);

      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
        e.printStackTrace();
View Full Code Here

  public static void main(String[] args) {
    final JLabel temperature = new JLabel("-");
    final JLabel humidity = new JLabel("-");

    // UntypedActor
    final ActorRef sensor = actorOf(WeatherSensor.class).start();
    final ActorRef ui = actorOf(new UntypedActorFactory() {
      public UntypedActor create() {
        return new WeatherUI(sensor, temperature, humidity);
      }
    }).start();
View Full Code Here

    @Before public void initialise() {
        counters = new ArrayList<ActorRef>();
        for (int i = 1; i <= numCounters; i++) {
            final String name = "counter" + i;
            ActorRef counter = UntypedActor.actorOf(new UntypedActorFactory() {
                public UntypedActor create() {
                    return new UntypedCounter(name);
                }
            });
            counter.start();
            counters.add(counter);
        }
        failer = UntypedActor.actorOf(UntypedFailer.class);
        failer.start();
    }
View Full Code Here

    public static void main(String[] args) throws InterruptedException {
        System.out.println();
        System.out.println("Untyped transactor example");
        System.out.println();

        ActorRef counter1 = UntypedActor.actorOf(UntypedCoordinatedCounter.class).start();
        ActorRef counter2 = UntypedActor.actorOf(UntypedCoordinatedCounter.class).start();

        counter1.sendOneWay(new Coordinated(new Increment(counter2)));

        Thread.sleep(3000);

        Future future1 = counter1.sendRequestReplyFuture("GetCount");
        Future future2 = counter2.sendRequestReplyFuture("GetCount");

        future1.await();
        if (future1.isCompleted()) {
            if (future1.result().isDefined()) {
                int result = (Integer) future1.result().get();
                System.out.println("counter 1: " + result);
            }
        }

        future2.await();
        if (future2.isCompleted()) {
            if (future2.result().isDefined()) {
                int result = (Integer) future2.result().get();
                System.out.println("counter 2: " + result);
            }
        }

        counter1.stop();
        counter2.stop();
    }
View Full Code Here

    public static void main(String[] args) throws InterruptedException {
        System.out.println();
        System.out.println("Untyped transactor example");
        System.out.println();

        ActorRef counter1 = UntypedActor.actorOf(UntypedCounter.class).start();
        ActorRef counter2 = UntypedActor.actorOf(UntypedCounter.class).start();

        counter1.sendOneWay(new Increment(counter2));

        Thread.sleep(3000);

        Future future1 = counter1.sendRequestReplyFuture("GetCount");
        Future future2 = counter2.sendRequestReplyFuture("GetCount");

        future1.await();
        if (future1.isCompleted()) {
            if (future1.result().isDefined()) {
                int result = (Integer) future1.result().get();
                System.out.println("counter 1: " + result);
            }
        }

        future2.await();
        if (future2.isCompleted()) {
            if (future2.result().isDefined()) {
                int result = (Integer) future2.result().get();
                System.out.println("counter 2: " + result);
            }
        }

        counter1.stop();
        counter2.stop();
    }
View Full Code Here

    @Before public void initialise() {
        counters = new ArrayList<ActorRef>();
        for (int i = 1; i <= numCounters; i++) {
            final String name = "counter" + i;
            ActorRef counter = UntypedActor.actorOf(new UntypedActorFactory() {
                public UntypedActor create() {
                    return new UntypedCoordinatedCounter(name);
                }
            });
            counter.start();
            counters.add(counter);
        }
        failer = UntypedActor.actorOf(UntypedFailer.class);
        failer.start();
    }
View Full Code Here

import com.typesafe.config.ConfigFactory;

public class BettingProcessorApplication {
    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("BettingProcessorActorSystem", ConfigFactory.load());
        ActorRef bettingProcessor = system.actorOf(new Props(BettingProcessor.class), "bettingProcessor");
    }
View Full Code Here

                "}");
        return ActorSystem.create("TestActorSystem", config);
    }

    private void sendMessages(ActorSystem system) {
        ActorRef service = getService(system);
        for (int i = 0; i < 200; i++) {
            service.tell(new Bet("ready_player_one", i % 10 + 1, i % 100 + 1));
        }
        System.out.println("*** SENDING OK");
    }
View Full Code Here

        }
        System.out.println("*** SENDING OK");
    }

    private void retrieveMessages(ActorSystem system) throws Exception {
        ActorRef service = getService(system);
        Timeout timeout = new Timeout(Duration.create(2, TimeUnit.SECONDS));
        Future<Object> fBets = Patterns.ask(service, new RetrieveBets(), timeout);
        List<Bet> bets = (List<Bet>) Await.result(fBets, timeout.duration());
        assert bets.size() == 200;
        System.out.println("*** TESTING OK");
View Full Code Here

TOP

Related Classes of akka.actor.ActorRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.