@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { if (securityIdentity != null) { try { return securityIdentity.runAs((PrivilegedExceptionAction<Object>) (() -> { try { return super.invoke(proxy, method, args); } catch (Throwable e) { throw new WrapperException(e); } })); } catch (PrivilegedActionException e) { Throwable cause = e.getCause(); throw cause instanceof WrapperException ? cause.getCause() : cause; } } else { return super.invoke(proxy, method, args); } }
void doneExecution(V result, long scheduledStart, long runStart, long runEnd) { lastExecution = new LastExecutionImpl(result, scheduledStart, runStart, runEnd); // schedule next run scheduleNextRun(); }
@Override public boolean cancel(boolean mayInterruptIfRunning) { super.cancel(mayInterruptIfRunning); // cancel the next scheduled task return getCurrentFuture().cancel(mayInterruptIfRunning); }
@Override public boolean cancel(boolean mayInterruptIfRunning) { boolean cancelled = super.cancel(mayInterruptIfRunning); if (cancelled && getRemoveOnCancelPolicy() && heapIndex >= 0) { remove(this); } return cancelled; }
/** * Same as prestartCoreThread except arranges that at least one * thread is started even if corePoolSize is 0. */ void ensurePrestart() { if (getCorePoolSize() == 0) { setCorePoolSize(1); } prestartCoreThread(); }
public void setThreadLifeTime(long threadLifeTime) { this.threadLifeTime = threadLifeTime; if (threadLifeTime > 0) { long keepAliveTime = getKeepAliveTime(TimeUnit.SECONDS); if (keepAliveTime == 0 || threadLifeTime < keepAliveTime) { setKeepAliveTime(threadLifeTime, TimeUnit.SECONDS); allowCoreThreadTimeOut(true); } } }
@Override public int compareTo(Delayed o) { return getCurrentFuture().compareTo(o); }
@Override public long getDelay(TimeUnit unit) { return getCurrentFuture().getDelay(unit); }
/** * Returns the trigger time of a delayed action. */ long triggerTime(long delay) { return now() + ((delay < (Long.MAX_VALUE >> 1)) ? delay : overflowFree(delay)); }
public void executeManagedTask(ManagedFutureTask task) { if (task instanceof ManagedScheduledFutureTask) { delayedExecute((ManagedScheduledFutureTask)task); } else { // should not happen schedule(task.executor, task, null, 0L, TimeUnit.NANOSECONDS); } }
@Override public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { if (skipped) { throw new SkippedException(); } return getCurrentFuture().get(timeout, unit); }
@Override public long getCompletedTaskCount() { return threadPoolExecutor.getCompletedTaskCount(); }
@Override protected <V> ManagedFutureTask<V> getNewTaskFor(Callable<V> callable) { return threadPoolExecutor.newTaskFor(this, callable); }
@Override public long getTaskCount() { return threadPoolExecutor.getTaskCount(); }
@Override public boolean equals(Object other) { if (other instanceof TriggerControllerFuture) { return compareTo((TriggerControllerFuture)other) == 0; } return false; }
@Override boolean cancelTask() { if (task != null) { return task.cancel(true); } return false; }
@Override public String getTaskIdentityName() { if (task != null) { return task.getTaskIdentityName(); } return "null"; }
public <V> ManagedFutureTask<V> newTaskFor( AbstractManagedExecutorService executor, Runnable r, V result) { return new ManagedScheduledFutureTask<>(executor, r, result, 0L); }
@Override protected void executeManagedFutureTask(ManagedFutureTask task) { // task.submitted() will be called from threadPoolExecutor.delayExecute() threadPoolExecutor.executeManagedTask(task); }
@Override public long getCompletedTaskCount() { return threadPoolExecutor.getCompletedTaskCount(); } }