public void run(Runnable runnable, long startTimeout, long completeTimeout) { RunnableTaskWrapper wrapper = new RunnableTaskWrapper(runnable, startTimeout, completeTimeout); runTaskWrapper(wrapper); }
public void runTask(Task task) { BasicTaskWrapper wrapper = new BasicTaskWrapper(task); runTaskWrapper(wrapper); }
/** * Create a new task wrapper * * @param task the task * @throws IllegalArgumentException for a null task */ public BasicTaskWrapper(Task task) { setTask(task); }
public void execute(Runnable command) { pool.run(command); } }
/** * Notify the task it has started * * @return true when the notification succeeds, false otherwise */ protected boolean taskStarted() { try { task.started(getElapsedTime()); return true; } catch (Throwable t) { log.warn("Unexpected error during 'started' for task: " + taskString, t); return false; } }
/** * Notify the task it has been accepted * * @return true when the notification succeeds, false otherwise */ protected boolean taskAccepted() { try { task.accepted(getElapsedTime()); return true; } catch (Throwable t) { log.warn("Unexpected error during 'accepted' for task: " + taskString, t); return false; } }
/** * Notify the task it has been rejected * * @param e any error associated with the rejection * @return true when the notification succeeds, false otherwise */ protected boolean taskRejected(RuntimeException e) { try { task.rejected(getElapsedTime(), e); return true; } catch (Throwable t) { log.warn("Unexpected error during 'rejected' for task: " + taskString, t); if (e != null) log.warn("Original reason for rejection of task: " + taskString, e); return false; } }
/** * Notify the task it has completed * * @param throwable any throwable associated with the completion * @return true when the notification succeeds, false otherwise */ protected boolean taskCompleted(Throwable throwable) { try { task.completed(getElapsedTime(), throwable); return true; } catch (Throwable t) { log.warn("Unexpected error during 'completed' for task: " + taskString, t); if (throwable != null) log.warn("Original error during 'run' for task: " + taskString, throwable); return false; } }
/** * For backward compatibility with the previous string based mode * @param name - the string form of the mode enum */ public void setBlockingMode(String name) { blockingMode = BlockingMode.toBlockingMode(name); if( blockingMode == null ) blockingMode = BlockingMode.ABORT; }
/** * Wait for a task * * @param wrapper the task wrapper */ protected void waitForTask(TaskWrapper wrapper) { wrapper.waitForTask(); }
/** * Used to lazily create the task completion timeout thread and monitor */ protected synchronized void checkTimeoutMonitor() { if( timeoutTask == null ) timeoutTask = new TimeoutMonitor(name, log); } protected TimeoutInfo getNextTimeout()
public long getTaskCompletionTimeout() { return wrapper.getTaskCompletionTimeout(); } /** Get the time remaining to the complete timeout timestamp in MS.
/** Invoke stopTask on the wrapper and indicate whether this was the first * time the task has been notified to stop. * @return true if this is the first stopTask, false on the second. */ public boolean stopTask() { wrapper.stopTask(); boolean wasFirstStop = firstStop == false; firstStop = true; return wasFirstStop; } }
/** Invoke stop on the thread pool if its not the class default pool. * * @param immeadiate the immeadiate flag passed to the TheadPool#stop */ protected void stopThreadPool(boolean immeadiate) { if( pool != defaultPool ) { pool.stop(immeadiate); } }
public void run(Runnable runnable) { run(runnable, 0, 0); }
public void stop() { stop(false); }
public void rejectTask(RuntimeException e) { synchronized (stateLock) { state = TASK_REJECTED; stateLock.notifyAll(); } taskRejected(e); }
/** * Execute a task on the same thread * * @param wrapper the task wrapper */ protected void executeOnThread(TaskWrapper wrapper) { if( trace ) log.trace("executeOnThread, wrapper="+wrapper); wrapper.run(); }
/** * For backward compatibility with the previous string based mode * This is needed for microcontainer as it gets confused with overloaded * setters. * @param name - the string form of the mode enum */ public void setBlockingModeString(String name) { blockingMode = BlockingMode.toBlockingMode(name); if( blockingMode == null ) blockingMode = BlockingMode.ABORT; }
/** * Returns a BlockingMode for the input object converted to a string. * * @return a BlockingMode enum instance * */ public Object getValue() { String text = getAsText(); BlockingMode mode = BlockingMode.toBlockingMode(text); return mode; } }