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