• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ReceiveBuilder类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中akka.japi.pf.ReceiveBuilder的典型用法代码示例。如果您正苦于以下问题:Java ReceiveBuilder类的具体用法?Java ReceiveBuilder怎么用?Java ReceiveBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ReceiveBuilder类属于akka.japi.pf包,在下文中一共展示了ReceiveBuilder类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: Guest

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Guest(ActorRef waiter, Coffee favoriteCoffee, FiniteDuration finishCoffeeDuration, int caffeineLimit) {
    this.waiter = waiter;
    this.favoriteCoffee = favoriteCoffee;
    this.finishCoffeeDuration = finishCoffeeDuration;
    this.caffeineLimit = caffeineLimit;
    orderFavoriteCoffee();

    receive(ReceiveBuilder.
            match(Waiter.CoffeeServed.class, coffeeServed -> coffeeServed.coffee.equals(favoriteCoffee), coffeeServed -> {
                coffeeCount++;
                log().info("Enjoying my {} yummy {}!", coffeeCount, coffeeServed.coffee);
                scheduleCoffeeFinished();
            }).
            match(Waiter.CoffeeServed.class, coffeeServed -> {
                log().info("Expected a {}, but got a {}!", favoriteCoffee, coffeeServed.coffee);
                waiter.tell(new Waiter.Complaint(favoriteCoffee), self());
            }).
            match(CoffeeFinished.class, coffeeFinished -> coffeeCount > this.caffeineLimit, coffeeFinished -> {
                throw new CaffeineException();
            }).
            match(CoffeeFinished.class, coffeeFinished ->
                    orderFavoriteCoffee()
            ).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:27,代码来源:Guest.java


示例2: Waiter

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Waiter(ActorRef coffeeHouse, ActorRef barista, int maxComplaintCount) {
    this.coffeeHouse = coffeeHouse;
    this.barista = barista;
    this.maxComplaintCount = maxComplaintCount;

    receive(ReceiveBuilder.
            match(ServeCoffee.class, serveCoffee ->
                    this.coffeeHouse.tell(new CoffeeHouse.ApproveCoffee(serveCoffee.coffee, sender()), self())
            ).
            match(Barista.CoffeePrepared.class, coffeePrepared ->
                    coffeePrepared.guest.tell(new CoffeeServed(coffeePrepared.coffee), self())
            ).
            match(Complaint.class, complaint -> complaintCount == this.maxComplaintCount, complaint -> {
                throw new FrustratedException(complaint.coffee, sender());
            }).
            match(Complaint.class, complaint -> {
                complaintCount++;
                this.barista.tell(new Barista.PrepareCoffee(complaint.coffee, sender()), self());
            }).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:23,代码来源:Waiter.java


示例3: CoffeeHouse

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public CoffeeHouse(int caffeineLimit) {
    log().debug("CoffeeHouse Open");
    this.caffeineLimit = caffeineLimit;

    receive(ReceiveBuilder.
            match(CreateGuest.class, createGuest -> {
                final ActorRef guest = createGuest(createGuest.favoriteCoffee, createGuest.caffeineLimit);
                addGuestToBookkeeper(guest);
                context().watch(guest);
            }).
            match(ApproveCoffee.class, this::coffeeApproved, approveCoffee ->
                    barista.forward(new Barista.PrepareCoffee(approveCoffee.coffee, approveCoffee.guest), context())
            ).
            match(ApproveCoffee.class, approveCoffee -> {
                log().info("Sorry, {}, but you have reached your limit.", approveCoffee.guest.path().name());
                context().stop(approveCoffee.guest);
            }).
            match(Terminated.class, terminated -> {
                log().info("Thanks, {}, for being our guest!", terminated.getActor());
                removeGuestFromBookkeeper(terminated.getActor());
            }).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:25,代码来源:CoffeeHouse.java


示例4: shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
@Test
public void shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure() {
    new JavaTestKit(system) {{
        createActor(CoffeeHouse.class, "resend-prepare-coffee", () -> new CoffeeHouse(Integer.MAX_VALUE) {
            @Override
            protected ActorRef createBarista() {
                return getRef();
            }

            @Override
            protected ActorRef createWaiter() { //stubbing out the waiter actor to always throw exception
                return context().actorOf(Props.create(AbstractActor.class, () -> new AbstractActor() {{
                    receive(
                            ReceiveBuilder.matchAny(o -> {
                                throw new Waiter.FrustratedException(new Coffee.Akkaccino(), system.deadLetters());
                            }).build());
                }}), "waiter");
            }
        });
        ActorRef waiter = expectActor(this, "/user/resend-prepare-coffee/waiter");
        waiter.tell("Blow up", ActorRef.noSender());
        expectMsgEquals(new Barista.PrepareCoffee(new Coffee.Akkaccino(), system.deadLetters()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:25,代码来源:CoffeeHouseTest.java


示例5: Waiter

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Waiter(ActorRef coffeeHouse, ActorRef barista, int maxComplaintCount) {
        this.coffeeHouse = coffeeHouse;
        this.barista = barista;
        this.maxComplaintCount = maxComplaintCount;

        receive(ReceiveBuilder.
                match(ServeCoffee.class, serveCoffee ->
                        this.coffeeHouse.tell(new CoffeeHouse.ApproveCoffee(serveCoffee.coffee, sender()), self())
                ).
                match(Barista.CoffeePrepared.class, coffeePrepared ->
                        coffeePrepared.guest.tell(new CoffeeServed(coffeePrepared.coffee), self())
                ).
//                match(Complaint.class, complaint -> complaintCount == this.maxComplaintCount, complaint -> {
//                    throw new FrustratedException(complaint.coffee, sender());
//                }).
                match(Complaint.class, complaint -> {
                    complaintCount++;
                    this.barista.tell(new Barista.PrepareCoffee(complaint.coffee, sender()), self());
                }).
                matchAny(this::unhandled).build()
        );
    }
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:23,代码来源:Waiter.java


示例6: Guest

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Guest(ActorRef waiter, Coffee favoriteCoffee, FiniteDuration finishCoffeeDuration) {
    this.waiter = waiter;
    this.favoriteCoffee = favoriteCoffee;
    this.finishCoffeeDuration = finishCoffeeDuration;
    orderFavoriteCoffee();

    receive(ReceiveBuilder.
            match(Waiter.CoffeeServed.class, coffeeServed -> {
                coffeeCount++;
                log().info("Enjoying my {} yummy {}!", coffeeCount, coffeeServed.coffee);
                scheduleCoffeeFinished();
            }).
            match(CoffeeFinished.class, coffeeFinished ->
                    orderFavoriteCoffee()
            ).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:19,代码来源:Guest.java


示例7: Guest

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Guest(ActorRef waiter, Coffee favoriteCoffee, FiniteDuration finishCoffeeDuration, int caffeineLimit) {
    this.waiter = waiter;
    this.favoriteCoffee = favoriteCoffee;
    this.finishCoffeeDuration = finishCoffeeDuration;
    this.caffeineLimit = caffeineLimit;
    orderFavoriteCoffee();

    receive(ReceiveBuilder.
            match(Waiter.CoffeeServed.class, coffeeServed -> {
                coffeeCount++;
                log().info("Enjoying my {} yummy {}!", coffeeCount, coffeeServed.coffee);
                scheduleCoffeeFinished();
            }).
            match(CoffeeFinished.class, coffeeFinished -> coffeeCount > this.caffeineLimit, coffeeFinished -> {
                throw new CaffeineException();
            }).
            match(CoffeeFinished.class, coffeeFinished ->
                    orderFavoriteCoffee()
            ).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:23,代码来源:Guest.java


示例8: CoffeeHouse

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public CoffeeHouse(int caffeineLimit) {
        log().debug("CoffeeHouse Open");
        this.caffeineLimit = caffeineLimit;

        receive(ReceiveBuilder.
                match(CreateGuest.class, createGuest -> {
                    final ActorRef guest = createGuest(createGuest.favoriteCoffee);
//                    final ActorRef guest = createGuest(createGuest.favoriteCoffee, createGuest.caffeineLimit);
                    addGuestToBookkeeper(guest);
                    context().watch(guest);
                }).
                match(ApproveCoffee.class, this::coffeeApproved, approveCoffee ->
                        barista.forward(new Barista.PrepareCoffee(approveCoffee.coffee, approveCoffee.guest), context())
                ).
                match(ApproveCoffee.class, approveCoffee -> {
                    log().info("Sorry, {}, but you have reached your limit.", approveCoffee.guest.path().name());
                    context().stop(approveCoffee.guest);
                }).
                match(Terminated.class, terminated -> {
                    log().info("Thanks, {}, for being our guest!", terminated.getActor());
                    removeGuestFromBookkeeper(terminated.getActor());
                }).
                matchAny(this::unhandled).build()
        );
    }
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:26,代码来源:CoffeeHouse.java


示例9: CoffeeHouse

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public CoffeeHouse(int caffeineLimit) {
        log().debug("CoffeeHouse Open");
        this.caffeineLimit = caffeineLimit;

        receive(ReceiveBuilder.
                match(CreateGuest.class, createGuest -> {
                    final ActorRef guest = createGuest(createGuest.favoriteCoffee);
                    addGuestToBookkeeper(guest);
//                    context().watch(guest);
                }).
                match(ApproveCoffee.class, this::coffeeApproved, approveCoffee ->
                        barista.forward(new Barista.PrepareCoffee(approveCoffee.coffee, approveCoffee.guest), context())
                ).
                match(ApproveCoffee.class, approveCoffee -> {
                    log().info("Sorry, {}, but you have reached your limit.", approveCoffee.guest.path().name());
                    context().stop(approveCoffee.guest);
                }).
//                match(Terminated.class, terminated -> {
//                    log().info("Thanks, {}, for being our guest!", terminated.getActor());
//                    removeGuestFromBookkeeper(terminated.getActor());
//                }).
                matchAny(this::unhandled).build()
        );
    }
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:25,代码来源:CoffeeHouse.java


示例10: CoffeeHouse

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public CoffeeHouse(int caffeineLimit) {
    log().debug("CoffeeHouse Open");
    this.caffeineLimit = caffeineLimit;

    receive(ReceiveBuilder.
            match(CreateGuest.class, createGuest -> {
                final ActorRef guest = createGuest(createGuest.favoriteCoffee);
                addGuestToBookkeeper(guest);
            }).
            match(ApproveCoffee.class, this::coffeeApproved, approveCoffee ->
                    barista.forward(new Barista.PrepareCoffee(approveCoffee.coffee, approveCoffee.guest), context())
            ).
            match(ApproveCoffee.class, approveCoffee -> {
                log().info("Sorry, {}, but you have reached your limit.", approveCoffee.guest.path().name());
                context().stop(approveCoffee.guest);
            }).
            matchAny(this::unhandled).build()
    );
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:20,代码来源:CoffeeHouse.java


示例11: Guest

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Guest(ActorRef waiter, Coffee favoriteCoffee, FiniteDuration finishCoffeeDuration, int caffeineLimit) {
        this.waiter = waiter;
        this.favoriteCoffee = favoriteCoffee;
        this.finishCoffeeDuration = finishCoffeeDuration;
        this.caffeineLimit = caffeineLimit;
        orderFavoriteCoffee();

        receive(ReceiveBuilder.
                match(Waiter.CoffeeServed.class, coffeeServed -> coffeeServed.coffee.equals(favoriteCoffee), coffeeServed -> {
                    coffeeCount++;
                    log().info("Enjoying my {} yummy {}!", coffeeCount, coffeeServed.coffee);
                    scheduleCoffeeFinished();
                }).
//                match(Waiter.CoffeeServed.class, coffeeServed -> {
//                    log().info("Expected a {}, but got a {}!", favoriteCoffee, coffeeServed.coffee);
//                    waiter.tell(new Waiter.Complaint(favoriteCoffee), self());
//                }).
                match(CoffeeFinished.class, coffeeFinished -> coffeeCount > this.caffeineLimit, coffeeFinished -> {
                    throw new CaffeineException();
                }).
                match(CoffeeFinished.class, coffeeFinished ->
                        orderFavoriteCoffee()
                ).
                matchAny(this::unhandled).build()
        );
    }
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:27,代码来源:Guest.java


示例12: Waiter

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public Waiter(ActorRef coffeeHouse, ActorRef barista) {
        this.coffeeHouse = coffeeHouse;
        this.barista = barista;
//        this.maxComplaintCount = maxComplaintCount;

        receive(ReceiveBuilder.
                match(ServeCoffee.class, serveCoffee ->
                        this.coffeeHouse.tell(new CoffeeHouse.ApproveCoffee(serveCoffee.coffee, sender()), self())
                ).
                match(Barista.CoffeePrepared.class, coffeePrepared ->
                        coffeePrepared.guest.tell(new CoffeeServed(coffeePrepared.coffee), self())
                ).
//                match(Complaint.class, complaint -> complaintCount == this.maxComplaintCount, complaint -> {
//                    throw new FrustratedException();
//                }).
                match(Complaint.class, complaint -> {
                    complaintCount++;
                    this.barista.tell(new Barista.PrepareCoffee(complaint.coffee, sender()), self());
                }).
                matchAny(this::unhandled).build()
        );
    }
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:23,代码来源:Waiter.java


示例13: ParseSupervisorActor

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public ParseSupervisorActor() {
  receive(
      ReceiveBuilder.match(ParseMessageCreateCommand.class, this::handleParseMessageCreateCommand)
          .match(ParseMessageCreatedEvent.class, this::handleParseMessageCreatedEvent)
          .match(ParsedMessageEvent.class, this::handleParsedMessageEvent)
          .match(WorkflowFinishedEvent.class, this::handleWorkflowFinishedEvent)
          .matchAny(o -> LOG.warn("Unhandled message [{}]", o)).build());
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:9,代码来源:ParseSupervisorActor.java


示例14: ParseMessageActor

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public ParseMessageActor() {
  receive(ReceiveBuilder
      .match(ParseMessageCreateCommand.class,
          cmd -> getDBPersistenceActor().tell(cmd, getContext().parent()))
      .match(ParseMessageCommand.class, this::handleParseMessageCommand)
      .match(ConfigRetrievedEvent.class, this::handleConfigRetrievedEvent)
      .match(NotifyProcessEngineCommand.class, this::handleNotifyProcessEngineCommand)
      .match(NotifyConfigRetrievedEvent.class, this::handleNotifyConfigRetrievedEvent)
      .matchAny(o -> LOG.warn("Unhandled message [{}]", o)).build());
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:11,代码来源:ParseMessageActor.java


示例15: ParsePersistenceActor

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
public ParsePersistenceActor() {
  receive(
      ReceiveBuilder.match(ParseMessageCreateCommand.class, this::handleParseMessageCreateCommand)
          .match(ConfigRetrievalCommand.class, this::handleConfigRetrievalCommand)
          .match(StoreInternalDataCommand.class, this::handleStoreInternalDataCommand)
          .match(NotifyProcessEngineCommand.class, this::handleNotifyProcessEngineCommand)
          .match(UpdateMessageStateCommand.class, this::handleUpdateMessageStateCommand)
          .matchAny(o -> LOG.warn("Unhandled message [{}]", o)).build());
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:10,代码来源:ParsePersistenceActor.java


示例16: createReceive

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
@Override
public Receive createReceive() {
  return ReceiveBuilder.create()
          .match(
                  PaxosAPI.Propose.class,
                  propose -> propose.txid() == txid,
                  propose -> {
                    LOG.info("Received proposal={}", propose);
                    this.proposal = propose.value();
                    broadcastNextBallot(1);
                  }
          )
          .build();
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:15,代码来源:DecreePresident.java


示例17: nextBallotSent

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
private Receive nextBallotSent() {
  return ReceiveBuilder.create()
          .match(AlreadySucceed.class, this::onAlreadySucceed)
          .match(LastVote.class,
                  lastVote -> lastVote.ballotNumber() == lastTried && lastVote.txid() == txid,
                  lastVote -> {
                    LOG.info("Received last vote from {}", lastVote);
                    lastVotes.put(sender(), lastVote);

                    if (lastVotes.size() > priests.size() / 2) {
                      LOG.info("There is a quorum");
                      final LastVote winner = Collections.max(lastVotes.values());

                      final Object lockedValue;

                      if (winner.vote() == SpecialValues.BLANK) {
                        lockedValue = proposal;
                      } else if (winner.vote() == SpecialValues.OUTDATED_BALLOT_NUMBER) {
                        LOG.info("Seems that I have outdated ballot number");
                        broadcastNextBallot(winner.ballotNumber() + 1);
                        return;
                      } else {
                        lockedValue = winner.vote();
                      }

                      priests.forEach(p -> p.tell(new BeginBallot(txid, lastTried, lockedValue), self()));
                      getContext().become(beginBallotSent());
                    }
                  })
          .build();
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:32,代码来源:DecreePresident.java


示例18: beginBallotSent

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
private Receive beginBallotSent() {
  return ReceiveBuilder.create()
          .match(AlreadySucceed.class, this::onAlreadySucceed)
          .match(Voted.class,
                  voted -> voted.ballotNumber() == lastTried && voted.txid() == txid,
                  voted -> {
                    votes.add(voted);

                    if (votes.size() > priests.size() / 2) {
                      priests.forEach(p -> p.tell(new Success(txid, voted.vote()), self()));
                      context().stop(self());
                    }
                  })
          .build();
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:16,代码来源:DecreePresident.java


示例19: createReceive

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
@Override
public Receive createReceive() {
  if (decision == null) {
    return ReceiveBuilder.create()
            .match(NextBallot.class, nextBallot -> {
              if (nextBallot.ballotNumber() > lastBallot) {
                lastBallot = nextBallot.ballotNumber();
                sender().tell(new LastVote(txid, lastBallot, lastVote), self());
              } else {
                sender().tell(new LastVote(txid, lastBallot, SpecialValues.OUTDATED_BALLOT_NUMBER), self());
                LOG.warning(
                        "NextBallot: Proposer has outdated ballotNumber number proposer={}, ballotNumber={}, currentBallot={}",
                        sender(), nextBallot.ballotNumber(), lastBallot
                );
              }
            })
            .match(BeginBallot.class, beginBallot -> {
              //FIXME: equal ballotNumber numbers may cause collisions, but they shouldn't pass NextBallot
              if (beginBallot.ballotNumber() == lastBallot) {
                lastVote = beginBallot.decree();
                sender().tell(new Voted(txid, beginBallot.ballotNumber(), beginBallot.decree()), self());
              } else {
                sender().tell(new Voted(txid, lastBallot, SpecialValues.OUTDATED_BALLOT_NUMBER), self());
                LOG.warning(
                        "BeginBallot: Proposer has outdated ballotNumber number proposer={}, ballotNumber={}, currentBallot={}",
                        sender(), beginBallot.ballotNumber(), lastBallot
                );
              }
            })
            .match(Success.class, success -> {
              LOG.info("Learned {} for txid={}", success.decree(), txid);
              decision = success.decree();
              subscriber.tell(new PaxosAPI.Decide(decision, txid), self());
              getContext().become(success());
            })
            .build();
  } else {
    return success();
  }
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:41,代码来源:DecreePriest.java


示例20: createReceive

import akka.japi.pf.ReceiveBuilder; //导入依赖的package包/类
@Override
public Receive createReceive() {
  return ReceiveBuilder.create()
          .match(PaxosMessage.class, this::onPaxosMessage)
          .match(PaxosAPI.Decide.class, this::onDecide)
          .match(Broadcast.class, this::onBroadcast)
          .build();
}
 
开发者ID:marnikitta,项目名称:Concierge,代码行数:9,代码来源:AtomicBroadcast.java



注:本文中的akka.japi.pf.ReceiveBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SerialUtilities类代码示例发布时间:2022-05-21
下一篇:
Java Permission类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap