本文整理汇总了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;
}
示例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));
}
示例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;
}
示例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));
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例11: actorClass
import akka.actor.Actor; //导入依赖的package包/类
@Override
public Class<? extends Actor> actorClass() {
return (Class<? extends Actor>) applicationContext.getType(actorBeanName);
}
示例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);
}
示例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();
}
示例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();
}
示例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();
}