akka.actor.Cancellable Java Examples
The following examples show how to use
akka.actor.Cancellable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 6 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleAtFixedRate(@Nonnull Runnable command, long initialDelay, long period, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(period)); Cancellable cancellable = actorSystem.scheduler().schedule( new FiniteDuration(initialDelay, unit), new FiniteDuration(period, unit), scheduledFutureTask, actorSystem.dispatcher()); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #2
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 6 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleAtFixedRate(@Nonnull Runnable command, long initialDelay, long period, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(period)); Cancellable cancellable = actorSystem.scheduler().schedule( new FiniteDuration(initialDelay, unit), new FiniteDuration(period, unit), scheduledFutureTask, actorSystem.dispatcher()); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #3
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 6 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleAtFixedRate(@Nonnull Runnable command, long initialDelay, long period, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(period)); Cancellable cancellable = actorSystem.scheduler().schedule( new FiniteDuration(initialDelay, unit), new FiniteDuration(period, unit), scheduledFutureTask, actorSystem.dispatcher()); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #4
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override @Nonnull public <V> ScheduledFuture<V> schedule(@Nonnull Callable<V> callable, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<V> scheduledFutureTask = new ScheduledFutureTask<>(callable, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #5
Source File: ScheduleService.java From htwplus with MIT License | 5 votes |
private void schedule() { // set the email schedule to next full hour clock for sending daily and hourly emails Cancellable emailScheudler = system.scheduler().schedule( Duration.create(nextExecutionInSeconds(getNextHour(), 0), TimeUnit.SECONDS), Duration.create(1, TimeUnit.HOURS), () -> { emailService.sendDailyHourlyNotificationsEmails(); }, system.dispatcher() ); // cancel it on application stop lifecycle.addStopHook(() -> { emailScheudler.cancel(); return CompletableFuture.completedFuture(null); }); // Sets the schedule for cleaning the media temp directory Cancellable cleanUpScheudler = system.scheduler().schedule( Duration.create(0, TimeUnit.MILLISECONDS), Duration.create(2, TimeUnit.HOURS), () -> { mediaManager.cleanUpTemp(); }, system.dispatcher() ); // cancel it on application stop lifecycle.addStopHook(() -> { cleanUpScheudler.cancel(); return CompletableFuture.completedFuture(null); }); }
Example #6
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleWithFixedDelay(@Nonnull Runnable command, long initialDelay, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(-delay)); Cancellable cancellable = internalSchedule(scheduledFutureTask, initialDelay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #7
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public <V> ScheduledFuture<V> schedule(@Nonnull Callable<V> callable, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<V> scheduledFutureTask = new ScheduledFutureTask<>(callable, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #8
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> schedule(@Nonnull Runnable command, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>(command, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #9
Source File: ReconnectActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
private Cancellable scheduleReconnect() { final FiniteDuration initialDelay = getInitialDelay(); final FiniteDuration interval = getInterval(); final ActorContext context = getContext(); final ReconnectMessages message = ReconnectMessages.START_RECONNECT; log.info("Scheduling reconnect for all connections with initial delay <{}> and interval <{}>.", initialDelay, interval); return context.getSystem() .scheduler() .schedule(initialDelay, interval, getSelf(), message, context.dispatcher(), ActorRef.noSender()); }
Example #10
Source File: StreamingSessionActor.java From ditto with Eclipse Public License 2.0 | 5 votes |
private Cancellable startSessionTimeout(final Instant sessionExpirationTime) { final long timeout = sessionExpirationTime.minusMillis(Instant.now().toEpochMilli()).toEpochMilli(); logger.debug("Starting session timeout - session will expire in {} ms", timeout); final FiniteDuration sessionExpirationTimeMillis = FiniteDuration.apply(timeout, TimeUnit.MILLISECONDS); return getContext().getSystem().getScheduler().scheduleOnce(sessionExpirationTimeMillis, this::handleSessionTimeout, getContext().getDispatcher()); }
Example #11
Source File: PostOffice.java From mercury with Apache License 2.0 | 5 votes |
/** * Schedule a future event * * @param event envelope * @param future time * @return eventId of the scheduled delivery * @throws IOException if route not found or invalid parameters */ public String sendLater(final EventEnvelope event, Date future) throws IOException { String dest = event.getTo(); if (dest == null) { throw new IOException("Missing routing path"); } String to = substituteRouteIfAny(dest); event.setTo(to); // propagate trace info TraceInfo trace = getTrace(); if (trace != null) { if (trace.route != null && event.getFrom() == null) { event.setFrom(trace.route); } if (trace.id != null && trace.path != null) { event.setTrace(trace.id, trace.path); } } long now = System.currentTimeMillis(); long futureMs = future.getTime(); long interval = futureMs - now; if (interval < 1) { throw new IOException("Future milliseconds must be later than present time"); } // best effort to check if the target can be discovered discover(to, event.isEndOfRoute()); log.debug("Future event to {} in {} ms", to, interval); // schedule the event delivery ActorSystem system = Platform.getInstance().getEventSystem(); Cancellable task = system.scheduler().scheduleOnce(Duration.create(interval, TimeUnit.MILLISECONDS), () -> { try { futureEvents.remove(event.getId()); send(event); } catch (IOException e) { log.error("Deferred delivery to {} failed - {}", event.getTo(), e.getMessage()); } }, system.dispatcher()); futureEvents.put(event.getId(), new FutureEvent(to, task, future)); return event.getId(); }
Example #12
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleWithFixedDelay(@Nonnull Runnable command, long initialDelay, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(-delay)); Cancellable cancellable = internalSchedule(scheduledFutureTask, initialDelay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #13
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public <V> ScheduledFuture<V> schedule(@Nonnull Callable<V> callable, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<V> scheduledFutureTask = new ScheduledFutureTask<>(callable, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #14
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> schedule(@Nonnull Runnable command, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>(command, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #15
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> scheduleWithFixedDelay(@Nonnull Runnable command, long initialDelay, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>( command, triggerTime(unit.toNanos(initialDelay)), unit.toNanos(-delay)); Cancellable cancellable = internalSchedule(scheduledFutureTask, initialDelay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #16
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Override @Nonnull public ScheduledFuture<?> schedule(@Nonnull Runnable command, long delay, @Nonnull TimeUnit unit) { ScheduledFutureTask<Void> scheduledFutureTask = new ScheduledFutureTask<>(command, unit.toNanos(delay), 0L); Cancellable cancellable = internalSchedule(scheduledFutureTask, delay, unit); scheduledFutureTask.setCancellable(cancellable); return scheduledFutureTask; }
Example #17
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 4 votes |
public void setCancellable(Cancellable newCancellable) { this.cancellable = newCancellable; }
Example #18
Source File: FutureEvent.java From mercury with Apache License 2.0 | 4 votes |
public FutureEvent(String to, Cancellable task, Date time) { this.to = to; this.task = task; this.time = time; }
Example #19
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 4 votes |
private Cancellable internalSchedule(Runnable runnable, long delay, TimeUnit unit) { return actorSystem.scheduler().scheduleOnce( new FiniteDuration(delay, unit), runnable, actorSystem.dispatcher()); }
Example #20
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
public void setCancellable(Cancellable newCancellable) { this.cancellable = newCancellable; }
Example #21
Source File: ActorSystemScheduledExecutorAdapter.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
private Cancellable internalSchedule(Runnable runnable, long delay, TimeUnit unit) { return actorSystem.scheduler().scheduleOnce( new FiniteDuration(delay, unit), runnable, actorSystem.dispatcher()); }
Example #22
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 4 votes |
private Cancellable internalSchedule(Runnable runnable, long delay, TimeUnit unit) { return actorSystem.scheduler().scheduleOnce( new FiniteDuration(delay, unit), runnable, actorSystem.dispatcher()); }
Example #23
Source File: ActorSystemScheduledExecutorAdapter.java From flink with Apache License 2.0 | 4 votes |
public void setCancellable(Cancellable newCancellable) { this.cancellable = newCancellable; }