]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.thread/src/org/simantics/utils/threads/IThreadWorkQueue.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.utils.thread / src / org / simantics / utils / threads / IThreadWorkQueue.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 package org.simantics.utils.threads;
13
14 /**
15  * IThreadAccess is an interface for thread context switching.
16  * 
17  * TODO Yield that makes the thread do other tasks in queue
18  * 
19  * @Todo Queue open method + QueueClosed exception
20  * @see SWTThread
21  * @see AWTThread
22  * @see CurrentThread
23  * @author Toni Kalajainen
24  */
25 public interface IThreadWorkQueue {
26
27         /**
28          * Execute runnable asynchronously.
29          * <p>
30          * Note!
31          * Do not call this method directly unless the instance has been wrapped with 
32          * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.asyncExec.
33          * 
34          * 
35          * @param runnable
36          * @return the thread that is processing the runnable or null if thread refused to accept event
37          */
38         Thread asyncExec(Runnable runnable);
39         
40         /**
41          * Execute runnable synchronously. 
42          * This invocation will block until runnable has been executed.
43          * Note!
44          * Do not call this method directly unless the instance has been wrapped with 
45          * ThreadUtils.getBetterThreadAccess(), if not use ThreadUtils.syncExec.
46          * 
47          * @param runnable
48          * @return true if thread accepted the event, false if not
49          */
50         boolean syncExec(Runnable runnable);
51         
52         /**
53          * Is the current thread the same as this access
54          * @return <code>true</code> if current thread is the same as this queue uses
55          */
56         boolean currentThreadAccess();
57         
58         /**
59          * Get the thread. May return null if the thread has not been initialized.
60          * The returned thread may also change right after call if no runnables are
61          * in queue.
62          * 
63          * @return thread or null
64          */
65         Thread getThread();
66
67 }