]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkMonitor.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / WorkMonitor.java
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
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 \r
13 package org.simantics.utils.threads.ua;\r
14 \r
15 \r
16 /**\r
17  * Asynchronous work monitor object.\r
18  * \r
19  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)\r
20  */\r
21 public interface WorkMonitor extends IStatefulObject<WorkState, RuntimeException> {\r
22 \r
23         /**\r
24          * Get the command\r
25          * \r
26          * @return runnable instance of the work\r
27          */\r
28         Runnable getRunnable();\r
29         \r
30     /**\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
39      *\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
43      *\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
46      * to complete\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
50      */\r
51     boolean cancel(boolean mayInterruptIfRunning);\r
52 \r
53         /**\r
54          * Get error that occured during execution of the runnable.\r
55          * @return run-time exception\r
56          */\r
57     RuntimeException getError();\r
58         \r
59 }\r