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

Examples of org.akka.essentials.stm.transactor.example2.msg.AccountCredit


    @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


        public void run() {
          // credit amount - will always be successful
          to.tell(coordinated.coordinate(new AccountCredit(transfer
              .getAmtToBeTransferred())));
          // debit amount - throws an exception if funds insufficient
          from.tell(coordinated.coordinate(new AccountDebit(transfer
              .getAmtToBeTransferred())));
        }
      });
    } else if (message instanceof AccountBalance) {
View Full Code Here

  // default method to be overridden
  @Override
  public void atomically(Object message) throws Exception {
    if (message instanceof AccountDebit) {
      AccountDebit accDebit = (AccountDebit) message;
      // check for funds availability
      if (balance.get() > accDebit.getAmount()) {
        float bal = balance.get() - accDebit.getAmount();
        balance.set(bal);
      } else {
        throw new IllegalStateException("Insufficient Balance");
      }
View Full Code Here

    }

    @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

  @Override
  public void onReceive(Object message) throws Exception {

    if (message instanceof TransferMsg) {
      final TransferMsg transfer = (TransferMsg) message;
      final Coordinated coordinated = new Coordinated(timeout);

      coordinated.atomic(new Runnable() {
        public void run() {
          // credit amount - will always be successful
          to.tell(coordinated.coordinate(new AccountCredit(transfer
              .getAmtToBeTransferred())));
          // debit amount - throws an exception if funds insufficient
          from.tell(coordinated.coordinate(new AccountDebit(transfer
              .getAmtToBeTransferred())));
        }
      });
    } else if (message instanceof AccountBalance) {
View Full Code Here

    BankApplication bankApp = new BankApplication();

    bankApp.showBalances();

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

    bankApp.showBalances();

    bankApp.bank.tell(new TransferMsg(Float.valueOf("1400")));

    bankApp.showBalances();

    bankApp.bank.tell(new TransferMsg(Float.valueOf("3500")));

    bankApp.showBalances();

    bankApp._system.shutdown();
View Full Code Here

TOP

Related Classes of org.akka.essentials.stm.transactor.example2.msg.AccountCredit

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.