Package akka.actor

Examples of akka.actor.ActorSystem


        }
    }

    public static void main(String[] args) {
        // Create the 'helloakka' actor system
        final ActorSystem system = ActorSystem.create("helloakka");

        // Create the 'greeter' actor
        final ActorRef greeter = system.actorOf(Props.create(Greeter.class), "greeter");

        // Create the "actor-in-a-box"
        final Inbox inbox = Inbox.create(system);

        // Tell the 'greeter' to change its 'greeting' message
        greeter.tell(new WhoToGreet("akka"), ActorRef.noSender());

        // Ask the 'greeter for the latest 'greeting'
        // Reply should go to the "actor-in-a-box"
        inbox.send(greeter, new Greet());

        // Wait 5 seconds for the reply with the 'greeting' message
        Greeting greeting1 = (Greeting) inbox.receive(Duration.create(5, TimeUnit.SECONDS));
        System.out.println("Greeting: " + greeting1.message);

        // Change the greeting and ask for it again
        greeter.tell(new WhoToGreet("typesafe"), ActorRef.noSender());
        inbox.send(greeter, new Greet());
        Greeting greeting2 = (Greeting) inbox.receive(Duration.create(5, TimeUnit.SECONDS));
        System.out.println("Greeting: " + greeting2.message);

        // after zero seconds, send a Greet message every second to the greeter with a sender of the GreetPrinter
        ActorRef greetPrinter = system.actorOf(Props.create(GreetPrinter.class));
        system.scheduler().schedule(Duration.Zero(), Duration.create(1, TimeUnit.SECONDS), greeter, new Greet(), system.dispatcher(), greetPrinter);
        //system.shutdown();
    }
View Full Code Here


   * }}}
   *
   * @return ActorSystem
   */
  public static ActorSystem system() {
    ActorSystem applicationSystem = AkkaPlugin.applicationSystem;
    if (applicationSystem == null) {
      throw new RuntimeException("Akka plugin is not registered.");
    }
    return applicationSystem;
  }
View Full Code Here

  }

  private ActorSystem applicationSystem() {
    applicationSystemEnabled = true;
    Config akkaConf = ConfigFactory.load(config);
    ActorSystem system = ActorSystem.create("application", akkaConf);
    logger.info("Starting application default Akka system.");
    return system;
  }
View Full Code Here

  public void calculate(final int nrOfWorkers, final int nrOfElements,
      final int nrOfMessages) {

    // Create an Akka system
    ActorSystem system = ActorSystem.create("PiSystem");

    // create the result listener, which will print the result and shutdown
    // the system
    final ActorRef listener = system.actorOf(new Props(Listener.class),
        "listener");

    // create the master
    ActorRef master = system.actorOf(new Props(new UntypedActorFactory() {
      private static final long serialVersionUID = 1L;

      public UntypedActor create() {
        return new Master(nrOfWorkers, nrOfMessages, nrOfElements,
            listener);
View Full Code Here

        }
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
  public static void main(String... args) {
        ActorSystem system = ActorSystem.create("example");

        ActorRef counter = system.actorOf(new Props(Counter.class));

        counter.tell("tick");
        counter.tell("tick");
        counter.tell("tick");

        Future future = ask(counter, "get", 5000);

        future.onSuccess(new OnSuccess<Integer>() {
            public void onSuccess(Integer count) {
                System.out.println("Count is " + count);
            }
        });

        system.shutdown();
    }
View Full Code Here

  }

  private ActorSystem applicationSystem() {
    applicationSystemEnabled = true;
    Config akkaConf = ConfigFactory.load(config);
    ActorSystem system = ActorSystem.create("application", akkaConf);
    logger.info("Starting application default Akka system.");
    return system;
  }
View Full Code Here

   * }}}
   *
   * @return ActorSystem
   */
  public static ActorSystem system() {
    ActorSystem applicationSystem = AkkaPlugin.applicationSystem;
    if (ValidateUtils.me().isNullOrEmpty(applicationSystem)) {
      throw new RuntimeException("Akka plugin is not registered.");
    }
    return applicationSystem;
  }
View Full Code Here

  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    ActorSystem system = ActorSystem.create("faultTolerance");

    LoggingAdapter log = Logging.getLogger(system, system);

    Integer originalValue = Integer.valueOf(0);

    ActorRef supervisor = system.actorOf(new Props(SupervisorActor2.class),
        "supervisor");

    log.info("Sending value 8, no exceptions should be thrown! ");
    supervisor.tell(Integer.valueOf(8));

    Integer result = (Integer) Await.result(
        Patterns.ask(supervisor, new Result(), 5000),
        Duration.create(5000, TimeUnit.MILLISECONDS));

    log.info("Value Received-> {}", result);
    assert result.equals(Integer.valueOf(8));

    log.info("Sending value -8, ArithmeticException should be thrown! Our Supervisor strategy says resume !");
    supervisor.tell(Integer.valueOf(-8));

    result = (Integer) Await.result(
        Patterns.ask(supervisor, new Result(), 5000),
        Duration.create(5000, TimeUnit.MILLISECONDS));

    log.info("Value Received-> {}", result);
    assert result.equals(Integer.valueOf(8));

    log.info("Sending value null, NullPointerException should be thrown! Our Supervisor strategy says restart !");
    supervisor.tell(null);

    result = (Integer) Await.result(
        Patterns.ask(supervisor, new Result(), 5000),
        Duration.create(5000, TimeUnit.MILLISECONDS));

    log.info("Value Received-> {}", result);
    assert originalValue.equals(result);

    log.info("Sending value \"String\", IllegalArgumentException should be thrown! Our Supervisor strategy says Stop !");

    supervisor.tell(String.valueOf("Do Something"));

    log.info("Worker Actor shutdown !");
    system.shutdown();

  }
View Full Code Here

  /**
   * @param args
   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    ActorSystem system = ActorSystem.create("faultTolerance");

    ActorRef supervisor = system.actorOf(new Props(SupervisorActor.class),
        "supervisor");

    supervisor.tell(Integer.valueOf(10));
    supervisor.tell("10");

    Thread.sleep(5000);

    supervisor.tell(Integer.valueOf(10));

    system.shutdown();
  }
View Full Code Here

import akka.actor.Props;

public class TestActorSystem {

  public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem.create("FutureUsageExample");
    ActorRef processOrder = _system.actorOf(new Props(
        ProcessOrderActor.class));
    processOrder.tell(Integer.valueOf(456));

    Thread.sleep(5000);

    _system.shutdown();
  }
View Full Code Here

TOP

Related Classes of akka.actor.ActorSystem

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.