1 /*******************************************************************************
\r
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
\r
3 * in Industry THTH ry.
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
13 package org.simantics.utils.threads.ua;
\r
17 * Asynchronous work monitor object.
\r
19 * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
\r
21 public interface WorkMonitor extends IStatefulObject<WorkState, RuntimeException> {
\r
26 * @return runnable instance of the work
\r
28 Runnable getRunnable();
\r
31 * Attempts to cancel execution of this task. This attempt will
\r
32 * fail if the task has already completed, has already been cancelled,
\r
33 * or could not be cancelled for some other reason. If successful,
\r
34 * and this task has not started when <tt>cancel</tt> is called,
\r
35 * this task should never run. If the task has already started,
\r
36 * then the <tt>mayInterruptIfRunning</tt> parameter determines
\r
37 * whether the thread executing this task should be interrupted in
\r
38 * an attempt to stop the task.
\r
40 * <p>After this method returns, subsequent calls to {@link #isDone} will
\r
41 * always return <tt>true</tt>. Subsequent calls to {@link #isCancelled}
\r
42 * will always return <tt>true</tt> if this method returned <tt>true</tt>.
\r
44 * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
\r
45 * task should be interrupted; otherwise, in-progress tasks are allowed
\r
47 * @return <tt>false</tt> if the task could not be cancelled,
\r
48 * typically because it has already completed normally;
\r
49 * <tt>true</tt> otherwise
\r
51 boolean cancel(boolean mayInterruptIfRunning);
\r
54 * Get error that occured during execution of the runnable.
\r
55 * @return run-time exception
\r
57 RuntimeException getError();
\r