当前位置: 首页>>代码示例>>Java>>正文


Java AbstractActor类代码示例

本文整理汇总了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()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:27,代码来源:CoffeeHouseTest.java

示例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()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-with-akka,代码行数:27,代码来源:CoffeeHouseTest.java

示例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()));
    }};
}
 
开发者ID:ironfish,项目名称:oreilly-reactive-architecture-old,代码行数:25,代码来源:CoffeeHouseTest.java

示例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);
		}
	}
}
 
开发者ID:chanan,项目名称:AkkaGuice,代码行数:24,代码来源:AkkaGuiceModule.java

示例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);
        }
    }
}
 
开发者ID:chanan,项目名称:AkkaGuice,代码行数:19,代码来源:AkkaGuiceModule.java

示例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();
}
 
开发者ID:henrikengstrom,项目名称:ujug2017,代码行数:13,代码来源:DatabaseActor.java

示例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);
}
 
开发者ID:bertilmuth,项目名称:requirementsascode,代码行数:6,代码来源:Akka.java


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