]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/ua/WorkMonitor.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / ua / WorkMonitor.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12
13 package org.simantics.utils.threads.ua;
14
15
16 /**
17  * Asynchronous work monitor object.
18  * 
19  * @author Toni Kalajainen (toni.kalajainen@vtt.fi)
20  */
21 public interface WorkMonitor extends IStatefulObject<WorkState, RuntimeException> {
22
23         /**
24          * Get the command
25          * 
26          * @return runnable instance of the work
27          */
28         Runnable getRunnable();
29         
30     /**
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.
39      *
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>.
43      *
44      * @param mayInterruptIfRunning <tt>true</tt> if the thread executing this
45      * task should be interrupted; otherwise, in-progress tasks are allowed
46      * to complete
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
50      */
51     boolean cancel(boolean mayInterruptIfRunning);
52
53         /**
54          * Get error that occured during execution of the runnable.
55          * @return run-time exception
56          */
57     RuntimeException getError();
58         
59 }