@Override public Receive createReceive() { return receiveBuilder() .match(EnterGrid.class, msg -> { if (userMap.containsKey(msg.user.getUserId())) { getSender().tell(false, getSelf()); } else { userMap.put(msg.user.getUserId(), msg.user); getSender().tell(true, getSelf()); } }).match(LeaveGrid.class, msg -> { if (userMap.containsKey(msg.userId)) { userMap.remove(msg.userId); } }).match(GetPlayers.class, msg -> { Collection<IUser> values = userMap.values(); List<IUser> list = new ArrayList<IUser>(); list.addAll(values); getSender().tell(list, getSelf()); }) .match(ScheduleTask.class, msg -> { Scheduler scheduler = getContext().getSystem().scheduler(); if (msg.isOnce()) { Cancellable cancellable = scheduler.scheduleOnce(Duration.create(msg.getDelay(), TimeUnit.MILLISECONDS), msg.getTask(), getContext().getSystem().dispatcher()); } else { Cancellable schedule = scheduler.schedule(Duration.create(msg.getDelay(), TimeUnit.MILLISECONDS), Duration.create(msg.getInterval(), TimeUnit.MILLISECONDS), msg.getTask(), getContext().getSystem().dispatcher()); } }) .build(); }
@Override public Cancellable schedule(long initialDelay, long interval, String actorName, Object message) { ActorRef actor = getActor(actorName); if (actor == null) { return null; } FiniteDuration initial = new FiniteDuration(initialDelay, TimeUnit.MILLISECONDS); FiniteDuration gap = new FiniteDuration(interval, TimeUnit.MILLISECONDS); Scheduler scheduler = actorSystem.scheduler(); return scheduler.schedule(initial, gap, actor, message, actorSystem.dispatcher(), ActorRef.noSender()); }
@Override public Cancellable runOnce(long initialDelay, String actorName, Object message) { ActorRef actor = getActor(actorName); if (actor == null) { return null; } FiniteDuration initial = new FiniteDuration(initialDelay, TimeUnit.MILLISECONDS); Scheduler scheduler = actorSystem.scheduler(); return scheduler.scheduleOnce(initial, actor, message, actorSystem.dispatcher(), ActorRef.noSender()); }
@Inject public RaguelThreadsScheduler(ActorSystem actorSystem, JPAApi jpaApi, JophielClientAPI jophielClientAPI) { Scheduler scheduler = actorSystem.scheduler(); ExecutionContextExecutor context = actorSystem.dispatcher(); UserActivityMessagePusher userActivityMessagePusher = new UserActivityMessagePusher(jpaApi, jophielClientAPI, UserActivityMessageServiceImpl.getInstance()); scheduler.schedule(Duration.create(1, TimeUnit.SECONDS), Duration.create(1, TimeUnit.MINUTES), userActivityMessagePusher, context); }
@Inject public UrielThreadsScheduler(ActorSystem actorSystem, JPAApi jpaApi, ProgrammingSubmissionService programmingSubmissionService, SealtielClientAPI sealtielClientAPI, ContestService contestService, ContestScoreboardService contestScoreboardService, ContestContestantService contestContestantService, JophielClientAPI jophielClientAPI) { Scheduler scheduler = actorSystem.scheduler(); ExecutionContextExecutor context = actorSystem.dispatcher(); GradingResponsePoller poller = new GradingResponsePoller(scheduler, context, programmingSubmissionService, sealtielClientAPI, TimeUnit.MILLISECONDS.convert(2, TimeUnit.SECONDS)); ScoreboardUpdaterDispatcher updater = new ScoreboardUpdaterDispatcher(jpaApi, scheduler, context, contestService, contestScoreboardService, contestContestantService, programmingSubmissionService); UserActivityMessagePusher userActivityMessagePusher = new UserActivityMessagePusher(jpaApi, jophielClientAPI, UserActivityMessageServiceImpl.getInstance()); scheduler.schedule(Duration.create(1, TimeUnit.SECONDS), Duration.create(UrielProperties.getInstance().getUrielGradingPollerInterval(), TimeUnit.SECONDS), poller, context); scheduler.schedule(Duration.create(1, TimeUnit.SECONDS), Duration.create(UrielProperties.getInstance().getUrielScoreboardUpdateInterval(), TimeUnit.SECONDS), updater, context); scheduler.schedule(Duration.create(1, TimeUnit.SECONDS), Duration.create(UrielProperties.getInstance().getUrielLogPusherInterval(), TimeUnit.SECONDS), userActivityMessagePusher, context); }
public ScoreboardUpdaterDispatcher(JPAApi jpaApi, Scheduler scheduler, ExecutionContext executor, ContestService contestService, ContestScoreboardService contestScoreboardService, ContestContestantService contestContestantService, ProgrammingSubmissionService programmingSubmissionService) { this.jpaApi = jpaApi; this.scheduler = scheduler; this.executor = executor; this.contestService = contestService; this.contestScoreboardService = contestScoreboardService; this.contestContestantService = contestContestantService; this.programmingSubmissionService = programmingSubmissionService; }
public static synchronized void updateScoreboard(Scheduler scheduler, ExecutionContext executor, Contest contest, ContestService contestService, ContestScoreboardService contestScoreboardService, ContestContestantService contestContestantService, ProgrammingSubmissionService programmingSubmissionService) { if (ScoreboardUpdaterDispatcher.updaterExists(contest.getJid())) { return; } ScoreboardUpdater scoreboardUpdater = new ScoreboardUpdater(contest, contestService, contestScoreboardService, contestContestantService, programmingSubmissionService); scoreboardUpdater.addOnScoreboardUpdateFinishListener(new OnScoreboardUpdateFinishListener() { @Override public void onFinish(String contestJid) { UPDATER_JIDS.remove(contestJid); } }); UPDATER_JIDS.add(contest.getJid()); scheduler.scheduleOnce(Duration.create(10, TimeUnit.MILLISECONDS), scoreboardUpdater, executor); }
@Provides @Singleton @Nonnull public Scheduler provideScheduler( @Nonnull final ActorSystem actorSystem) { assert actorSystem != null; return actorSystem.scheduler(); }
protected Scheduler getScheduler() { return getContext().getSystem().scheduler(); }
protected Scheduler getScheduler() { return systemContext.getScheduler(); }
public Scheduler getScheduler() { return actorSystem.scheduler(); }
@Override public final Scheduler getScheduler() { return akka.scheduler(); }
/** * @return an Akka scheduler service */ public Scheduler scheduler() { return system().scheduler(); }
/** * @return an Akka scheduler service */ Scheduler getScheduler();