本文整理汇总了Java中akka.routing.RoundRobinPool类的典型用法代码示例。如果您正苦于以下问题:Java RoundRobinPool类的具体用法?Java RoundRobinPool怎么用?Java RoundRobinPool使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RoundRobinPool类属于akka.routing包,在下文中一共展示了RoundRobinPool类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReadFilesWithActors
import akka.routing.RoundRobinPool; //导入依赖的package包/类
@Test
public void shouldReadFilesWithActors() throws Exception {
ActorRef workerRouter = system.actorOf(Props.create(ArticleParseActor.class).
withRouter(new RoundRobinPool(8)));
CompletableFuture future = new CompletableFuture();
ActorRef cameoActor = system.actorOf(Props.create(TestCameoActor.class, future));
IntStream.range(0, 2000).forEach(x -> {
workerRouter.tell(
new ParseArticle(TestHelper.file)
, cameoActor);
}
);
long start = System.currentTimeMillis();
future.get();
long elapsedTime = System.currentTimeMillis() - start;
System.out.println("ReadFilesWithActorsTest Took: " + elapsedTime);
}
示例2: startEventMessageProcessingActor
import akka.routing.RoundRobinPool; //导入依赖的package包/类
/**
* Start the router associated with the specified flow type (IN or OUT).
*
* @param pluginRegistrationEntry
* a plugin registration entry
* @param flowType
* a type of flow
* @return the actor ref created
*/
private ActorRef startEventMessageProcessingActor(PluginRegistrationEntry pluginRegistrationEntry, FlowType flowType) {
ActorRef actorRef = null;
EventInterfaceConfiguration eventInterfaceConfiguration = null;
if (flowType.equals(FlowType.IN)) {
eventInterfaceConfiguration = (pluginRegistrationEntry.getDescriptor().hasInMessageInterface() ? new EventInterfaceConfiguration() : null);
} else {
eventInterfaceConfiguration = (pluginRegistrationEntry.getDescriptor().hasOutMessageInterface() ? new EventInterfaceConfiguration() : null);
}
if (eventInterfaceConfiguration != null) {
actorRef = getActorSystem().actorOf(
(new RoundRobinPool(eventInterfaceConfiguration.getPoolSize()))
.withSupervisorStrategy(getSupervisorStrategy(eventInterfaceConfiguration.getNumberOfRetry(),
eventInterfaceConfiguration.getRetryDuration(), pluginRegistrationEntry.getPluginConfigurationId()))
.props(Props.create(new EventMessageProcessingActorCreator(pluginRegistrationEntry.getPluginConfigurationId(),
pluginRegistrationEntry.getPluginRunner(), FlowType.OUT))),
flowType.getRouterPrefix() + pluginRegistrationEntry.getPluginConfigurationId() + "-" + UUID.randomUUID().toString());
String message = "The %s interface for the plugin %d has been started";
log.info(String.format(message, flowType.name(), pluginRegistrationEntry.getPluginConfigurationId()));
return actorRef;
}
return null;
}
示例3: GenerateActor
import akka.routing.RoundRobinPool; //导入依赖的package包/类
/**
* Instantiates a new Generate actor.
*
* @param config the config
* @param callback the callback
*/
public GenerateActor(GeneratorConfig config, Callback callback)
{
this.config = config;
this.callback = callback;
// lookups
jobKeys = new HashSet<>();
jobCountLookup = new HashMap<>();
// create pool of workers
RoundRobinPool roundRobinPool = new RoundRobinPool(config.getThreads());
workerPool = getContext().system().actorOf(roundRobinPool.props(Props.create(GenerateWorkActor.class)));
// lets delegate some work
for(int i = 0; i < config.getThreads(); i++)
{
String jobKey = UUID.randomUUID().toString();
jobKeys.add(jobKey);
workerPool.tell(new GenerateWorkMsg(jobKey, config), getSelf());
}
}
示例4: initActorSystem
import akka.routing.RoundRobinPool; //导入依赖的package包/类
/**
* Inits the actor system.
*/
@PostConstruct
public void initActorSystem() {
LOG.info("Initializing Akka system...");
akka = ActorSystem.create(EPS, context.getConfig());
LOG.info("Initializing Akka EPS actor...");
opsActor = akka.actorOf(Props.create(
new OperationsServerActor.ActorCreator(context))
.withDispatcher(CORE_DISPATCHER_NAME), EPS);
LOG.info("Lookup platform protocols");
Set<String> platformProtocols = PlatformLookup.lookupPlatformProtocols(
PlatformLookup.DEFAULT_PROTOCOL_LOOKUP_PACKAGE_NAME);
LOG.info("Initializing Akka io router...");
ioRouter = akka.actorOf(
new RoundRobinPool(context.getIoWorkerCount())
.withSupervisorStrategy(SupervisionStrategyFactory.createIoRouterStrategy(context))
.props(Props.create(new EncDecActor.ActorCreator(opsActor, context, platformProtocols))
.withDispatcher(IO_DISPATCHER_NAME)), IO_ROUTER_ACTOR_NAME);
LOG.info("Initializing Akka event service listener...");
eventListener = new AkkaEventServiceListener(opsActor);
context.getEventService().addListener(eventListener);
clusterListener = new AkkaClusterServiceListener(opsActor);
context.getClusterService().setListener(clusterListener);
LOG.info("Initializing Akka system done");
}
示例5: TaskRunner
import akka.routing.RoundRobinPool; //导入依赖的package包/类
public TaskRunner() {
this.taskActor =
context().actorOf(
Props.create(TaskActor.class).withRouter(new RoundRobinPool(10)),
"task"
);
receive(
ReceiveBuilder
.matchEquals("start", msg -> {
for (int i = 0; i < numRuns; i++) {
taskActor.tell("run", self());
activeTasks++;
}
originator = sender();
})
.match(Long.class, msg -> {
currentSum += msg;
activeTasks--;
if (activeTasks == 0) {
originator.tell(currentSum, self());
}
})
.matchEquals("progress", msg -> printProgress(activeTasks))
.build()
);
}
示例6: createRouter
import akka.routing.RoundRobinPool; //导入依赖的package包/类
/**
* bean factory to create pool of the master client actors, the pool is used in a round robin manner
* @param system
* @param pool
* @param masterName
* @return
*/
@Bean
public ActorRef createRouter(ActorSystem system,
@Value("${master.client.pool}") int pool,
@Value("${master.name}") String masterName){
ActorRef router1 = system.actorOf(new RoundRobinPool(pool).props(Props.create(MasterClientActor.class,system,masterName)), "router");
return router1;
}
示例7: createOrResize
import akka.routing.RoundRobinPool; //导入依赖的package包/类
@Override
public void createOrResize(String routerName, int newSize) {
if(!routerMap.containsKey(routerName)) {
final ActorSystem actorSystem = actorSystemManager.retrieveActorSystem();
//create a local router with configured no.of task actors and keep the router reference in routerMap
ActorRef router = actorSystem.actorOf(new RoundRobinPool(newSize).withSupervisorStrategy(getTasksuperviseStrategy())
.props(Props.create(AkkaTask.class)), routerName);
routerMap.put(routerName, router);
logger.info("Created router: {} with no.of actors: {}", routerName, newSize);
} else {
// TODO ask the router to resize its pool of routees.
logger.warn("Currently router resize is NOT SUPPORTED. To change size Flux process has to be relaunched. Received resize request for router: {}, newSize: {}", routerName, newSize);
}
}
示例8: Master
import akka.routing.RoundRobinPool; //导入依赖的package包/类
public Master(final int nrOfWorkers, int nrOfMessages,
int nrOfElements, ActorRef listener) {
this.nrOfMessages = nrOfMessages;
this.nrOfElements = nrOfElements;
this.listener = listener;
workerRouter = this.getContext().actorOf(
Props.create(Worker.class).withRouter(
new RoundRobinPool(nrOfWorkers)), "workerRouter");
}
示例9: Master
import akka.routing.RoundRobinPool; //导入依赖的package包/类
public Master(final int nrOfWorkers, int nrOfMessages, int nrOfElements, ActorRef listener) {
this.nrOfElements = nrOfElements;
this.nrOfMessages = nrOfMessages;
this.listener = listener;
workerRouter = getContext()
.actorOf(Props.create(Worker.class)
.withRouter(new RoundRobinPool(nrOfWorkers)),
"workerRouter");
}
示例10: createActors
import akka.routing.RoundRobinPool; //导入依赖的package包/类
private void createActors(ActorSystem actorSystem) {
SupervisorStrategy strategy = getSupervisorStrategy(getNotificationRetryNumber(), getNotificationRetryDuration());
this.supervisorActor = actorSystem.actorOf((new RoundRobinPool(getPoolSize())).withSupervisorStrategy(strategy)
.props(Props.create(new NotificationMessageProcessingActorCreator(getConfiguration(), getPreferenceManagerPlugin(), getEmailService(),
this.getI18nMessagesPlugin()))),
SUPERVISOR_ACTOR_NAME);
log.info("Actor based notification system is started");
}
示例11: Master
import akka.routing.RoundRobinPool; //导入依赖的package包/类
@Autowired
public Master(final SpringProps springProps) {
LOGGER.debug("CREATING MASTER...");
this.workerRouter = getContext().actorOf(springProps.create(Worker.class)
.withRouter(new RoundRobinPool(5)),
"workerRouter");
}
示例12: init
import akka.routing.RoundRobinPool; //导入依赖的package包/类
protected static void init(DialsSystemConfiguration configuration) {
systemConfiguration = configuration;
system = ActorSystem.create("Dials");
system.actorOf(Props.create(ExecutionRegistry.class, configuration.getExecutionContextRecorder())
.withRouter(new RoundRobinPool(ACTOR_COUNT)), "ExecutionRegistry");
initialized = true;
}
示例13: MainActor
import akka.routing.RoundRobinPool; //导入依赖的package包/类
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();
}
示例14: AlbumActor
import akka.routing.RoundRobinPool; //导入依赖的package包/类
private AlbumActor() {
database = PhotostashDatabase.INSTANCE;
storyRouter = getContext().actorOf(new RoundRobinPool(5).props(Props.create(StoryActor.class)), "story-router");
storiesOrganizing = new HashMap<AlbumDocument, Set<File>>();
organizingRequestMap = new HashMap<AlbumDocument, OrganizeAlbumRequester>();
}
示例15: ShoeboxActor
import akka.routing.RoundRobinPool; //导入依赖的package包/类
private ShoeboxActor() {
albumRouter = getContext().actorOf(new RoundRobinPool(2).props(Props.create(AlbumActor.class)), "album-router");
albumsOrganizing = new HashSet<File>();
}