public class InjectingActorProvider implements Provider<ActorRef> { @Inject private Injector injector; @SuppressWarnings("serial") @Override public final ActorRef get() { Props props = new Props(new UntypedActorFactory() { @Override public Actor create() { return injector.getInstance(actorClass); } }); props = props.withRouter(...); props = props.withDispatcher(...); actor = system.actorOf(props, actorName); return actor; } }
/** * Returns a (named) typed router actor that will forward all messages using the routerConfig. * * @param name Actor name (or null if unnamed). * @param interfaceClass The type of the proxy interface. * @param routerConfig The router configuration to use. * @param <T> The type of the proxy interface. * @return Typed router actor. */ @Nonnull public static <T> T routerFor( @Nullable final String name, @Nonnull final Class<T> interfaceClass, @Nonnull final RouterConfig routerConfig) { assert interfaceClass != null; assert routerConfig != null; final ActorContext context = TypedActor.context(); // Create actor for router. final ActorRef routerActor; if (name == null) { routerActor = context.actorOf(Props.empty().withRouter(routerConfig)); } else { routerActor = context.actorOf(Props.empty().withRouter(routerConfig), name); } // Wrap actor with interfaceClass. final TypedProps<T> props = new TypedProps<>(interfaceClass); return TypedActor.get(context).typedActorOf(props, routerActor); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, Parameters actorParameters, String actorLogicalName) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName, actorParameters).withRouter(routerConfig).withDispatcher(dispatcher), actorLogicalName); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, String actorLogicalName, Object... actorParameters) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName, actorParameters).withRouter(routerConfig).withDispatcher(dispatcher), actorLogicalName); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName).withRouter(routerConfig).withDispatcher(dispatcher)); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, Parameters actorParameters) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName, actorParameters).withRouter(routerConfig).withDispatcher(dispatcher)); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, String actorLogicalName) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName).withRouter(routerConfig).withDispatcher(dispatcher), actorLogicalName); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, String actorLogicalName) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName).withRouter(routerConfig).withDispatcher(dispatcher), actorLogicalName); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName).withRouter(routerConfig).withDispatcher(dispatcher)); }
public ActorRef actorOf(ActorSystem actorSystem, String actorSpringBeanName, RouterConfig routerConfig, String dispatcher, Object... actorParameters) { return actorSystem.actorOf(get(actorSystem).props(actorSpringBeanName, actorParameters).withRouter(routerConfig).withDispatcher(dispatcher)); }
public SetupIndexWorkerActor(final SetupIndexService setupIndexService, final SampleDataGeneratorService sampleDataGeneratorService, final IndexProductDataService indexProductDataService) { this.setupIndexService = setupIndexService; workerRouter = getContext().actorOf( Props.create(SetupDocumentTypeWorkerActor.class, sampleDataGeneratorService, indexProductDataService) .withDispatcher( "setupDocumentTypeWorkerActorDispatcher") .withRouter(new FromConfig()), "setupDocumentTypeWorkerActor"); }
public SetupIndexMasterActor(final SetupIndexService setupIndexService, final SampleDataGeneratorService sampleDataGeneratorService, final IndexProductDataService indexProductDataService) { workerRouter = getContext().actorOf( Props.create(SetupIndexWorkerActor.class, setupIndexService, sampleDataGeneratorService, indexProductDataService) .withDispatcher("setupIndexWorkerActorDispatcher") .withRouter(new FromConfig()), "setupIndexWorkerActor"); }
@SuppressWarnings("unchecked") private ActorRef doCreateObject() throws Exception { Props props; if (actorClass != null) { props = Props.create(new SpringCreator(ctx, Class.forName(actorClass), args)); } else if (actorBeanName != null && actorBeanClass != null) { props = SpringProps.create(actorSystem, actorBeanName, (Class<? extends AbstractActor>) Class.forName(actorBeanClass)); } else if (actorBeanClass != null) { props = SpringProps.create(actorSystem, (Class<? extends AbstractActor>) Class.forName(actorBeanClass)); } else { props = SpringProps.create(actorSystem, actorBeanName); } if (props == null) { throw new BeanCreationException("Can not create ActorRef for given parameters, actorClass=" + actorClass + ", actorBeanClass=" + actorBeanClass + ", actorBeanName=" + actorBeanName); } if (routerConfig != null) { props = props.withRouter(routerConfig); } if (deploy != null) { props = props.withDeploy(deploy); } if (mailbox != null) { props = props.withMailbox(mailbox); } if (dispatcher != null) { props = props.withDispatcher(dispatcher); } return actorSystem.actorOf(props); }
public TrainModelActor(final ModelConfig modelConfig, final List<ColumnConfig> columnConfigList, final AkkaExecStatus akkaStatus, final List<AbstractTrainer> trainers) { super(modelConfig, columnConfigList, akkaStatus); log.info("Creating Master Actor ..."); this.resultCnt = 0; this.trainerCnt = trainers.size(); final ActorRef parentActorRef = getSelf(); // actors to training models trainModelRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -5719806635080547488L; public UntypedActor create() { return new TrainModelWorker(modelConfig, columnConfigList, parentActorRef, parentActorRef); } }).withRouter(new RoundRobinRouter(this.modelConfig.getBaggingNum())), "ModelTrainWorker"); // actors to aggregate all training data trainDataPrepRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -5719806635080547488L; public UntypedActor create() throws IOException { return new TrainDataPrepWorker(modelConfig, columnConfigList, parentActorRef, trainModelRef, trainers); } }).withRouter(new RoundRobinRouter(1)), "DataPrepWorker"); // actors to load data dataLoadRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -6869659846227133318L; public UntypedActor create() { return new DataLoadWorker(modelConfig, columnConfigList, parentActorRef, trainDataPrepRef); } }).withRouter(new RoundRobinRouter(Environment.getInt(Environment.LOCAL_NUM_PARALLEL, 16))), "DataLoaderWorker"); }
/** 웹서버 역할을 하는 HttpActor와 라우터를 생성한다 */ public static void main(String[] args) { ActorSystem actorSystem = ActorSystem.create("ClusterSystem"); ActorRef router = actorSystem.actorOf(Props.create(PingService.class).withRouter(new FromConfig()), "serviceRouter"); ActorRef httpActor = actorSystem.actorOf(Props.create(HttpActor.class, router), "httpActor"); } }
public TrainDtModelActor(final ModelConfig modelConfig, final List<ColumnConfig> columnConfigList, AkkaExecStatus akkaStatus, final List<AbstractTrainer> trainers) { super(modelConfig, columnConfigList, akkaStatus); log.info("Creating Master Actor ..."); this.resultCnt = 0; this.trainerCnt = trainers.size(); final ActorRef parentActorRef = getSelf(); // actors to training models trainModelRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -5719806635080547488L; public UntypedActor create() { return new TrainModelWorker(modelConfig, columnConfigList, parentActorRef, parentActorRef); } }).withRouter(new RoundRobinRouter(this.modelConfig.getBaggingNum())), "ModelTrainWorker"); // actors to aggregate all training data trainDataPrepRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -5719806635080547488L; public UntypedActor create() throws IOException { return new TrainDataPrepWorker(modelConfig, columnConfigList, parentActorRef, trainModelRef, trainers); } }).withRouter(new RoundRobinRouter(1)), "DataPrepWorker"); // actors to load data dataLoadRef = this.getContext().actorOf(new Props(new UntypedActorFactory() { private static final long serialVersionUID = -6869659846227133318L; public UntypedActor create() { return new DataLoadWorker(modelConfig, columnConfigList, parentActorRef, trainDataPrepRef); } }).withRouter(new RoundRobinRouter(Environment.getInt(Environment.LOCAL_NUM_PARALLEL, 16))), "DataLoaderWorker"); }
public SupervisingActor(final Indexer indexer, final PageRetriever pageRetriever) { this.pageParsingActor = getContext().actorOf(Props.create(ResendingPageParsingActor.class, pageRetriever) .withRouter(new RoundRobinRouter(10)).withDispatcher("worker-dispatcher")); this.indexingActor = getContext().actorOf(Props.create(IndexingActor.class, indexer)); }
public ParallelMaster(final Indexer indexer, final PageRetriever pageRetriever) { parser = getContext().actorOf(Props.create(PageParsingActor.class, pageRetriever) .withRouter(new RoundRobinRouter(10)).withDispatcher("worker-dispatcher")); indexingActor = getContext().actorOf(Props.create(IndexingActor.class, indexer)); }
public SetupDocumentTypeWorkerActor( final SampleDataGeneratorService sampleDataGeneratorService, final IndexProductDataService indexProductDataService) { dataGeneratorWorkerRouter = getContext().actorOf( Props.create(DataGeneratorWorkerActor.class, sampleDataGeneratorService), "dataGeneratorWorker"); documentGeneratorWorkerRouter = getContext() .actorOf( Props.create(DocumentGeneratorWorkerActor.class, sampleDataGeneratorService) .withRouter(new FromConfig()) .withDispatcher( "documentGenerateWorkerActorDispatcher"), "documentGeneratorWorker"); indexDocumentWorkerRouter = getContext().actorOf( Props.create(IndexProductDataWorkerActor.class, indexProductDataService).withRouter(new FromConfig()) .withDispatcher("indexDocumentWorkerActorDispatcher"), "indexDocumentWorker"); }
public MainActor() { MAX_CONCURRENCY = getNumWorkers(); workerRouter = getContext().actorOf(Props.create(WorkerActor.class). withRouter(new RoundRobinPool(MAX_CONCURRENCY)), "workerRouter"); scheduler = getContext().system().scheduler(); WORK_GENERATE_INTERVAL = getWorkGenerateInterval(); WORK_TRACKER_INTERVAL = getWorkTrackInterval(); }