本文整理汇总了Java中akka.actor.AbstractActor类的典型用法代码示例。如果您正苦于以下问题:Java AbstractActor类的具体用法?Java AbstractActor怎么用?Java AbstractActor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractActor类属于akka.actor包,在下文中一共展示了AbstractActor类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure
import akka.actor.AbstractActor; //导入依赖的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() {
@Override
public Receive createReceive() {
return 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()));
}};
}
示例2: shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure
import akka.actor.AbstractActor; //导入依赖的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() {
@Override
public Receive createReceive() {
return 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()));
}};
}
示例3: shouldRestartWaiterAndResendPrepareCoffeeToBaristaOnFailure
import akka.actor.AbstractActor; //导入依赖的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()));
}};
}
示例4: RegisterActors
import akka.actor.AbstractActor; //导入依赖的package包/类
private static void RegisterActors(Binder binder) {
Logger.debug("Actor Scanner Started...");
final Map<String, ActorHolder> map = new HashMap<>();
final ConfigurationBuilder configBuilder = build();
final Reflections reflections = new Reflections(configBuilder.setScanners(new SubTypesScanner()));
final Set<Class<? extends UntypedActor>> actors = reflections.getSubTypesOf(UntypedActor.class);
final Set<Class<? extends AbstractActor>> abstractActors = reflections.getSubTypesOf(AbstractActor.class);
loopOnActors(map, actors);
loopOnAbstractActors(map, abstractActors);
if(!map.isEmpty()) Logger.debug("Registering actors: ");
for(final String key : map.keySet()) {
final ActorHolder actorHolder = map.get(key);
final Class<? extends Actor> actor = actorHolder.getActor();
if(actorHolder.isSingleton()) {
Logger.debug("Binding class " + actor.getSimpleName() + " to name: " + key + " Singleton Scoped.");
binder.bind(ActorRef.class).annotatedWith(Names.named(key)).toProvider(new ActorRefProvider(actor, key, true)).in(Singleton.class);
} else {
Logger.debug("Binding class " + actor.getSimpleName() + " to name: " + key + " Request Scoped.");
binder.bind(ActorRef.class).annotatedWith(Names.named(key)).toProvider(new ActorRefProvider(actor, key, false));
PropsContext.put(key, actorHolder);
}
}
}
示例5: loopOnAbstractActors
import akka.actor.AbstractActor; //导入依赖的package包/类
private static void loopOnAbstractActors(Map<String, ActorHolder> map, Set<Class<? extends AbstractActor>> actors) {
for(final Class<? extends Actor> actor : actors) {
if(ignore.contains(actor.getSimpleName())) continue;
final String named = getNamed(actor);
final boolean isSingleton = isSingleton(actor);
final ActorHolder actorHolder = new ActorHolder(actor, isSingleton);
if(named != null) {
map.put(named, actorHolder);
} else {
if(map.containsKey(actor.getSimpleName())){
map.put(actor.getName(), actorHolder);
final ActorHolder tempHolder = map.remove(actor.getSimpleName());
map.put(tempHolder.getActor().getName(), tempHolder);
}
else map.put(actor.getSimpleName(), actorHolder);
}
}
}
示例6: createReceive
import akka.actor.AbstractActor; //导入依赖的package包/类
public AbstractActor.Receive createReceive() {
return receiveBuilder()
.match(BackendActor.Identifiers.class, identifiers -> {
long totalTime = 0l;
for (long id : identifiers.ids) {
long simulatedDatabaseCallTime = id;
Thread.sleep(simulatedDatabaseCallTime);
totalTime += simulatedDatabaseCallTime;
}
getSender().tell("DB CALL TIME = " + totalTime + "ms\n", getSender());
}).build();
}
示例7: spawn
import akka.actor.AbstractActor; //导入依赖的package包/类
static <T> ActorRef spawn(String actorName, ActorSystem system, Class<? extends AbstractActor> actorClass,
Object... constructorParams) {
Props props = Props.create(actorClass, constructorParams);
return system.actorOf(props, actorName);
}