Package org.akka.essentials.stm.transactor.example.msg

Examples of org.akka.essentials.stm.transactor.example.msg.AccountBalance


  }

  private void showBalances() {
    try {
      Thread.sleep(2000);
      bank.tell(new AccountBalance("XYZ"));
      bank.tell(new AccountBalance("ABC"));

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
View Full Code Here


        TestActorRef<BankActor> bank = TestActorRef.apply(new Props(
                BankActor.class), _system);

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

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

        Assert.assertEquals(Float.parseFloat("3223"), balance.getBalance(),
                Float.parseFloat("0"));

        balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("ABC"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("2777"), balance.getBalance(),
                Float.parseFloat("0"));
    }
View Full Code Here

        TestActorRef<BankActor> bank = TestActorRef.apply(new Props(
                BankActor.class), _system);

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

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

        Assert.assertEquals(Float.parseFloat("3500"), balance.getBalance(),
                Float.parseFloat("0"));

        balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("ABC"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("2500"), balance.getBalance(),
                Float.parseFloat("0"));

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

        Thread.sleep(2000);

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

        Assert.assertEquals(Float.parseFloat("3500"), balance.getBalance(),
                Float.parseFloat("0"));

        balance = (AccountBalance) Await.result(
                ask(bank, new AccountBalance("ABC"), 5000),
                Duration.create("5 second"));

        Assert.assertEquals(Float.parseFloat("2500"), balance.getBalance(),
                Float.parseFloat("0"));
    }
View Full Code Here

  @Override
  public void onReceive(Object message) throws Exception {
    if (message instanceof TransferMsg) {
      transfer.tell(message);
    } else if (message instanceof AccountBalance) {
      AccountBalance account = (AccountBalance) Await.result(
          ask(transfer, message, 5000), Duration.create("5 second"));

      System.out.println("Account #" + account.getAccountNumber()
          + " , Balance " + account.getBalance());
     
      getSender().tell(account);
    }

  }
View Full Code Here

              .getAmtToBeTransferred())));
        }
      });
    } else if (message instanceof AccountBalance) {

      AccountBalance accBalance = (AccountBalance) message;
      // check the account number and return the balance
      if (accBalance.getAccountNumber().equals(fromAccount)) {
        from.tell(accBalance, sender());
      }
      if (accBalance.getAccountNumber().equals(toAccount)) {
        to.tell(accBalance, sender());
      }
    }
  }
View Full Code Here

          }
        });
      }
    } else if (o instanceof AccountBalance) {
      // reply with the account balance
      sender().tell(new AccountBalance(accountNumber, balance.get()));
    } else
      unhandled(o);
  }
View Full Code Here

TOP

Related Classes of org.akka.essentials.stm.transactor.example.msg.AccountBalance

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.