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


Java Actor类代码示例

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


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

示例1: createTestActor

import akka.actor.Actor; //导入依赖的package包/类
/**
 * Create a test actor with the passed in name.
 *
 * @param props the actor Props
 * @param actorId name of actor
 * @param <T> the actor type
 * @return the ActorRef
 */
@SuppressWarnings("unchecked")
public <T extends Actor> TestActorRef<T> createTestActor(Props props, String actorId) {
    InvalidActorNameException lastError = null;
    for (int i = 0; i < 10; i++) {
        try {
            TestActorRef<T> actorRef = TestActorRef.create(system, props, actorId);
            return (TestActorRef<T>) addActor(actorRef, true);
        } catch (InvalidActorNameException e) {
            lastError = e;
            Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS);
        }
    }

    throw lastError;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:24,代码来源:TestActorFactory.java

示例2: FhirProxyTestKit

import akka.actor.Actor; //导入依赖的package包/类
public FhirProxyTestKit(ActorSystem actorSystem, Class<? extends Actor> context, Class<? extends MockHTTPConnector> upstreamMock) {
    super(actorSystem);
    List<MockLauncher.ActorToLaunch> testActors = new ArrayList<>();
    testActors.add(new MockLauncher.ActorToLaunch("fhir-context", context));
    testActors.add(new MockLauncher.ActorToLaunch("http-connector", upstreamMock));
    TestingUtils.launchActors(system, testConfig.getName(), testActors);
    expectNoMsg((FiniteDuration) dilated(Duration.create(20, TimeUnit.MILLISECONDS))); //delay a bit - the actors sometimes need a moment

    fhirProxyHandler = system.actorOf(Props.create(FhirProxyHandler.class, testConfig));
}
 
开发者ID:jembi,项目名称:openhim-mediator-fhir-proxy,代码行数:11,代码来源:FhirProxyHandlerTest.java

示例3: subscribeEvent

import akka.actor.Actor; //导入依赖的package包/类
/**
 * Attempts to register the subscriber to the specified channel.
 *
 * @return the temporary actor that delegates the event to given handler
 */
public <T> ActorRef subscribeEvent(final Handler<T> handler, final Class<T> channel) {
    ActorRef ref = system.actorOf(new Props().withCreator(new Creator<Actor>() {
        @Override
        public Actor create() throws Exception {
            return new UntypedActor() {
                @Override
                public void onReceive(Object message) throws Exception {
                    if (message != null && message.getClass().equals(channel)) {
                        handler.handle(channel.cast(message));
                    } else {
                        unhandled(message);
                    }
                }
            };
        }
    }));

    eventStream().subscribe(ref, channel);
    return ref;
}
 
开发者ID:l0rdn1kk0n,项目名称:wicket-akka,代码行数:26,代码来源:Akka.java

示例4: detach

import akka.actor.Actor; //导入依赖的package包/类
@Test
public void detach() throws Exception {
    ActorModel<Integer> model = new ActorModel<Integer>() {
        @Override
        protected ActorRef newActor() {
            return system().actorOf(Props.apply(new Creator<Actor>() {
                @Override
                public Actor create() throws Exception {
                    return new UntypedActor() {
                        @Override
                        public void onReceive(Object message) throws Exception {
                            unhandled(message);
                        }
                    };
                }
            }));
        }
    };

    model.detach();
    Thread.sleep(100);

    assertThat(model.getObject(), is(nullValue()));
    assertThat(model.getActorRef().isTerminated(), is(true));
}
 
开发者ID:l0rdn1kk0n,项目名称:wicket-akka,代码行数:26,代码来源:ActorModelTest.java

示例5: RegisterActors

import akka.actor.Actor; //导入依赖的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

示例6: loopOnAbstractActors

import akka.actor.Actor; //导入依赖的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

示例7: loopOnActors

import akka.actor.Actor; //导入依赖的package包/类
private static void loopOnActors(Map<String, ActorHolder> map, Set<Class<? extends UntypedActor>> 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

示例8: produce

import akka.actor.Actor; //导入依赖的package包/类
@Override
public Actor produce() {
  if (args == null) {
    return (Actor) applicationContext.getBean(actorBeanName);
  } else {
    return (Actor) applicationContext.getBean(actorBeanName, args);
  }
}
 
开发者ID:stefanstaniAIM,项目名称:IPPR2016,代码行数:9,代码来源:SpringActorProducer.java

示例9: produce

import akka.actor.Actor; //导入依赖的package包/类
@Override
public Actor produce() {
    if (args != null) {
        return (Actor) applicationContext.getBean(actorBeanName, args);
    } else {
        return (Actor) applicationContext.getBean(actorBeanName);
    }
}
 
开发者ID:vrk-kpa,项目名称:xroad-catalog,代码行数:9,代码来源:SpringActorProducer.java

示例10: produce

import akka.actor.Actor; //导入依赖的package包/类
@Override
public Actor produce() {
    try {
        Actor newActor = type.newInstance();
        ApplicationContextProvider.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(newActor);
        return newActor;
    } catch (InstantiationException | IllegalAccessException e) {
        LOG.error("Unable to create actor of type:{}", type, e);
    }
    return null;
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:12,代码来源:SpringTypeActorProducer.java

示例11: actorClass

import akka.actor.Actor; //导入依赖的package包/类
@Override
public Class<? extends Actor> actorClass() {
    return (Class<? extends Actor>) applicationContext.getType(actorBeanName);
}
 
开发者ID:PuspenduBanerjee,项目名称:akka-springctx-camel,代码行数:5,代码来源:SpringActorProducer.java

示例12: props

import akka.actor.Actor; //导入依赖的package包/类
public <A extends Actor, F> Props props(
        Class<A> actorClass,
        Class<F> factoryClass,
        Function<F, A> factoryFunction) {
    return Props.create(GuiceFactoryActorProducer.class,
            injector, actorClass, factoryClass, factoryFunction);
}
 
开发者ID:redvasily,项目名称:akka-guice-utils,代码行数:8,代码来源:GuiceExtension.java

示例13: ask

import akka.actor.Actor; //导入依赖的package包/类
@Test
public void ask() throws Exception {
    BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() {
        @Override
        protected ActorRef newActor() {
            return system().actorOf(Props.apply(new Creator<Actor>() {
                @Override
                public Actor create() throws Exception {
                    return new UntypedActor() {
                        @Override
                        public void onReceive(Object message) throws Exception {
                            if (message instanceof String) {
                                getSender().tell(Integer.parseInt((String) message), getSelf());
                            } else {
                                unhandled(message);
                            }
                        }
                    };
                }
            }));
        }
    };

    assertThat(model.ask("100").get(), is(100));

    model.detach();
}
 
开发者ID:l0rdn1kk0n,项目名称:wicket-akka,代码行数:28,代码来源:ActorModelTest.java

示例14: askByConstructor

import akka.actor.Actor; //导入依赖的package包/类
@Test
public void askByConstructor() throws Exception {
    BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() {
        @Override
        protected ActorRef newActor() {
            return system().actorOf(Props.apply(new Creator<Actor>() {
                @Override
                public Actor create() throws Exception {
                    return new UntypedActor() {
                        @Override
                        public void onReceive(Object message) throws Exception {
                            if (message instanceof String) {
                                getSender().tell(Integer.parseInt((String) message), getSelf());
                            } else {
                                unhandled(message);
                            }
                        }
                    };
                }
            }));
        }
    };

    assertThat(model.ask("100").get(), is(100));

    model.detach();
}
 
开发者ID:l0rdn1kk0n,项目名称:wicket-akka,代码行数:28,代码来源:ActorModelTest.java

示例15: askWithScalaFuture

import akka.actor.Actor; //导入依赖的package包/类
@Test
public void askWithScalaFuture() throws Exception {
    BaseAskActorModel<Integer, String> model = new BaseAskActorModel<Integer, String>() {
        @Override
        protected ActorRef newActor() {
            return system().actorOf(Props.apply(new Creator<Actor>() {
                @Override
                public Actor create() throws Exception {
                    return new UntypedActor() {
                        @Override
                        public void onReceive(Object message) throws Exception {
                            if (message instanceof String) {
                                getSender().tell(Integer.parseInt((String) message), getSelf());
                            } else {
                                unhandled(message);
                            }
                        }
                    };
                }
            }));
        }
    };

    Future<Integer> f = model.askWithScalaFuture("100");

    assertThat(Await.result(f, Duration.apply("3 sec")), is(100));
    assertThat(model.getObject(), is(100));

    model.detach();
}
 
开发者ID:l0rdn1kk0n,项目名称:wicket-akka,代码行数:31,代码来源:ActorModelTest.java


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