Package akka.actor

Examples of akka.actor.ActorRef


   * @throws InterruptedException
   */
  public static void main(String[] args) throws InterruptedException {
    ActorSystem _system = ActorSystem.create("CustomRouteeRouterExample");
   
    ActorRef echoActor1 = _system.actorOf(new Props(MsgEchoActor.class));
    ActorRef echoActor2 = _system.actorOf(new Props(MsgEchoActor.class));
    ActorRef echoActor3 = _system.actorOf(new Props(MsgEchoActor.class));
   
    Iterable<ActorRef> routees = Arrays.asList(new ActorRef[] { echoActor1,
        echoActor2, echoActor3 });

    ActorRef randomRouter = _system.actorOf(new Props(MsgEchoActor.class)
        .withRouter(RandomRouter.create(routees)));

    for (int i = 1; i <= 10; i++) {
      // sends randomly to actors
      randomRouter.tell(i);
    }
    _system.shutdown();
  }
View Full Code Here


    counterResult = calculator.incrementAndReturn();
    System.out.println("Result is " + counterResult.get());

    // Get access to the ActorRef
    ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
    // call actor with a message
    calActor.tell("Hi there");
   
    _system.shutdown();

  }
View Full Code Here

    int lowerBound = 2;
    int upperBound = 15;
    DefaultResizer resizer = new DefaultResizer(lowerBound, upperBound);

    ActorRef randomRouter = _system.actorOf(new Props(MsgEchoActor.class)
        .withRouter(new RandomRouter(resizer)));

    for (int i = 1; i <= 10; i++) {
      // sends randomly to actors
      randomRouter.tell(i);
    }
    _system.shutdown();
  }
View Full Code Here

    CalculatorInt calculator2 = TypedActor.get(_system).typedActorOf(
        new TypedProps<Calculator>(CalculatorInt.class,
            Calculator.class));

    // Create a router with Typed Actors
    ActorRef actor1 = TypedActor.get(_system).getActorRefFor(calculator1);
    ActorRef actor2 = TypedActor.get(_system).getActorRefFor(calculator2);

    Iterable<ActorRef> routees = Arrays.asList(new ActorRef[] { actor1,
        actor2 });
    ActorRef router = _system.actorOf(new Props()
        .withRouter(BroadcastRouter.create(routees)));

    router.tell("Hello there");

    _system.shutdown();

  }
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {
    ActorSystem _system = ActorSystem.create("CustomRouterExample");
    ActorRef burstyMessageRouter = _system.actorOf(new Props(
        MsgEchoActor.class).withRouter(new BurstyMessageRouter(5,2)));

    for (int i = 1; i <= 13; i++) {
      //sends series of messages in a round robin way to all the actors
      burstyMessageRouter.tell(i);
    }
    _system.shutdown();

  }
View Full Code Here

  public static void main(String[] args) throws Exception {
    // TODO Auto-generated method stub
    ActorSystem system = ActorSystem.create("DurableMailBox", ConfigFactory
        .load().getConfig("myapp1"));

    ActorRef actor = system
        .actorOf(new Props(DurableMailBox.class)
            .withDispatcher("my-dispatcher"), "serverActor");

    actor.tell("Hello");

    Thread.sleep(500);

    system.shutdown();
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {
    ActorSystem _system = ActorSystem.create("SmallestMailBoxRouterExample");
    ActorRef smallestMailBoxRouter = _system.actorOf(new Props(MsgEchoActor.class)
        .withRouter(new SmallestMailboxRouter(5)),"mySmallestMailBoxRouterActor");

    for (int i = 1; i <= 10; i++) {
      //works like roundrobin but tries to rebalance the load based on
      //size of actor's mailbox
      smallestMailBoxRouter.tell(i);
    }
    _system.shutdown();

  }
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {
    ActorSystem _system = ActorSystem.create("BroadcastRouterExample");
    ActorRef broadcastRouter = _system.actorOf(new Props(MsgEchoActor.class)
        .withRouter(new BroadcastRouter(5)),"myBroadcastRouterActor");

    for (int i = 1; i <= 2; i++) {
      //same message goes to all the actors
      broadcastRouter.tell(i);
    }
    _system.shutdown();

  }
View Full Code Here

   * @param args
   * @throws InterruptedException
   */
  public static void main(String[] args) throws InterruptedException {
    ActorSystem _system = ActorSystem.create("RandomRouterExample");
    ActorRef randomRouter = _system.actorOf(new Props(MsgEchoActor.class)
        .withRouter(new RandomRouter(5)),"myRandomRouterActor");

    for (int i = 1; i <= 10; i++) {
      //sends randomly to actors
      randomRouter.tell(i);
    }
    _system.shutdown();
  }
View Full Code Here

  @Test
  public void stopAndRestartTest() throws Exception {
    TestActorRef<SupervisorActor> supervisor = TestActorRef.apply(
        new Props(SupervisorActor.class), _system);
    ActorRef workerActor = supervisor.underlyingActor().getWorker();
    TestProbe probe = new TestProbe(_system);
    probe.watch(workerActor);
    supervisor.tell("10");
    probe.expectMsgClass(Terminated.class);
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.