Package akka.transactor

Examples of akka.transactor.Coordinated


  }

  @Override
  public void onReceive(Object o) throws Exception {
    if (o instanceof Coordinated) {
      Coordinated coordinated = (Coordinated) o;
      final Object message = coordinated.getMessage();
      if (message instanceof AccountDebit) {
        coordinated.atomic(new Runnable() {
          public void run() {
            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");
            }
          }
        });

      } else if (message instanceof AccountCredit) {
        coordinated.atomic(new Runnable() {
          public void run() {
            AccountCredit accCredit = (AccountCredit) message;
            float bal = balance.get() + accCredit.getAmount();
            balance.set(bal);
          }
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

  @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

        System.out.println();

        ActorRef counter1 = UntypedActor.actorOf(UntypedCoordinatedCounter.class).start();
        ActorRef counter2 = UntypedActor.actorOf(UntypedCoordinatedCounter.class).start();

        counter1.sendOneWay(new Coordinated(new Increment(counter2)));

        Thread.sleep(3000);

        Future future1 = counter1.sendRequestReplyFuture("GetCount");
        Future future2 = counter2.sendRequestReplyFuture("GetCount");
View Full Code Here

        count.set(count.get() + 1);
    }

    public void onReceive(Object incoming) throws Exception {
        if (incoming instanceof Coordinated) {
            Coordinated coordinated = (Coordinated) incoming;
            Object message = coordinated.getMessage();
            if (message instanceof Increment) {
                Increment increment = (Increment) message;
                List<ActorRef> friends = increment.getFriends();
                final CountDownLatch latch = increment.getLatch();
                if (!friends.isEmpty()) {
                    Increment coordMessage = new Increment(friends.subList(1, friends.size()), latch);
                    friends.get(0).sendOneWay(coordinated.coordinate(coordMessage));
                }
                coordinated.atomic(new Atomically(txFactory) {
                    public void atomically() {
                        increment();
                        StmUtils.scheduleDeferredTask(new Runnable() {
                            public void run() { latch.countDown(); }
                        });
View Full Code Here

    }

    @Test public void incrementAllCountersWithSuccessfulTransaction() {
        CountDownLatch incrementLatch = new CountDownLatch(numCounters);
        Increment message = new Increment(counters.subList(1, counters.size()), incrementLatch);
        counters.get(0).sendOneWay(new Coordinated(message));
        try {
            incrementLatch.await(timeout, TimeUnit.SECONDS);
        } catch (InterruptedException exception) {}
        for (ActorRef counter : counters) {
            Future future = counter.sendRequestReplyFuture("GetCount");
View Full Code Here

    @Test public void incrementNoCountersWithFailingTransaction() {
        CountDownLatch incrementLatch = new CountDownLatch(numCounters);
        List<ActorRef> actors = new ArrayList<ActorRef>(counters);
        actors.add(failer);
        Increment message = new Increment(actors.subList(1, actors.size()), incrementLatch);
        actors.get(0).sendOneWay(new Coordinated(message));
        try {
            incrementLatch.await(timeout, TimeUnit.SECONDS);
        } catch (InterruptedException exception) {}
        for (ActorRef counter : counters) {
            Future future = counter.sendRequestReplyFuture("GetCount");
View Full Code Here

        count.set(count.get() + 1);
    }

    public void onReceive(Object incoming) throws Exception {
        if (incoming instanceof Coordinated) {
            Coordinated coordinated = (Coordinated) incoming;
            Object message = coordinated.getMessage();
            if (message instanceof Increment) {
                Increment increment = (Increment) message;
                if (increment.hasFriend()) {
                    increment.getFriend().sendOneWay(coordinated.coordinate(new Increment()));
                }
                coordinated.atomic(new Atomically() {
                    public void atomically() {
                        increment();
                    }
                });
            }
View Full Code Here

TOP

Related Classes of akka.transactor.Coordinated

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.