@Override public void runTimer() throws Exception { if (index.traceOptimisticLockErrors) { tasks.defaultExecutor().fork(this::cleanOldRecordings); } }
/** * Executes the action in its own executor */ public void execute() { CallContext.setCurrent(context); tasks.executor("index-delay").fork(cmd); } }
/** * Calls {@link #executeWork()} in the determined executor. * <p> * This is kind of the main loop, as {@code executeWork()} will call {@code loop()} once the computation * ({@code doWork()} is finished. Using {@link ExecutionBuilder#frequency(Object, double)} this is limited to the * call frequency as determined by {@code maxCallFrequency()}. */ protected void loop() { tasks.executor(determineExecutor()).frequency(this, maxCallFrequency()).start(this::executeWork); }
@Override public synchronized void runTimer() throws Exception { tasks.defaultExecutor().start(this::collectMetrics); }
/** * Generates a new TaskContext. * <p> * Normally this is should only be invoked by {@link CallContext}. Use {@link CallContext#get(Class)} to obtain an * instance. */ public TaskContext() { this.adapter = new BasicTaskContextAdapter(this); this.parent = CallContext.getCurrent(); }
/** * Creates a new context with the given debugging description and the expected runtime. * * @param description a provider for a description used for debugging purposes * @param expectedDuration the expected duration of the whole batch operation */ public BatchContext(Supplier<String> description, Duration expectedDuration) { this.op = new Operation(description, expectedDuration); }
@Override public void onFailure(Throwable throwable) { promise.fail(throwable); } });
/** * Determines if the execution of this task is still active. * <p> * A task can be either stopped via the {@link #cancel()} method or due to a system shutdown. In any case it is * wise for a task to check this flag every once in a while to keep the overall app responsive. * * @return <tt>true</tt> as long as the task is expected to be executed, <tt>false</tt> otherwise */ public boolean isActive() { return adapter.isActive() && tasks.isRunning(); }
/** * Creates an instantly successful promise containing the given value. * * @param successValue the value to fulfill the promise with */ public Promise(V successValue) { success(successValue); }
/** * Determines if the promise is completed yet. * * @return <tt>true</tt> if the promise has either successfully completed or failed yet, <tt>false</tt> otherwise. */ public boolean isCompleted() { return isFailed() || isSuccessful(); }
/** * Logs the given message and sets it as current state. * * @param message the message to log * @param args the parameters used to format the message (see {@link Strings#apply(String, Object...)}) */ public void logAsCurrentState(String message, Object... args) { log(message, args); setState(message, args); }
@Override public void initialize() throws Exception { readyFuture = new Future(); } }
protected void execute(ExecutionBuilder.TaskWrapper wrapper) { if (wrapper.synchronizer == null) { executeNow(wrapper); } else { schedule(wrapper); } }
@Override public void stopped() { running = false; wakeSchedulerLoop(); // Try an ordered (fair) shutdown... for (AsyncExecutor exec : executors.values()) { exec.shutdown(); } }
/** * Cancels the execution of this task. * <p> * Note that this will not kill the underlying thread. This will merely toggle the canceled flag. It is * however the task programmers job to check this flag and interrupt / terminate all computations. */ public void cancel() { adapter.cancel(); }
/** * Creates a new barrier. * * @return a new empty barrier. */ public static Barrier create() { return new Barrier(); }
/** * Returns the default executor. * * @return the execution builder which submits tasks to the default executor. */ public ExecutionBuilder defaultExecutor() { return new ExecutionBuilder(this, DEFAULT); }
@Override public SubContext fork() { TaskContext child = new TaskContext(); child.adapter = adapter; return child; }
@Override public void runTimer() throws Exception { tasks.defaultExecutor().start(this::runEviction); }
@Override public void onFailure(Throwable throwable) { promise.fail(throwable); } });