本文整理汇总了Java中akka.japi.pf.ReceiveBuilder类的典型用法代码示例。如果您正苦于以下问题:Java ReceiveBuilder类的具体用法?Java ReceiveBuilder怎么用?Java ReceiveBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReceiveBuilder类属于akka.japi.pf包,在下文中一共展示了ReceiveBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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()
);
}
示例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()
);
}
示例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()
);
}
示例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()));
}};
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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()
);
}
示例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());
}
示例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());
}
示例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());
}