Package akka.actor

Examples of akka.actor.ActorRef


   * @throws Exception
   */
  public static void main(String[] args) throws Exception {
    ActorSystem _system = ActorSystem
        .create("ScatterGatherFirstCompletedRouterExample");
    ActorRef scatterGatherFirstCompletedRouter = _system.actorOf(new Props(
        RandomTimeActor.class)
        .withRouter(new ScatterGatherFirstCompletedRouter(5, Duration
            .create(2, "seconds"))),
        "myScatterGatherFirstCompletedRouterActor");

View Full Code Here


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

    for (int i = 1; i <= 10; i++) {
      //sends messages in a round robin way to all the actors
      roundRobinRouter.tell(i);
      if (i == 5) {
        TimeUnit.MILLISECONDS.sleep(100);
        System.out.println("\n");
      }
    }
View Full Code Here

    CalculatorInt calculator = TypedActor.get(_system).typedActorOf(
        new TypedProps<SupervisorActor>(CalculatorInt.class,
            SupervisorActor.class),"supervisorActor");

    // Get access to the ActorRef
    ActorRef calActor = TypedActor.get(_system).getActorRefFor(calculator);
    // call actor with a message
    calActor.tell("Hi there",calActor);
   
    //wait for child actor to get restarted
    Thread.sleep(500);
   
    // Invoke the method and wait for result
View Full Code Here

        super(_system);
    }

    @Test
    public void successTest() throws Exception {
        ActorRef bank = _system.actorOf(new Props(BankActor.class));
        bank.tell(new TransferMsg(Float.valueOf("1777")));

        AccountBalance balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("XYZ"), 5000),
                Duration.create("5 second"));
View Full Code Here

    }

    @Test
    public void failureTest() throws Exception {
        ActorRef bank = _system.actorOf(new Props(BankActor.class));

        bank.tell(new TransferMsg(Float.valueOf("5500")));

        // sleeping to allow some time for actors to be restarted
        Thread.sleep(4000);

        AccountBalance balance = (AccountBalance) Await.result(
View Full Code Here

    }

    @Test
    public void accountTest() throws Exception {
        ActorRef bank = _system.actorOf(new Props(BankActor.class));

        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountCredit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("1000")));
        bank.tell(new AccountDebit(Float.parseFloat("3500")));
        bank.tell(new AccountCredit(Float.parseFloat("2500")));
        bank.tell(new AccountDebit(Float.parseFloat("3500")));

        // sleeping to allow some time for all messages to be processed
        Thread.sleep(4000);

        AccountBalance balance = (AccountBalance) Await.result(
View Full Code Here

  }

  @Test
  public void testEchoActor() {
    ActorRef echoActorRef = _system.actorOf(new Props(EchoActor.class));
    // pass the reference to implicit sender testActor() otherwise
    // message end up in dead mailbox
    echoActorRef.tell("Hi there", super.testActor());
    expectMsg("Hi there");
  }
View Full Code Here

    expectMsg("Hi there");
  }

  @Test
  public void testForwardingActor() {
    ActorRef forwardingActorRef = _system.actorOf(new Props(
        new UntypedActorFactory() {
          public UntypedActor create() {
            return new ForwardingActor(testActor());
          }
        }));
    // pass the reference to implicit sender testActor() otherwise
    // message end up in dead mailbox
    forwardingActorRef.tell("test message", super.testActor());
    expectMsg("test message");
  }
View Full Code Here

    for (int i = 0; i < randomHead; i++)
      headList.add(i);
    for (int i = 1; i < randomTail; i++)
      tailList.add(i);

    ActorRef sequencingActorRef = _system.actorOf(new Props(
        new UntypedActorFactory() {
          public UntypedActor create() {
            return new SequencingActor(testActor(), headList,
                tailList);
          }
        }));

    // pass the reference to implicit sender testActor() otherwise
    // message end up in dead mailbox
    sequencingActorRef.tell("do something", super.testActor());

    for (Integer value : headList) {
      expectMsgClass(Integer.class);
    }
    expectMsg("do something");
View Full Code Here

    expectNoMsg();
  }

  @Test
  public void testFilteringActor() {
    ActorRef filteringActorRef = _system.actorOf(new Props(
        new UntypedActorFactory() {
          public UntypedActor create() {
            return new FilteringActor(testActor());
          }
        }));
    // pass the reference to implicit sender testActor() otherwise
    // message end up in dead mailbox
    // first test
    filteringActorRef.tell("test message", super.testActor());
    expectMsg("test message");
    // second test
    filteringActorRef.tell(1, super.testActor());
    expectNoMsg();
  }
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.